Skip to content

Improve the diagnostic for when an fn contains qualifiers inside an extern block. #79082

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
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ impl<'a> AstValidator<'a> {
self.err_handler()
.struct_span_err(ident.span, "functions in `extern` blocks cannot have qualifiers")
.span_label(self.current_extern_span(), "in this `extern` block")
.span_suggestion(
.span_suggestion_verbose(
span.until(ident.span.shrink_to_lo()),
"remove the qualifiers",
"fn ".to_string(),
Expand Down
45 changes: 30 additions & 15 deletions src/test/ui/parser/fn-header-semantic-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,12 @@ error: functions in `extern` blocks cannot have qualifiers
LL | extern {
| ------ in this `extern` block
LL | async fn fe1();
| ---------^^^
| |
| help: remove the qualifiers: `fn`
| ^^^
|
help: remove the qualifiers
|
LL | fn fe1();
| ^^

error: functions in `extern` blocks cannot have qualifiers
--> $DIR/fn-header-semantic-fail.rs:52:19
Expand All @@ -119,9 +122,12 @@ LL | extern {
| ------ in this `extern` block
LL | async fn fe1();
LL | unsafe fn fe2();
| ----------^^^
| |
| help: remove the qualifiers: `fn`
| ^^^
|
help: remove the qualifiers
|
LL | fn fe2();
| ^^

error: functions in `extern` blocks cannot have qualifiers
--> $DIR/fn-header-semantic-fail.rs:53:18
Expand All @@ -130,9 +136,12 @@ LL | extern {
| ------ in this `extern` block
...
LL | const fn fe3();
| ---------^^^
| |
| help: remove the qualifiers: `fn`
| ^^^
|
help: remove the qualifiers
|
LL | fn fe3();
| ^^

error: functions in `extern` blocks cannot have qualifiers
--> $DIR/fn-header-semantic-fail.rs:54:23
Expand All @@ -141,9 +150,12 @@ LL | extern {
| ------ in this `extern` block
...
LL | extern "C" fn fe4();
| --------------^^^
| |
| help: remove the qualifiers: `fn`
| ^^^
|
help: remove the qualifiers
|
LL | fn fe4();
| ^^

error: functions in `extern` blocks cannot have qualifiers
--> $DIR/fn-header-semantic-fail.rs:55:42
Expand All @@ -152,9 +164,12 @@ LL | extern {
| ------ in this `extern` block
...
LL | const async unsafe extern "C" fn fe5();
| ---------------------------------^^^
| |
| help: remove the qualifiers: `fn`
| ^^^
|
help: remove the qualifiers
|
LL | fn fe5();
| ^^

error: functions cannot be both `const` and `async`
--> $DIR/fn-header-semantic-fail.rs:55:9
Expand Down
18 changes: 12 additions & 6 deletions src/test/ui/parser/no-const-fn-in-extern-block.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ error: functions in `extern` blocks cannot have qualifiers
LL | extern {
| ------ in this `extern` block
LL | const fn foo();
| ---------^^^
| |
| help: remove the qualifiers: `fn`
| ^^^
|
help: remove the qualifiers
|
LL | fn foo();
| ^^

error: functions in `extern` blocks cannot have qualifiers
--> $DIR/no-const-fn-in-extern-block.rs:4:21
Expand All @@ -15,9 +18,12 @@ LL | extern {
| ------ in this `extern` block
...
LL | const unsafe fn bar();
| ----------------^^^
| |
| help: remove the qualifiers: `fn`
| ^^^
|
help: remove the qualifiers
|
LL | fn bar();
| ^^

error: aborting due to 2 previous errors