From b75f81c9b3f996100c72f9141dcf6161f8fc90f4 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Mon, 2 May 2016 08:45:38 +0200 Subject: [PATCH] parser: do not try to continue with `unsafe` on foreign fns The changed line makes it look like `unsafe` is allowed, but the first statement of `parse_item_foreign_fn` is: `self.expect_keyword(keywords::Fn)?;` So we get the strange "expected one of `fn`, `pub`, `static`, or `unsafe`, found `unsafe`". Fixes: #27361 --- src/libsyntax/parse/parser.rs | 2 +- src/test/parse-fail/extern-no-fn.rs | 2 +- src/test/parse-fail/removed-syntax-extern-const.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 671a11b57dec1..c22a36739d678 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -6025,7 +6025,7 @@ impl<'a> Parser<'a> { // FOREIGN STATIC ITEM return Ok(Some(self.parse_item_foreign_static(visibility, lo, attrs)?)); } - if self.check_keyword(keywords::Fn) || self.check_keyword(keywords::Unsafe) { + if self.check_keyword(keywords::Fn) { // FOREIGN FUNCTION ITEM return Ok(Some(self.parse_item_foreign_fn(visibility, lo, attrs)?)); } diff --git a/src/test/parse-fail/extern-no-fn.rs b/src/test/parse-fail/extern-no-fn.rs index bf5cbe0c4592a..acf7187cf436f 100644 --- a/src/test/parse-fail/extern-no-fn.rs +++ b/src/test/parse-fail/extern-no-fn.rs @@ -11,7 +11,7 @@ // compile-flags: -Z parse-only extern { - f(); //~ ERROR expected one of `fn`, `pub`, `static`, `unsafe`, or `}`, found `f` + f(); //~ ERROR expected one of `fn`, `pub`, `static`, or `}`, found `f` } fn main() { diff --git a/src/test/parse-fail/removed-syntax-extern-const.rs b/src/test/parse-fail/removed-syntax-extern-const.rs index c42fae71237da..e632af6c83b1d 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`, `unsafe`, or `}`, found `const` + //~^ ERROR expected one of `fn`, `pub`, `static`, or `}`, found `const` }