expect fn after const unsafe / const extern

This commit is contained in:
Mazdak Farrokhzad 2020-01-09 23:00:28 +01:00
parent 59eb49d0da
commit 915db7ae64
5 changed files with 42 additions and 1 deletions

View File

@ -140,7 +140,7 @@ impl<'a> Parser<'a> {
self.sess.gated_spans.gate(sym::const_extern_fn, lo.to(self.token.span));
}
let ext = self.parse_extern()?;
self.bump(); // `fn`
self.expect_keyword(kw::Fn)?;
let header = FnHeader {
unsafety,

View File

@ -0,0 +1,7 @@
fn main() {}
#[cfg(FALSE)]
fn container() {
const unsafe WhereIsFerris Now() {}
//~^ ERROR expected one of `extern` or `fn`
}

View File

@ -0,0 +1,8 @@
error: expected one of `extern` or `fn`, found `WhereIsFerris`
--> $DIR/issue-68062-const-extern-fns-dont-need-fn-specifier-2.rs:5:18
|
LL | const unsafe WhereIsFerris Now() {}
| ^^^^^^^^^^^^^ expected one of `extern` or `fn`
error: aborting due to previous error

View File

@ -0,0 +1,8 @@
fn main() {}
#[cfg(FALSE)]
fn container() {
const extern "Rust" PUT_ANYTHING_YOU_WANT_HERE bug() -> usize { 1 }
//~^ ERROR expected `fn`
//~| ERROR `const extern fn` definitions are unstable
}

View File

@ -0,0 +1,18 @@
error: expected `fn`, found `PUT_ANYTHING_YOU_WANT_HERE`
--> $DIR/issue-68062-const-extern-fns-dont-need-fn-specifier.rs:5:25
|
LL | const extern "Rust" PUT_ANYTHING_YOU_WANT_HERE bug() -> usize { 1 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `fn`
error[E0658]: `const extern fn` definitions are unstable
--> $DIR/issue-68062-const-extern-fns-dont-need-fn-specifier.rs:5:5
|
LL | const extern "Rust" PUT_ANYTHING_YOU_WANT_HERE bug() -> usize { 1 }
| ^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/64926
= help: add `#![feature(const_extern_fn)]` to the crate attributes to enable
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0658`.