From 4af849bc12e8a2ec592074b1470464efa59f06bf Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 1 Oct 2013 14:41:59 -0700 Subject: [PATCH] Obsolete parsing 'loop' as 'continue' --- src/libsyntax/parse/obsolete.rs | 6 ++++++ src/libsyntax/parse/parser.rs | 1 + src/test/compile-fail/loop-as-continue.rs | 15 +++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 src/test/compile-fail/loop-as-continue.rs diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index adf0c208da4..5a8563f963d 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -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); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 4dd09cbcbd2..5c88c617950 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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); diff --git a/src/test/compile-fail/loop-as-continue.rs b/src/test/compile-fail/loop-as-continue.rs new file mode 100644 index 00000000000..e4273fdfeff --- /dev/null +++ b/src/test/compile-fail/loop-as-continue.rs @@ -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 or the MIT license +// , 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` + } +}