-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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 #97172 - SparrowLii:unsafe_extern, r=compiler-errors
Optimize the diagnostic generation for `extern unsafe` This PR does the following about diagnostic generation when parsing foreign mod: 1. Fixes the FIXME about avoiding depending on the error message text. 2. Continue parsing when `unsafe` is followed by `{` (just like `unsafe extern {...}`). 3. Add test case.
- Loading branch information
Showing
4 changed files
with
52 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
extern "C" unsafe { | ||
//~^ ERROR expected `{`, found keyword `unsafe` | ||
//~| ERROR extern block cannot be declared unsafe | ||
unsafe fn foo(); | ||
//~^ ERROR functions in `extern` blocks cannot have qualifiers | ||
} | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
error: expected `{`, found keyword `unsafe` | ||
--> $DIR/unsafe-foreign-mod-2.rs:1:12 | ||
| | ||
LL | extern "C" unsafe { | ||
| ^^^^^^ expected `{` | ||
|
||
error: extern block cannot be declared unsafe | ||
--> $DIR/unsafe-foreign-mod-2.rs:1:12 | ||
| | ||
LL | extern "C" unsafe { | ||
| ^^^^^^ | ||
|
||
error: functions in `extern` blocks cannot have qualifiers | ||
--> $DIR/unsafe-foreign-mod-2.rs:4:15 | ||
| | ||
LL | extern "C" unsafe { | ||
| ----------------- in this `extern` block | ||
... | ||
LL | unsafe fn foo(); | ||
| ^^^ | ||
| | ||
help: remove the qualifiers | ||
| | ||
LL | fn foo(); | ||
| ~~ | ||
|
||
error: aborting due to 3 previous errors | ||
|