Obsolete parsing 'loop' as 'continue'

This commit is contained in:
Alex Crichton 2013-10-01 14:41:59 -07:00
parent 7f9b918562
commit 4af849bc12
3 changed files with 22 additions and 0 deletions

View File

@ -63,6 +63,7 @@ pub enum ObsoleteSyntax {
ObsoleteTraitFuncVisibility,
ObsoleteConstPointer,
ObsoleteEmptyImpl,
ObsoleteLoopAsContinue,
}
impl to_bytes::IterBytes for ObsoleteSyntax {
@ -244,6 +245,11 @@ impl ParserObsoleteMethods for Parser {
"empty implementation",
"instead of `impl A;`, write `impl A {}`"
),
ObsoleteLoopAsContinue => (
"`loop` instead of `continue`",
"`loop` is now only used for loops and `continue` is used for \
skipping iterations"
),
};
self.report(sp, kind, kind_str, desc);

View File

@ -2597,6 +2597,7 @@ impl Parser {
"a label may not be used with a `loop` expression");
}
self.obsolete(*self.last_span, ObsoleteLoopAsContinue);
let lo = self.span.lo;
let ex = if self.token_is_lifetime(&*self.token) {
let lifetime = self.get_lifetime(&*self.token);

View File

@ -0,0 +1,15 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
loop {
loop //~ ERROR: `loop` instead of `continue`
}
}