-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #87235 - poliorcetics:issue-87217-fn-quali-order, r=nagisa
Improve diagnostics for wrongly ordered keywords in function declaration Fix #87217 `@rustbot` label A-diagnostics T-compiler
- Loading branch information
Showing
13 changed files
with
184 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/test/ui/parser/issue-87217-keyword-order/const-async-const.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// edition:2018 | ||
|
||
// Test that even when `const` is already present, the proposed fix is `const const async`, | ||
// like for `pub pub`. | ||
|
||
const async const fn test() {} | ||
//~^ ERROR expected one of `extern`, `fn`, or `unsafe`, found keyword `const` | ||
//~| NOTE expected one of `extern`, `fn`, or `unsafe` | ||
//~| HELP `const` must come before `async` | ||
//~| SUGGESTION const async | ||
//~| NOTE keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern` |
13 changes: 13 additions & 0 deletions
13
src/test/ui/parser/issue-87217-keyword-order/const-async-const.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error: expected one of `extern`, `fn`, or `unsafe`, found keyword `const` | ||
--> $DIR/const-async-const.rs:6:13 | ||
| | ||
LL | const async const fn test() {} | ||
| ------^^^^^ | ||
| | | | ||
| | 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` | ||
|
||
error: aborting due to previous error | ||
|
14 changes: 14 additions & 0 deletions
14
src/test/ui/parser/issue-87217-keyword-order/several-kw-jump.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// edition:2018 | ||
|
||
// There is an order to respect for keywords before a function: | ||
// `<visibility>, const, async, unsafe, extern, "<ABI>"` | ||
// | ||
// This test ensures the compiler is helpful about them being misplaced. | ||
// Visibilities are tested elsewhere. | ||
|
||
async unsafe const fn test() {} | ||
//~^ ERROR expected one of `extern` or `fn`, found keyword `const` | ||
//~| 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` |
13 changes: 13 additions & 0 deletions
13
src/test/ui/parser/issue-87217-keyword-order/several-kw-jump.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error: expected one of `extern` or `fn`, found keyword `const` | ||
--> $DIR/several-kw-jump.rs:9:14 | ||
| | ||
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` | ||
|
||
error: aborting due to previous error | ||
|
14 changes: 14 additions & 0 deletions
14
src/test/ui/parser/issue-87217-keyword-order/wrong-async.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// edition:2018 | ||
|
||
// There is an order to respect for keywords before a function: | ||
// `<visibility>, const, async, unsafe, extern, "<ABI>"` | ||
// | ||
// This test ensures the compiler is helpful about them being misplaced. | ||
// Visibilities are tested elsewhere. | ||
|
||
unsafe async fn test() {} | ||
//~^ ERROR expected one of `extern` or `fn`, found keyword `async` | ||
//~| 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` |
13 changes: 13 additions & 0 deletions
13
src/test/ui/parser/issue-87217-keyword-order/wrong-async.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error: expected one of `extern` or `fn`, found keyword `async` | ||
--> $DIR/wrong-async.rs:9:8 | ||
| | ||
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` | ||
|
||
error: aborting due to previous error | ||
|
14 changes: 14 additions & 0 deletions
14
src/test/ui/parser/issue-87217-keyword-order/wrong-const.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// edition:2018 | ||
|
||
// There is an order to respect for keywords before a function: | ||
// `<visibility>, const, async, unsafe, extern, "<ABI>"` | ||
// | ||
// This test ensures the compiler is helpful about them being misplaced. | ||
// Visibilities are tested elsewhere. | ||
|
||
unsafe const fn test() {} | ||
//~^ ERROR expected one of `extern` or `fn`, found keyword `const` | ||
//~| 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` |
13 changes: 13 additions & 0 deletions
13
src/test/ui/parser/issue-87217-keyword-order/wrong-const.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error: expected one of `extern` or `fn`, found keyword `const` | ||
--> $DIR/wrong-const.rs:9:8 | ||
| | ||
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` | ||
|
||
error: aborting due to previous error | ||
|
14 changes: 14 additions & 0 deletions
14
src/test/ui/parser/issue-87217-keyword-order/wrong-unsafe.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// edition:2018 | ||
|
||
// There is an order to respect for keywords before a function: | ||
// `<visibility>, const, async, unsafe, extern, "<ABI>"` | ||
// | ||
// This test ensures the compiler is helpful about them being misplaced. | ||
// Visibilities are tested elsewhere. | ||
|
||
extern unsafe fn test() {} | ||
//~^ ERROR expected `fn`, found keyword `unsafe` | ||
//~| 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` |
13 changes: 13 additions & 0 deletions
13
src/test/ui/parser/issue-87217-keyword-order/wrong-unsafe.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error: expected `fn`, found keyword `unsafe` | ||
--> $DIR/wrong-unsafe.rs:9:8 | ||
| | ||
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` | ||
|
||
error: aborting due to previous error | ||
|