Skip to content

Commit d6391d5

Browse files
Note what qualifier
1 parent c085071 commit d6391d5

9 files changed

+39
-35
lines changed

compiler/rustc_ast_passes/messages.ftl

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ ast_passes_equality_in_where = equality constraints are not yet supported in `wh
6666
6767
ast_passes_extern_block_suggestion = if you meant to declare an externally defined function, use an `extern` block
6868
69-
ast_passes_extern_fn_qualifiers = functions in `extern` blocks cannot have qualifiers
69+
ast_passes_extern_fn_qualifiers = functions in `extern` blocks cannot have `{$kw}` qualifier
7070
.label = in this `extern` block
71-
.suggestion = remove this qualifier
71+
.suggestion = remove the `{$kw}` qualifier
7272
7373
ast_passes_extern_invalid_safety = items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
7474
.suggestion = add `unsafe` to this `extern` block

compiler/rustc_ast_passes/src/ast_validation.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -561,21 +561,24 @@ impl<'a> AstValidator<'a> {
561561
// Deconstruct to ensure exhaustiveness
562562
FnHeader { safety: _, coroutine_kind, constness, ext }: FnHeader,
563563
) {
564-
let report_err = |span| {
565-
self.dcx()
566-
.emit_err(errors::FnQualifierInExtern { span, block: self.current_extern_span() });
564+
let report_err = |span, kw| {
565+
self.dcx().emit_err(errors::FnQualifierInExtern {
566+
span,
567+
kw,
568+
block: self.current_extern_span(),
569+
});
567570
};
568571
match coroutine_kind {
569-
Some(knd) => report_err(knd.span()),
572+
Some(kind) => report_err(kind.span(), kind.as_str()),
570573
None => (),
571574
}
572575
match constness {
573-
Const::Yes(span) => report_err(span),
576+
Const::Yes(span) => report_err(span, "const"),
574577
Const::No => (),
575578
}
576579
match ext {
577580
Extern::None => (),
578-
Extern::Implicit(span) | Extern::Explicit(_, span) => report_err(span),
581+
Extern::Implicit(span) | Extern::Explicit(_, span) => report_err(span, "extern"),
579582
}
580583
}
581584

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/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 `extern` blocks without an `unsafe` qualifier 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 `extern` blocks without an `unsafe` qualifier 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

+12-12
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ 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

8181
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
8282
--> $DIR/fn-header-semantic-fail.rs:45:9
@@ -89,50 +89,50 @@ help: add `unsafe` to this `extern` block
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

137137
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
138138
--> $DIR/fn-header-semantic-fail.rs:48:9
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 `extern` blocks without an `unsafe` qualifier 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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
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

1818
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
1919
--> $DIR/no-const-fn-in-extern-block.rs:4:5

0 commit comments

Comments
 (0)