Skip to content

Fix invalid keyword order for function declarations #96629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
@@ -1020,7 +1020,7 @@ impl<'a> Parser<'a> {
&format!("`{}` must come before `{}`", invalid_qual, current_qual),
format!("{} {}", invalid_qual, current_qual),
Applicability::MachineApplicable,
).note("keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`");
).note("keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`");
}
}
Err(err)
@@ -2086,7 +2086,7 @@ impl<'a> Parser<'a> {
&format!("`{misplaced_qual}` must come before `{current_qual}`"),
format!("{misplaced_qual} {current_qual}"),
Applicability::MachineApplicable,
).note("keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`");
).note("keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`");
}
}
// Recover incorrect visibility order such as `async pub`
2 changes: 1 addition & 1 deletion src/test/ui/async-await/no-async-const.stderr
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ LL | pub async const fn x() {}
| | expected one of `extern`, `fn`, or `unsafe`
| help: `const` must come before `async`: `const async`
|
= note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/async-await/no-unsafe-async.stderr
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ LL | unsafe async fn g() {}
LL | }
| - the item list ends here
|
= note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`

error: expected one of `extern` or `fn`, found keyword `async`
--> $DIR/no-unsafe-async.rs:11:8
@@ -23,7 +23,7 @@ LL | unsafe async fn f() {}
| | expected one of `extern` or `fn`
| help: `async` must come before `unsafe`: `async unsafe`
|
= note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`

error: aborting due to 2 previous errors

6 changes: 6 additions & 0 deletions src/test/ui/fn/keyword-order.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// edition:2018

default pub const async unsafe extern fn err() {} //~ ERROR `default` is not followed by an item
//~^ ERROR expected item, found keyword `pub`

pub default const async unsafe extern fn ok() {}
16 changes: 16 additions & 0 deletions src/test/ui/fn/keyword-order.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error: `default` is not followed by an item
--> $DIR/keyword-order.rs:3:1
|
LL | default pub const async unsafe extern fn err() {}
| ^^^^^^^ the `default` qualifier
|
= note: only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`

error: expected item, found keyword `pub`
--> $DIR/keyword-order.rs:3:9
|
LL | default pub const async unsafe extern fn err() {}
| ^^^ expected item

error: aborting due to 2 previous errors

2 changes: 1 addition & 1 deletion src/test/ui/parser/issues/issue-19398.stderr
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ LL |
LL | }
| - the item list ends here
|
= note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`

error: aborting due to previous error

Original file line number Diff line number Diff line change
@@ -11,4 +11,4 @@ async unsafe const fn test() {}
//~| NOTE expected one of `extern` or `fn`
//~| HELP `const` must come before `async unsafe`
//~| SUGGESTION const async unsafe
//~| NOTE keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
//~| NOTE keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ LL | async unsafe const fn test() {}
| | expected one of `extern` or `fn`
| help: `const` must come before `async unsafe`: `const async unsafe`
|
= note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`

error: aborting due to previous error

Original file line number Diff line number Diff line change
@@ -11,4 +11,4 @@ unsafe async fn test() {}
//~| NOTE expected one of `extern` or `fn`
//~| HELP `async` must come before `unsafe`
//~| SUGGESTION async unsafe
//~| NOTE keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
//~| NOTE keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ LL | unsafe async fn test() {}
| | expected one of `extern` or `fn`
| help: `async` must come before `unsafe`: `async unsafe`
|
= note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`

error: aborting due to previous error

Original file line number Diff line number Diff line change
@@ -11,4 +11,4 @@ unsafe const fn test() {}
//~| NOTE expected one of `extern` or `fn`
//~| HELP `const` must come before `unsafe`
//~| SUGGESTION const unsafe
//~| NOTE keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
//~| NOTE keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ LL | unsafe const fn test() {}
| | expected one of `extern` or `fn`
| help: `const` must come before `unsafe`: `const unsafe`
|
= note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`

error: aborting due to previous error

Original file line number Diff line number Diff line change
@@ -11,4 +11,4 @@ extern unsafe fn test() {}
//~| NOTE expected `fn`
//~| HELP `unsafe` must come before `extern`
//~| SUGGESTION unsafe extern
//~| NOTE keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
//~| NOTE keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ LL | extern unsafe fn test() {}
| | expected `fn`
| help: `unsafe` must come before `extern`: `unsafe extern`
|
= note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`

error: aborting due to previous error