Skip to content

Commit 79d0e82

Browse files
committed
rollup merge of #17729 : alexcrichton/issue-17718-start
2 parents 61c4f6d + da7dcee commit 79d0e82

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

src/libsyntax/parse/parser.rs

+21-3
Original file line numberDiff line numberDiff line change
@@ -4732,8 +4732,7 @@ impl<'a> Parser<'a> {
47324732
}
47334733
}
47344734

4735-
fn parse_item_const(&mut self) -> ItemInfo {
4736-
let m = if self.eat_keyword(keywords::Mut) {MutMutable} else {MutImmutable};
4735+
fn parse_item_const(&mut self, m: Mutability) -> ItemInfo {
47374736
let id = self.parse_ident();
47384737
self.expect(&token::COLON);
47394738
let ty = self.parse_ty(true);
@@ -5289,7 +5288,26 @@ impl<'a> Parser<'a> {
52895288
if self.is_keyword(keywords::Static) {
52905289
// STATIC ITEM
52915290
self.bump();
5292-
let (ident, item_, extra_attrs) = self.parse_item_const();
5291+
let m = if self.eat_keyword(keywords::Mut) {MutMutable} else {MutImmutable};
5292+
let (ident, item_, extra_attrs) = self.parse_item_const(m);
5293+
let last_span = self.last_span;
5294+
let item = self.mk_item(lo,
5295+
last_span.hi,
5296+
ident,
5297+
item_,
5298+
visibility,
5299+
maybe_append(attrs, extra_attrs));
5300+
return IoviItem(item);
5301+
}
5302+
if self.is_keyword(keywords::Const) {
5303+
// CONST ITEM
5304+
self.bump();
5305+
if self.eat_keyword(keywords::Mut) {
5306+
let last_span = self.last_span;
5307+
self.span_err(last_span, "const globals cannot be mutable, \
5308+
did you mean to declare a static?");
5309+
}
5310+
let (ident, item_, extra_attrs) = self.parse_item_const(MutImmutable);
52935311
let last_span = self.last_span;
52945312
let item = self.mk_item(lo,
52955313
last_span.hi,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
const
12+
mut //~ ERROR: const globals cannot be mutable, did you mean to declare a static?
13+
FOO: uint = 3;
14+
15+
fn main() {
16+
}
17+
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -8,4 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
const i: int = 42; //~ ERROR expected item, found `const`
11+
const FOO: uint = 3;
12+
13+
fn main() {
14+
assert_eq!(FOO, 3);
15+
}

0 commit comments

Comments
 (0)