From 22c4ee365c3b921859e0a325a559b3d41f49c4bb Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 30 May 2017 14:23:02 -0700 Subject: [PATCH] Improve error message for const extern fn --- src/libsyntax/parse/parser.rs | 4 ++++ src/test/parse-fail/removed-syntax-extern-const.rs | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 8d7c8c5248b..d0b6a8b9fed 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -5981,6 +5981,10 @@ impl<'a> Parser<'a> { return Ok(Some(self.parse_item_foreign_fn(visibility, lo, attrs)?)); } + if self.check_keyword(keywords::Const) { + return Err(self.span_fatal(self.span, "extern items cannot be `const`")); + } + // FIXME #5668: this will occur for a macro invocation: match self.parse_macro_use_or_failure(attrs, true, false, lo, visibility)? { Some(item) => { diff --git a/src/test/parse-fail/removed-syntax-extern-const.rs b/src/test/parse-fail/removed-syntax-extern-const.rs index e632af6c83b..27688867de3 100644 --- a/src/test/parse-fail/removed-syntax-extern-const.rs +++ b/src/test/parse-fail/removed-syntax-extern-const.rs @@ -12,5 +12,5 @@ extern { const i: isize; - //~^ ERROR expected one of `fn`, `pub`, `static`, or `}`, found `const` + //~^ ERROR extern items cannot be `const` }