Skip to content

Commit b284fb9

Browse files
authored
Unrolled build for rust-lang#131550
Rollup merge of rust-lang#131550 - compiler-errors:extern-diags, r=spastorino Make some tweaks to extern block diagnostics Self-explanatory. See the diagnostic changes; I hope they make them a bit more descriptive. r? spastorino
2 parents 17a19e6 + d6391d5 commit b284fb9

16 files changed

+62
-58
lines changed

compiler/rustc_ast_passes/messages.ftl

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ ast_passes_equality_in_where = equality constraints are not yet supported in `wh
6262
6363
ast_passes_extern_block_suggestion = if you meant to declare an externally defined function, use an `extern` block
6464
65-
ast_passes_extern_fn_qualifiers = functions in `extern` blocks cannot have qualifiers
65+
ast_passes_extern_fn_qualifiers = functions in `extern` blocks cannot have `{$kw}` qualifier
6666
.label = in this `extern` block
67-
.suggestion = remove this qualifier
67+
.suggestion = remove the `{$kw}` qualifier
6868
69-
ast_passes_extern_invalid_safety = items in unadorned `extern` blocks cannot have safety qualifiers
70-
.suggestion = add unsafe to this `extern` block
69+
ast_passes_extern_invalid_safety = items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
70+
.suggestion = add `unsafe` to this `extern` block
7171
7272
ast_passes_extern_item_ascii = items in `extern` blocks cannot use non-ascii identifiers
7373
.label = in this `extern` block

compiler/rustc_ast_passes/src/ast_validation.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -524,21 +524,24 @@ impl<'a> AstValidator<'a> {
524524
// Deconstruct to ensure exhaustiveness
525525
FnHeader { safety: _, coroutine_kind, constness, ext }: FnHeader,
526526
) {
527-
let report_err = |span| {
528-
self.dcx()
529-
.emit_err(errors::FnQualifierInExtern { span, block: self.current_extern_span() });
527+
let report_err = |span, kw| {
528+
self.dcx().emit_err(errors::FnQualifierInExtern {
529+
span,
530+
kw,
531+
block: self.current_extern_span(),
532+
});
530533
};
531534
match coroutine_kind {
532-
Some(knd) => report_err(knd.span()),
535+
Some(kind) => report_err(kind.span(), kind.as_str()),
533536
None => (),
534537
}
535538
match constness {
536-
Const::Yes(span) => report_err(span),
539+
Const::Yes(span) => report_err(span, "const"),
537540
Const::No => (),
538541
}
539542
match ext {
540543
Extern::None => (),
541-
Extern::Implicit(span) | Extern::Explicit(_, span) => report_err(span),
544+
Extern::Implicit(span) | Extern::Explicit(_, span) => report_err(span, "extern"),
542545
}
543546
}
544547

compiler/rustc_ast_passes/src/errors.rs

+1
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ pub(crate) struct FnQualifierInExtern {
295295
pub span: Span,
296296
#[label]
297297
pub block: Span,
298+
pub kw: &'static str,
298299
}
299300

300301
#[derive(Diagnostic)]

tests/rustdoc-json/fns/extern_safe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ extern "C" {
22
//@ is "$.index[*][?(@.name=='f1')].inner.function.header.is_unsafe" true
33
pub fn f1();
44

5-
// items in unadorned `extern` blocks cannot have safety qualifiers
5+
// items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
66
}
77

88
unsafe extern "C" {

tests/ui/extern/issue-95829.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
extern {
44
async fn L() { //~ ERROR: incorrect function inside `extern` block
5-
//~^ ERROR: functions in `extern` blocks cannot have qualifiers
5+
//~^ ERROR: functions in `extern` blocks cannot have `async` qualifier
66
async fn M() {}
77
}
88
}

tests/ui/extern/issue-95829.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ LL | | }
1515
= help: you might have meant to write a function accessible through FFI, which can be done by writing `extern fn` outside of the `extern` block
1616
= note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
1717

18-
error: functions in `extern` blocks cannot have qualifiers
18+
error: functions in `extern` blocks cannot have `async` qualifier
1919
--> $DIR/issue-95829.rs:4:5
2020
|
2121
LL | extern {
2222
| ------ in this `extern` block
2323
LL | async fn L() {
24-
| ^^^^^ help: remove this qualifier
24+
| ^^^^^ help: remove the `async` qualifier
2525

2626
error: aborting due to 2 previous errors
2727

tests/ui/parser/fn-header-semantic-fail.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ fn main() {
4141
}
4242

4343
extern "C" {
44-
async fn fe1(); //~ ERROR functions in `extern` blocks cannot have qualifiers
45-
unsafe fn fe2(); //~ ERROR items in unadorned `extern` blocks cannot have safety qualifiers
46-
const fn fe3(); //~ ERROR functions in `extern` blocks cannot have qualifiers
47-
extern "C" fn fe4(); //~ ERROR functions in `extern` blocks cannot have qualifiers
44+
async fn fe1(); //~ ERROR functions in `extern` blocks cannot
45+
unsafe fn fe2(); //~ ERROR items in `extern` blocks without an `unsafe` qualifier cannot
46+
const fn fe3(); //~ ERROR functions in `extern` blocks cannot
47+
extern "C" fn fe4(); //~ ERROR functions in `extern` blocks cannot
4848
const async unsafe extern "C" fn fe5();
4949
//~^ ERROR functions in `extern` blocks
5050
//~| ERROR functions in `extern` blocks
5151
//~| ERROR functions in `extern` blocks
5252
//~| ERROR functions cannot be both `const` and `async`
53-
//~| ERROR items in unadorned `extern` blocks cannot have safety qualifiers
53+
//~| ERROR items in `extern` blocks without an `unsafe` qualifier cannot have
5454
}
5555
}

tests/ui/parser/fn-header-semantic-fail.stderr

+16-16
Original file line numberDiff line numberDiff line change
@@ -70,77 +70,77 @@ LL | const async unsafe extern "C" fn fi5() {}
7070
| | `async` because of this
7171
| `const` because of this
7272

73-
error: functions in `extern` blocks cannot have qualifiers
73+
error: functions in `extern` blocks cannot have `async` qualifier
7474
--> $DIR/fn-header-semantic-fail.rs:44:9
7575
|
7676
LL | extern "C" {
7777
| ---------- in this `extern` block
7878
LL | async fn fe1();
79-
| ^^^^^ help: remove this qualifier
79+
| ^^^^^ help: remove the `async` qualifier
8080

81-
error: items in unadorned `extern` blocks cannot have safety qualifiers
81+
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
8282
--> $DIR/fn-header-semantic-fail.rs:45:9
8383
|
8484
LL | unsafe fn fe2();
8585
| ^^^^^^^^^^^^^^^^
8686
|
87-
help: add unsafe to this `extern` block
87+
help: add `unsafe` to this `extern` block
8888
|
8989
LL | unsafe extern "C" {
9090
| ++++++
9191

92-
error: functions in `extern` blocks cannot have qualifiers
92+
error: functions in `extern` blocks cannot have `const` qualifier
9393
--> $DIR/fn-header-semantic-fail.rs:46:9
9494
|
9595
LL | extern "C" {
9696
| ---------- in this `extern` block
9797
...
9898
LL | const fn fe3();
99-
| ^^^^^ help: remove this qualifier
99+
| ^^^^^ help: remove the `const` qualifier
100100

101-
error: functions in `extern` blocks cannot have qualifiers
101+
error: functions in `extern` blocks cannot have `extern` qualifier
102102
--> $DIR/fn-header-semantic-fail.rs:47:9
103103
|
104104
LL | extern "C" {
105105
| ---------- in this `extern` block
106106
...
107107
LL | extern "C" fn fe4();
108-
| ^^^^^^^^^^ help: remove this qualifier
108+
| ^^^^^^^^^^ help: remove the `extern` qualifier
109109

110-
error: functions in `extern` blocks cannot have qualifiers
110+
error: functions in `extern` blocks cannot have `async` qualifier
111111
--> $DIR/fn-header-semantic-fail.rs:48:15
112112
|
113113
LL | extern "C" {
114114
| ---------- in this `extern` block
115115
...
116116
LL | const async unsafe extern "C" fn fe5();
117-
| ^^^^^ help: remove this qualifier
117+
| ^^^^^ help: remove the `async` qualifier
118118

119-
error: functions in `extern` blocks cannot have qualifiers
119+
error: functions in `extern` blocks cannot have `const` qualifier
120120
--> $DIR/fn-header-semantic-fail.rs:48:9
121121
|
122122
LL | extern "C" {
123123
| ---------- in this `extern` block
124124
...
125125
LL | const async unsafe extern "C" fn fe5();
126-
| ^^^^^ help: remove this qualifier
126+
| ^^^^^ help: remove the `const` qualifier
127127

128-
error: functions in `extern` blocks cannot have qualifiers
128+
error: functions in `extern` blocks cannot have `extern` qualifier
129129
--> $DIR/fn-header-semantic-fail.rs:48:28
130130
|
131131
LL | extern "C" {
132132
| ---------- in this `extern` block
133133
...
134134
LL | const async unsafe extern "C" fn fe5();
135-
| ^^^^^^^^^^ help: remove this qualifier
135+
| ^^^^^^^^^^ help: remove the `extern` qualifier
136136

137-
error: items in unadorned `extern` blocks cannot have safety qualifiers
137+
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
138138
--> $DIR/fn-header-semantic-fail.rs:48:9
139139
|
140140
LL | const async unsafe extern "C" fn fe5();
141141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
142142
|
143-
help: add unsafe to this `extern` block
143+
help: add `unsafe` to this `extern` block
144144
|
145145
LL | unsafe extern "C" {
146146
| ++++++
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
extern "C" {
22
const fn foo();
3-
//~^ ERROR functions in `extern` blocks cannot have qualifiers
3+
//~^ ERROR functions in `extern` blocks cannot
44
const unsafe fn bar();
5-
//~^ ERROR functions in `extern` blocks cannot have qualifiers
6-
//~| ERROR items in unadorned `extern` blocks cannot have safety qualifiers
5+
//~^ ERROR functions in `extern` blocks cannot
6+
//~| ERROR items in `extern` blocks without an `unsafe` qualifier cannot
77
}
88

99
fn main() {}

tests/ui/parser/no-const-fn-in-extern-block.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
error: functions in `extern` blocks cannot have qualifiers
1+
error: functions in `extern` blocks cannot have `const` qualifier
22
--> $DIR/no-const-fn-in-extern-block.rs:2:5
33
|
44
LL | extern "C" {
55
| ---------- in this `extern` block
66
LL | const fn foo();
7-
| ^^^^^ help: remove this qualifier
7+
| ^^^^^ help: remove the `const` qualifier
88

9-
error: functions in `extern` blocks cannot have qualifiers
9+
error: functions in `extern` blocks cannot have `const` qualifier
1010
--> $DIR/no-const-fn-in-extern-block.rs:4:5
1111
|
1212
LL | extern "C" {
1313
| ---------- in this `extern` block
1414
...
1515
LL | const unsafe fn bar();
16-
| ^^^^^ help: remove this qualifier
16+
| ^^^^^ help: remove the `const` qualifier
1717

18-
error: items in unadorned `extern` blocks cannot have safety qualifiers
18+
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
1919
--> $DIR/no-const-fn-in-extern-block.rs:4:5
2020
|
2121
LL | const unsafe fn bar();
2222
| ^^^^^^^^^^^^^^^^^^^^^^
2323
|
24-
help: add unsafe to this `extern` block
24+
help: add `unsafe` to this `extern` block
2525
|
2626
LL | unsafe extern "C" {
2727
| ++++++

tests/ui/rust-2024/unsafe-extern-blocks/safe-unsafe-on-unadorned-extern-block.edition2021.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
error: items in unadorned `extern` blocks cannot have safety qualifiers
1+
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
22
--> $DIR/safe-unsafe-on-unadorned-extern-block.rs:8:5
33
|
44
LL | safe static TEST1: i32;
55
| ^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
help: add unsafe to this `extern` block
7+
help: add `unsafe` to this `extern` block
88
|
99
LL | unsafe extern "C" {
1010
| ++++++
1111

12-
error: items in unadorned `extern` blocks cannot have safety qualifiers
12+
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
1313
--> $DIR/safe-unsafe-on-unadorned-extern-block.rs:10:5
1414
|
1515
LL | safe fn test1(i: i32);
1616
| ^^^^^^^^^^^^^^^^^^^^^^
1717
|
18-
help: add unsafe to this `extern` block
18+
help: add `unsafe` to this `extern` block
1919
|
2020
LL | unsafe extern "C" {
2121
| ++++++

tests/ui/rust-2024/unsafe-extern-blocks/safe-unsafe-on-unadorned-extern-block.edition2024.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@ LL | |
1010
LL | | }
1111
| |_^
1212

13-
error: items in unadorned `extern` blocks cannot have safety qualifiers
13+
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
1414
--> $DIR/safe-unsafe-on-unadorned-extern-block.rs:8:5
1515
|
1616
LL | safe static TEST1: i32;
1717
| ^^^^^^^^^^^^^^^^^^^^^^^
1818
|
19-
help: add unsafe to this `extern` block
19+
help: add `unsafe` to this `extern` block
2020
|
2121
LL | unsafe extern "C" {
2222
| ++++++
2323

24-
error: items in unadorned `extern` blocks cannot have safety qualifiers
24+
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
2525
--> $DIR/safe-unsafe-on-unadorned-extern-block.rs:10:5
2626
|
2727
LL | safe fn test1(i: i32);
2828
| ^^^^^^^^^^^^^^^^^^^^^^
2929
|
30-
help: add unsafe to this `extern` block
30+
help: add `unsafe` to this `extern` block
3131
|
3232
LL | unsafe extern "C" {
3333
| ++++++

tests/ui/rust-2024/unsafe-extern-blocks/safe-unsafe-on-unadorned-extern-block.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
extern "C" {
77
//[edition2024]~^ ERROR extern blocks must be unsafe
88
safe static TEST1: i32;
9-
//~^ ERROR items in unadorned `extern` blocks cannot have safety qualifiers
9+
//~^ ERROR items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
1010
safe fn test1(i: i32);
11-
//~^ ERROR items in unadorned `extern` blocks cannot have safety qualifiers
11+
//~^ ERROR items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
1212
}
1313

1414
fn test2() {

tests/ui/rust-2024/unsafe-extern-blocks/unsafe-on-extern-block-issue-126756.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![allow(dead_code)]
44

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

99
fn main() {}

tests/ui/rust-2024/unsafe-extern-blocks/unsafe-on-extern-block-issue-126756.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![allow(dead_code)]
44

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

99
fn main() {}

tests/ui/rust-2024/unsafe-extern-blocks/unsafe-on-extern-block-issue-126756.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: items in unadorned `extern` blocks cannot have safety qualifiers
1+
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
22
--> $DIR/unsafe-on-extern-block-issue-126756.rs:6:5
33
|
44
LL | unsafe fn foo();
55
| ^^^^^^^^^^^^^^^^
66
|
7-
help: add unsafe to this `extern` block
7+
help: add `unsafe` to this `extern` block
88
|
99
LL | unsafe extern "C" {
1010
| ++++++

0 commit comments

Comments
 (0)