diff options
| author | Michael Goulet <michael@errs.io> | 2022-05-30 15:57:27 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-30 15:57:27 -0700 |
| commit | 22da719762c1d101c20f59620f1445f5eaf75bba (patch) | |
| tree | f823806dacf96d81cbb1385152f08feed9c87f3d /src/test/ui/parser | |
| parent | 3c0b9d50ae43eb4c13390fcc363e7cc4d4d661d3 (diff) | |
| parent | 0be2ca96fa7d723db870fb2f96df0f07d32c0774 (diff) | |
| download | rust-22da719762c1d101c20f59620f1445f5eaf75bba.tar.gz rust-22da719762c1d101c20f59620f1445f5eaf75bba.zip | |
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.
Diffstat (limited to 'src/test/ui/parser')
| -rw-r--r-- | src/test/ui/parser/issues/issue-19398.stderr | 7 | ||||
| -rw-r--r-- | src/test/ui/parser/unsafe-foreign-mod-2.rs | 8 | ||||
| -rw-r--r-- | src/test/ui/parser/unsafe-foreign-mod-2.stderr | 28 |
3 files changed, 37 insertions, 6 deletions
diff --git a/src/test/ui/parser/issues/issue-19398.stderr b/src/test/ui/parser/issues/issue-19398.stderr index bbd85374b4b..1da00960adf 100644 --- a/src/test/ui/parser/issues/issue-19398.stderr +++ b/src/test/ui/parser/issues/issue-19398.stderr @@ -4,15 +4,10 @@ error: expected `{`, found keyword `unsafe` LL | trait T { | - while parsing this item list starting here LL | extern "Rust" unsafe fn foo(); - | --------------^^^^^^ - | | | - | | expected `{` - | help: `unsafe` must come before `extern "Rust"`: `unsafe extern "Rust"` + | ^^^^^^ expected `{` LL | LL | } | - the item list ends here - | - = note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern` error: aborting due to previous error diff --git a/src/test/ui/parser/unsafe-foreign-mod-2.rs b/src/test/ui/parser/unsafe-foreign-mod-2.rs new file mode 100644 index 00000000000..77856fb6734 --- /dev/null +++ b/src/test/ui/parser/unsafe-foreign-mod-2.rs @@ -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() {} diff --git a/src/test/ui/parser/unsafe-foreign-mod-2.stderr b/src/test/ui/parser/unsafe-foreign-mod-2.stderr new file mode 100644 index 00000000000..7cc2de141ae --- /dev/null +++ b/src/test/ui/parser/unsafe-foreign-mod-2.stderr @@ -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 + |
