Skip to content

Commit 6c7f4de

Browse files
committed
Fix invalid keyword order for function declarations
1 parent 4dd8b42 commit 6c7f4de

14 files changed

+36
-14
lines changed

Diff for: compiler/rustc_parse/src/parser/item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ impl<'a> Parser<'a> {
10201020
&format!("`{}` must come before `{}`", invalid_qual, current_qual),
10211021
format!("{} {}", invalid_qual, current_qual),
10221022
Applicability::MachineApplicable,
1023-
).note("keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`");
1023+
).note("keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`");
10241024
}
10251025
}
10261026
Err(err)
@@ -2086,7 +2086,7 @@ impl<'a> Parser<'a> {
20862086
&format!("`{misplaced_qual}` must come before `{current_qual}`"),
20872087
format!("{misplaced_qual} {current_qual}"),
20882088
Applicability::MachineApplicable,
2089-
).note("keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`");
2089+
).note("keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`");
20902090
}
20912091
}
20922092
// Recover incorrect visibility order such as `async pub`

Diff for: src/test/ui/async-await/no-async-const.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | pub async const fn x() {}
77
| | expected one of `extern`, `fn`, or `unsafe`
88
| help: `const` must come before `async`: `const async`
99
|
10-
= note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
10+
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
1111

1212
error: aborting due to previous error
1313

Diff for: src/test/ui/async-await/no-unsafe-async.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | unsafe async fn g() {}
1212
LL | }
1313
| - the item list ends here
1414
|
15-
= note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
15+
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
1616

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

2828
error: aborting due to 2 previous errors
2929

Diff for: src/test/ui/fn/keyword-order.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// edition:2018
2+
3+
default pub const async unsafe extern fn err() {} //~ ERROR `default` is not followed by an item
4+
//~^ ERROR expected item, found keyword `pub`
5+
6+
pub default const async unsafe extern fn ok() {}

Diff for: src/test/ui/fn/keyword-order.stderr

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: `default` is not followed by an item
2+
--> $DIR/keyword-order.rs:3:1
3+
|
4+
LL | default pub const async unsafe extern fn err() {}
5+
| ^^^^^^^ the `default` qualifier
6+
|
7+
= note: only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`
8+
9+
error: expected item, found keyword `pub`
10+
--> $DIR/keyword-order.rs:3:9
11+
|
12+
LL | default pub const async unsafe extern fn err() {}
13+
| ^^^ expected item
14+
15+
error: aborting due to 2 previous errors
16+

Diff for: src/test/ui/parser/issues/issue-19398.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL |
1212
LL | }
1313
| - the item list ends here
1414
|
15-
= note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
15+
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
1616

1717
error: aborting due to previous error
1818

Diff for: src/test/ui/parser/issues/issue-87217-keyword-order/several-kw-jump.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ async unsafe const fn test() {}
1111
//~| NOTE expected one of `extern` or `fn`
1212
//~| HELP `const` must come before `async unsafe`
1313
//~| SUGGESTION const async unsafe
14-
//~| NOTE keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
14+
//~| NOTE keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`

Diff for: src/test/ui/parser/issues/issue-87217-keyword-order/several-kw-jump.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | async unsafe const fn test() {}
77
| | expected one of `extern` or `fn`
88
| help: `const` must come before `async unsafe`: `const async unsafe`
99
|
10-
= note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
10+
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
1111

1212
error: aborting due to previous error
1313

Diff for: src/test/ui/parser/issues/issue-87217-keyword-order/wrong-async.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ unsafe async fn test() {}
1111
//~| NOTE expected one of `extern` or `fn`
1212
//~| HELP `async` must come before `unsafe`
1313
//~| SUGGESTION async unsafe
14-
//~| NOTE keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
14+
//~| NOTE keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`

Diff for: src/test/ui/parser/issues/issue-87217-keyword-order/wrong-async.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | unsafe async fn test() {}
77
| | expected one of `extern` or `fn`
88
| help: `async` must come before `unsafe`: `async unsafe`
99
|
10-
= note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
10+
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
1111

1212
error: aborting due to previous error
1313

Diff for: src/test/ui/parser/issues/issue-87217-keyword-order/wrong-const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ unsafe const fn test() {}
1111
//~| NOTE expected one of `extern` or `fn`
1212
//~| HELP `const` must come before `unsafe`
1313
//~| SUGGESTION const unsafe
14-
//~| NOTE keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
14+
//~| NOTE keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`

Diff for: src/test/ui/parser/issues/issue-87217-keyword-order/wrong-const.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | unsafe const fn test() {}
77
| | expected one of `extern` or `fn`
88
| help: `const` must come before `unsafe`: `const unsafe`
99
|
10-
= note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
10+
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
1111

1212
error: aborting due to previous error
1313

Diff for: src/test/ui/parser/issues/issue-87217-keyword-order/wrong-unsafe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ extern unsafe fn test() {}
1111
//~| NOTE expected `fn`
1212
//~| HELP `unsafe` must come before `extern`
1313
//~| SUGGESTION unsafe extern
14-
//~| NOTE keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
14+
//~| NOTE keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`

Diff for: src/test/ui/parser/issues/issue-87217-keyword-order/wrong-unsafe.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | extern unsafe fn test() {}
77
| | expected `fn`
88
| help: `unsafe` must come before `extern`: `unsafe extern`
99
|
10-
= note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
10+
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
1111

1212
error: aborting due to previous error
1313

0 commit comments

Comments
 (0)