forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#128229 - tdittr:unsafe-extern-abi-error, r=compiler-errors Improve `extern "<abi>" unsafe fn()` error message These errors were already reported in rust-lang#87217, and fixed by rust-lang#87235 but missed the case of an explicit ABI. This PR does not cover multiple keywords like `extern "C" pub const unsafe fn()`, but I don't know what a good way to cover this would be. It also seems rarer than `extern "C" unsafe` which I saw happen a few times in workshops.
- Loading branch information
Showing
5 changed files
with
47 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
trait T { | ||
extern "Rust" unsafe fn foo(); | ||
//~^ ERROR expected `{`, found keyword `unsafe` | ||
//~^ ERROR expected `fn`, found keyword `unsafe` | ||
//~| NOTE expected `fn` | ||
//~| HELP `unsafe` must come before `extern "Rust"` | ||
//~| SUGGESTION unsafe extern "Rust" | ||
//~| NOTE keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern` | ||
} | ||
|
||
fn main() {} |
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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
error: expected `{`, found keyword `unsafe` | ||
error: expected `fn`, found keyword `unsafe` | ||
--> $DIR/issue-19398.rs:2:19 | ||
| | ||
LL | trait T { | ||
| - while parsing this item list starting here | ||
LL | extern "Rust" unsafe fn foo(); | ||
| ^^^^^^ expected `{` | ||
LL | | ||
LL | } | ||
| - the item list ends here | ||
| --------------^^^^^^ | ||
| | | | ||
| | expected `fn` | ||
| help: `unsafe` must come before `extern "Rust"`: `unsafe extern "Rust"` | ||
| | ||
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern` | ||
|
||
error: aborting due to 1 previous error | ||
|
16 changes: 16 additions & 0 deletions
16
tests/ui/parser/issues/issue-87217-keyword-order/wrong-unsafe-abi.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,16 @@ | ||
//@ 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 "C" unsafe fn test() {} | ||
//~^ ERROR expected `fn`, found keyword `unsafe` | ||
//~| NOTE expected `fn` | ||
//~| HELP `unsafe` must come before `extern "C"` | ||
//~| SUGGESTION unsafe extern "C" | ||
//~| NOTE keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern` | ||
|
||
fn main() {} |
13 changes: 13 additions & 0 deletions
13
tests/ui/parser/issues/issue-87217-keyword-order/wrong-unsafe-abi.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-abi.rs:9:12 | ||
| | ||
LL | extern "C" unsafe fn test() {} | ||
| -----------^^^^^^ | ||
| | | | ||
| | expected `fn` | ||
| help: `unsafe` must come before `extern "C"`: `unsafe extern "C"` | ||
| | ||
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern` | ||
|
||
error: aborting due to 1 previous error | ||
|