diff options
| author | Santiago Pastorino <spastorino@gmail.com> | 2024-05-27 15:35:34 -0300 |
|---|---|---|
| committer | Santiago Pastorino <spastorino@gmail.com> | 2024-06-04 14:19:43 -0300 |
| commit | b4cbdb7246c633ab0ebc6ae4bbe4883cde79e787 (patch) | |
| tree | 29d5ede480bac488933745723a43fe8ac1ae43ed /tests/ui/parser | |
| parent | 2a377122dd41291747153ac82289e34a72275138 (diff) | |
| download | rust-b4cbdb7246c633ab0ebc6ae4bbe4883cde79e787.tar.gz rust-b4cbdb7246c633ab0ebc6ae4bbe4883cde79e787.zip | |
Fail when using safe/unsafe items inside unadorned extern blocks
Diffstat (limited to 'tests/ui/parser')
| -rw-r--r-- | tests/ui/parser/fn-header-semantic-fail.rs | 3 | ||||
| -rw-r--r-- | tests/ui/parser/fn-header-semantic-fail.stderr | 20 | ||||
| -rw-r--r-- | tests/ui/parser/no-const-fn-in-extern-block.rs | 1 | ||||
| -rw-r--r-- | tests/ui/parser/no-const-fn-in-extern-block.stderr | 11 |
4 files changed, 32 insertions, 3 deletions
diff --git a/tests/ui/parser/fn-header-semantic-fail.rs b/tests/ui/parser/fn-header-semantic-fail.rs index 3b98433cdd8..5907ac05260 100644 --- a/tests/ui/parser/fn-header-semantic-fail.rs +++ b/tests/ui/parser/fn-header-semantic-fail.rs @@ -44,7 +44,7 @@ fn main() { extern "C" { async fn fe1(); //~ ERROR functions in `extern` blocks cannot have qualifiers - unsafe fn fe2(); + unsafe fn fe2(); //~ ERROR items in unadorned `extern` blocks cannot have safety qualifiers const fn fe3(); //~ ERROR functions in `extern` blocks cannot have qualifiers extern "C" fn fe4(); //~ ERROR functions in `extern` blocks cannot have qualifiers const async unsafe extern "C" fn fe5(); @@ -52,5 +52,6 @@ fn main() { //~| ERROR functions in `extern` blocks //~| ERROR functions in `extern` blocks //~| ERROR functions cannot be both `const` and `async` + //~| ERROR items in unadorned `extern` blocks cannot have safety qualifiers } } diff --git a/tests/ui/parser/fn-header-semantic-fail.stderr b/tests/ui/parser/fn-header-semantic-fail.stderr index dc2a216754d..abaa6527b0a 100644 --- a/tests/ui/parser/fn-header-semantic-fail.stderr +++ b/tests/ui/parser/fn-header-semantic-fail.stderr @@ -78,6 +78,15 @@ LL | extern "C" { LL | async fn fe1(); | ^^^^^ help: remove this qualifier +error: items in unadorned `extern` blocks cannot have safety qualifiers + --> $DIR/fn-header-semantic-fail.rs:47:9 + | +LL | extern "C" { + | ---------- help: add unsafe to this `extern` block +LL | async fn fe1(); +LL | unsafe fn fe2(); + | ^^^^^^^^^^^^^^^^ + error: functions in `extern` blocks cannot have qualifiers --> $DIR/fn-header-semantic-fail.rs:48:9 | @@ -96,6 +105,15 @@ LL | extern "C" { LL | extern "C" fn fe4(); | ^^^^^^^^^^ help: remove this qualifier +error: items in unadorned `extern` blocks cannot have safety qualifiers + --> $DIR/fn-header-semantic-fail.rs:50:9 + | +LL | extern "C" { + | ---------- help: add unsafe to this `extern` block +... +LL | const async unsafe extern "C" fn fe5(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error: functions in `extern` blocks cannot have qualifiers --> $DIR/fn-header-semantic-fail.rs:50:15 | @@ -132,6 +150,6 @@ LL | const async unsafe extern "C" fn fe5(); | | `async` because of this | `const` because of this -error: aborting due to 15 previous errors +error: aborting due to 17 previous errors For more information about this error, try `rustc --explain E0379`. diff --git a/tests/ui/parser/no-const-fn-in-extern-block.rs b/tests/ui/parser/no-const-fn-in-extern-block.rs index 1993124edc3..3ad9ba006d3 100644 --- a/tests/ui/parser/no-const-fn-in-extern-block.rs +++ b/tests/ui/parser/no-const-fn-in-extern-block.rs @@ -3,6 +3,7 @@ extern "C" { //~^ ERROR functions in `extern` blocks cannot have qualifiers const unsafe fn bar(); //~^ ERROR functions in `extern` blocks cannot have qualifiers + //~| ERROR items in unadorned `extern` blocks cannot have safety qualifiers } fn main() {} diff --git a/tests/ui/parser/no-const-fn-in-extern-block.stderr b/tests/ui/parser/no-const-fn-in-extern-block.stderr index 2dec6f76931..892024ce893 100644 --- a/tests/ui/parser/no-const-fn-in-extern-block.stderr +++ b/tests/ui/parser/no-const-fn-in-extern-block.stderr @@ -6,6 +6,15 @@ LL | extern "C" { LL | const fn foo(); | ^^^^^ help: remove this qualifier +error: items in unadorned `extern` blocks cannot have safety qualifiers + --> $DIR/no-const-fn-in-extern-block.rs:4:5 + | +LL | extern "C" { + | ---------- help: add unsafe to this `extern` block +... +LL | const unsafe fn bar(); + | ^^^^^^^^^^^^^^^^^^^^^^ + error: functions in `extern` blocks cannot have qualifiers --> $DIR/no-const-fn-in-extern-block.rs:4:5 | @@ -15,5 +24,5 @@ LL | extern "C" { LL | const unsafe fn bar(); | ^^^^^ help: remove this qualifier -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors |
