Skip to content

Commit 85e5e20

Browse files
Rollup merge of rust-lang#42319 - Manishearth:const-extern, r=nikomatsakis
Improve error message for const extern fn It's currently ``error: unmatched visibility `pub` ``, which is a nonsensical error in this context.
2 parents 1316281 + 22c4ee3 commit 85e5e20

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5985,6 +5985,10 @@ impl<'a> Parser<'a> {
59855985
return Ok(Some(self.parse_item_foreign_fn(visibility, lo, attrs)?));
59865986
}
59875987

5988+
if self.check_keyword(keywords::Const) {
5989+
return Err(self.span_fatal(self.span, "extern items cannot be `const`"));
5990+
}
5991+
59885992
// FIXME #5668: this will occur for a macro invocation:
59895993
match self.parse_macro_use_or_failure(attrs, true, false, lo, visibility)? {
59905994
Some(item) => {

src/test/parse-fail/removed-syntax-extern-const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212

1313
extern {
1414
const i: isize;
15-
//~^ ERROR expected one of `fn`, `pub`, `static`, or `}`, found `const`
15+
//~^ ERROR extern items cannot be `const`
1616
}

0 commit comments

Comments
 (0)