Skip to content

Make some tweaks to extern block diagnostics #131550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Remove unadorned
  • Loading branch information
compiler-errors committed Oct 11, 2024
commit c085071631bd26227994fefeb4c34aa33e4d4cef
4 changes: 2 additions & 2 deletions compiler/rustc_ast_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ ast_passes_extern_fn_qualifiers = functions in `extern` blocks cannot have quali
.label = in this `extern` block
.suggestion = remove this qualifier

ast_passes_extern_invalid_safety = items in unadorned `extern` blocks cannot have safety qualifiers
.suggestion = add unsafe to this `extern` block
ast_passes_extern_invalid_safety = items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
.suggestion = add `unsafe` to this `extern` block

ast_passes_extern_item_ascii = items in `extern` blocks cannot use non-ascii identifiers
.label = in this `extern` block
Expand Down
2 changes: 1 addition & 1 deletion tests/rustdoc-json/fns/extern_safe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extern "C" {
//@ is "$.index[*][?(@.name=='f1')].inner.function.header.is_unsafe" true
pub fn f1();

// items in unadorned `extern` blocks cannot have safety qualifiers
// items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
}

unsafe extern "C" {
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/parser/fn-header-semantic-fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ fn main() {

extern "C" {
async fn fe1(); //~ ERROR functions in `extern` blocks cannot have qualifiers
unsafe fn fe2(); //~ ERROR items in unadorned `extern` blocks cannot have safety qualifiers
unsafe fn fe2(); //~ ERROR items in `extern` blocks without an `unsafe` qualifier 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();
//~^ ERROR functions in `extern` blocks
//~| 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
//~| ERROR items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
}
}
8 changes: 4 additions & 4 deletions tests/ui/parser/fn-header-semantic-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ LL | extern "C" {
LL | async fn fe1();
| ^^^^^ help: remove this qualifier

error: items in unadorned `extern` blocks cannot have safety qualifiers
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
--> $DIR/fn-header-semantic-fail.rs:45:9
|
LL | unsafe fn fe2();
| ^^^^^^^^^^^^^^^^
|
help: add unsafe to this `extern` block
help: add `unsafe` to this `extern` block
|
LL | unsafe extern "C" {
| ++++++
Expand Down Expand Up @@ -134,13 +134,13 @@ LL | extern "C" {
LL | const async unsafe extern "C" fn fe5();
| ^^^^^^^^^^ help: remove this qualifier

error: items in unadorned `extern` blocks cannot have safety qualifiers
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
--> $DIR/fn-header-semantic-fail.rs:48:9
|
LL | const async unsafe extern "C" fn fe5();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: add unsafe to this `extern` block
help: add `unsafe` to this `extern` block
|
LL | unsafe extern "C" {
| ++++++
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/parser/no-const-fn-in-extern-block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +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
//~| ERROR items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
}

fn main() {}
4 changes: 2 additions & 2 deletions tests/ui/parser/no-const-fn-in-extern-block.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ LL | extern "C" {
LL | const unsafe fn bar();
| ^^^^^ help: remove this qualifier

error: items in unadorned `extern` blocks cannot have safety qualifiers
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
--> $DIR/no-const-fn-in-extern-block.rs:4:5
|
LL | const unsafe fn bar();
| ^^^^^^^^^^^^^^^^^^^^^^
|
help: add unsafe to this `extern` block
help: add `unsafe` to this `extern` block
|
LL | unsafe extern "C" {
| ++++++
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
error: items in unadorned `extern` blocks cannot have safety qualifiers
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
--> $DIR/safe-unsafe-on-unadorned-extern-block.rs:8:5
|
LL | safe static TEST1: i32;
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: add unsafe to this `extern` block
help: add `unsafe` to this `extern` block
|
LL | unsafe extern "C" {
| ++++++

error: items in unadorned `extern` blocks cannot have safety qualifiers
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
--> $DIR/safe-unsafe-on-unadorned-extern-block.rs:10:5
|
LL | safe fn test1(i: i32);
| ^^^^^^^^^^^^^^^^^^^^^^
|
help: add unsafe to this `extern` block
help: add `unsafe` to this `extern` block
|
LL | unsafe extern "C" {
| ++++++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ LL | |
LL | | }
| |_^

error: items in unadorned `extern` blocks cannot have safety qualifiers
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
--> $DIR/safe-unsafe-on-unadorned-extern-block.rs:8:5
|
LL | safe static TEST1: i32;
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: add unsafe to this `extern` block
help: add `unsafe` to this `extern` block
|
LL | unsafe extern "C" {
| ++++++

error: items in unadorned `extern` blocks cannot have safety qualifiers
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
--> $DIR/safe-unsafe-on-unadorned-extern-block.rs:10:5
|
LL | safe fn test1(i: i32);
| ^^^^^^^^^^^^^^^^^^^^^^
|
help: add unsafe to this `extern` block
help: add `unsafe` to this `extern` block
|
LL | unsafe extern "C" {
| ++++++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
extern "C" {
//[edition2024]~^ ERROR extern blocks must be unsafe
safe static TEST1: i32;
//~^ ERROR items in unadorned `extern` blocks cannot have safety qualifiers
//~^ ERROR items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
safe fn test1(i: i32);
//~^ ERROR items in unadorned `extern` blocks cannot have safety qualifiers
//~^ ERROR items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
}

fn test2() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![allow(dead_code)]

unsafe extern "C" {
unsafe fn foo(); //~ ERROR items in unadorned `extern` blocks cannot have safety qualifiers
unsafe fn foo(); //~ ERROR items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
}

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![allow(dead_code)]

extern "C" {
unsafe fn foo(); //~ ERROR items in unadorned `extern` blocks cannot have safety qualifiers
unsafe fn foo(); //~ ERROR items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error: items in unadorned `extern` blocks cannot have safety qualifiers
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
--> $DIR/unsafe-on-extern-block-issue-126756.rs:6:5
|
LL | unsafe fn foo();
| ^^^^^^^^^^^^^^^^
|
help: add unsafe to this `extern` block
help: add `unsafe` to this `extern` block
|
LL | unsafe extern "C" {
| ++++++
Expand Down