Skip to content

Commit 2aff5b8

Browse files
Centrilcuviper
authored andcommitted
expect fn after const unsafe / const extern
(cherry picked from commit 915db7a)
1 parent 965ce16 commit 2aff5b8

5 files changed

+42
-1
lines changed

src/librustc_parse/parser/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl<'a> Parser<'a> {
144144
self.sess.gated_spans.gate(sym::const_extern_fn, lo.to(self.token.span));
145145
}
146146
let ext = self.parse_extern()?;
147-
self.bump(); // `fn`
147+
self.expect_keyword(kw::Fn)?;
148148

149149
let header = FnHeader {
150150
unsafety,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() {}
2+
3+
#[cfg(FALSE)]
4+
fn container() {
5+
const unsafe WhereIsFerris Now() {}
6+
//~^ ERROR expected one of `extern` or `fn`
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected one of `extern` or `fn`, found `WhereIsFerris`
2+
--> $DIR/issue-68062-const-extern-fns-dont-need-fn-specifier-2.rs:5:18
3+
|
4+
LL | const unsafe WhereIsFerris Now() {}
5+
| ^^^^^^^^^^^^^ expected one of `extern` or `fn`
6+
7+
error: aborting due to previous error
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {}
2+
3+
#[cfg(FALSE)]
4+
fn container() {
5+
const extern "Rust" PUT_ANYTHING_YOU_WANT_HERE bug() -> usize { 1 }
6+
//~^ ERROR expected `fn`
7+
//~| ERROR `const extern fn` definitions are unstable
8+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: expected `fn`, found `PUT_ANYTHING_YOU_WANT_HERE`
2+
--> $DIR/issue-68062-const-extern-fns-dont-need-fn-specifier.rs:5:25
3+
|
4+
LL | const extern "Rust" PUT_ANYTHING_YOU_WANT_HERE bug() -> usize { 1 }
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `fn`
6+
7+
error[E0658]: `const extern fn` definitions are unstable
8+
--> $DIR/issue-68062-const-extern-fns-dont-need-fn-specifier.rs:5:5
9+
|
10+
LL | const extern "Rust" PUT_ANYTHING_YOU_WANT_HERE bug() -> usize { 1 }
11+
| ^^^^^^^^^^^^
12+
|
13+
= note: for more information, see https://github.com/rust-lang/rust/issues/64926
14+
= help: add `#![feature(const_extern_fn)]` to the crate attributes to enable
15+
16+
error: aborting due to 2 previous errors
17+
18+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)