Skip to content

Commit 3f0f224

Browse files
authored
Rollup merge of #79082 - ThePuzzlemaker:issue-78941-fix, r=estebank
Improve the diagnostic for when an `fn` contains qualifiers inside an `extern` block. This mitigates #78941. As suggested by ```@estebank,``` `span_suggestion` was replaced with `span_suggestion_verbose` for this specific diagnostic.
2 parents 5a58b50 + b8ed466 commit 3f0f224

File tree

3 files changed

+43
-22
lines changed

3 files changed

+43
-22
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ impl<'a> AstValidator<'a> {
522522
self.err_handler()
523523
.struct_span_err(ident.span, "functions in `extern` blocks cannot have qualifiers")
524524
.span_label(self.current_extern_span(), "in this `extern` block")
525-
.span_suggestion(
525+
.span_suggestion_verbose(
526526
span.until(ident.span.shrink_to_lo()),
527527
"remove the qualifiers",
528528
"fn ".to_string(),

src/test/ui/parser/fn-header-semantic-fail.stderr

+30-15
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,12 @@ error: functions in `extern` blocks cannot have qualifiers
108108
LL | extern {
109109
| ------ in this `extern` block
110110
LL | async fn fe1();
111-
| ---------^^^
112-
| |
113-
| help: remove the qualifiers: `fn`
111+
| ^^^
112+
|
113+
help: remove the qualifiers
114+
|
115+
LL | fn fe1();
116+
| ^^
114117

115118
error: functions in `extern` blocks cannot have qualifiers
116119
--> $DIR/fn-header-semantic-fail.rs:52:19
@@ -119,9 +122,12 @@ LL | extern {
119122
| ------ in this `extern` block
120123
LL | async fn fe1();
121124
LL | unsafe fn fe2();
122-
| ----------^^^
123-
| |
124-
| help: remove the qualifiers: `fn`
125+
| ^^^
126+
|
127+
help: remove the qualifiers
128+
|
129+
LL | fn fe2();
130+
| ^^
125131

126132
error: functions in `extern` blocks cannot have qualifiers
127133
--> $DIR/fn-header-semantic-fail.rs:53:18
@@ -130,9 +136,12 @@ LL | extern {
130136
| ------ in this `extern` block
131137
...
132138
LL | const fn fe3();
133-
| ---------^^^
134-
| |
135-
| help: remove the qualifiers: `fn`
139+
| ^^^
140+
|
141+
help: remove the qualifiers
142+
|
143+
LL | fn fe3();
144+
| ^^
136145

137146
error: functions in `extern` blocks cannot have qualifiers
138147
--> $DIR/fn-header-semantic-fail.rs:54:23
@@ -141,9 +150,12 @@ LL | extern {
141150
| ------ in this `extern` block
142151
...
143152
LL | extern "C" fn fe4();
144-
| --------------^^^
145-
| |
146-
| help: remove the qualifiers: `fn`
153+
| ^^^
154+
|
155+
help: remove the qualifiers
156+
|
157+
LL | fn fe4();
158+
| ^^
147159

148160
error: functions in `extern` blocks cannot have qualifiers
149161
--> $DIR/fn-header-semantic-fail.rs:55:42
@@ -152,9 +164,12 @@ LL | extern {
152164
| ------ in this `extern` block
153165
...
154166
LL | const async unsafe extern "C" fn fe5();
155-
| ---------------------------------^^^
156-
| |
157-
| help: remove the qualifiers: `fn`
167+
| ^^^
168+
|
169+
help: remove the qualifiers
170+
|
171+
LL | fn fe5();
172+
| ^^
158173

159174
error: functions cannot be both `const` and `async`
160175
--> $DIR/fn-header-semantic-fail.rs:55:9

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

+12-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ error: functions in `extern` blocks cannot have qualifiers
44
LL | extern {
55
| ------ in this `extern` block
66
LL | const fn foo();
7-
| ---------^^^
8-
| |
9-
| help: remove the qualifiers: `fn`
7+
| ^^^
8+
|
9+
help: remove the qualifiers
10+
|
11+
LL | fn foo();
12+
| ^^
1013

1114
error: functions in `extern` blocks cannot have qualifiers
1215
--> $DIR/no-const-fn-in-extern-block.rs:4:21
@@ -15,9 +18,12 @@ LL | extern {
1518
| ------ in this `extern` block
1619
...
1720
LL | const unsafe fn bar();
18-
| ----------------^^^
19-
| |
20-
| help: remove the qualifiers: `fn`
21+
| ^^^
22+
|
23+
help: remove the qualifiers
24+
|
25+
LL | fn bar();
26+
| ^^
2127

2228
error: aborting due to 2 previous errors
2329

0 commit comments

Comments
 (0)