diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-10-03 07:38:29 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-10-03 07:38:29 -0700 |
| commit | 79d0e82f7386e9525e5232bf1083f74b0385838f (patch) | |
| tree | 7e414a66d8e280177bdd0c3bfb5fa05795dd0034 | |
| parent | 61c4f6dcd95a8e0359a818c6646310272dfb3ab0 (diff) | |
| parent | da7dcee8f16b7ea635b9e0ca83b529e1d92421b0 (diff) | |
rollup merge of #17729 : alexcrichton/issue-17718-start
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 24 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-17718-const-mut.rs | 17 | ||||
| -rw-r--r-- | src/test/run-pass/issue-17718-parse-const.rs (renamed from src/test/compile-fail/removed-syntax-const-item.rs) | 8 |
3 files changed, 44 insertions, 5 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d2735a425f5..4c877c0b101 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4732,8 +4732,7 @@ impl<'a> Parser<'a> { } } - fn parse_item_const(&mut self) -> ItemInfo { - let m = if self.eat_keyword(keywords::Mut) {MutMutable} else {MutImmutable}; + fn parse_item_const(&mut self, m: Mutability) -> ItemInfo { let id = self.parse_ident(); self.expect(&token::COLON); let ty = self.parse_ty(true); @@ -5289,7 +5288,26 @@ impl<'a> Parser<'a> { if self.is_keyword(keywords::Static) { // STATIC ITEM self.bump(); - let (ident, item_, extra_attrs) = self.parse_item_const(); + let m = if self.eat_keyword(keywords::Mut) {MutMutable} else {MutImmutable}; + let (ident, item_, extra_attrs) = self.parse_item_const(m); + let last_span = self.last_span; + let item = self.mk_item(lo, + last_span.hi, + ident, + item_, + visibility, + maybe_append(attrs, extra_attrs)); + return IoviItem(item); + } + if self.is_keyword(keywords::Const) { + // CONST ITEM + self.bump(); + if self.eat_keyword(keywords::Mut) { + let last_span = self.last_span; + self.span_err(last_span, "const globals cannot be mutable, \ + did you mean to declare a static?"); + } + let (ident, item_, extra_attrs) = self.parse_item_const(MutImmutable); let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, diff --git a/src/test/compile-fail/issue-17718-const-mut.rs b/src/test/compile-fail/issue-17718-const-mut.rs new file mode 100644 index 00000000000..31a5fee2044 --- /dev/null +++ b/src/test/compile-fail/issue-17718-const-mut.rs @@ -0,0 +1,17 @@ +// Copyright 2014 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. + +const +mut //~ ERROR: const globals cannot be mutable, did you mean to declare a static? +FOO: uint = 3; + +fn main() { +} + diff --git a/src/test/compile-fail/removed-syntax-const-item.rs b/src/test/run-pass/issue-17718-parse-const.rs index 841c1ec59fd..3ca6f473a79 100644 --- a/src/test/compile-fail/removed-syntax-const-item.rs +++ b/src/test/run-pass/issue-17718-parse-const.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -8,4 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -const i: int = 42; //~ ERROR expected item, found `const` +const FOO: uint = 3; + +fn main() { + assert_eq!(FOO, 3); +} |
