Skip to content

Commit

Permalink
Rollup merge of rust-lang#79082 - ThePuzzlemaker:issue-78941-fix, r=e…
Browse files Browse the repository at this point in the history
…stebank

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

This mitigates rust-lang#78941. As suggested by `@estebank,` `span_suggestion` was replaced with `span_suggestion_verbose` for this specific diagnostic.
  • Loading branch information
Dylan-DPC committed Nov 19, 2020
2 parents bd51d55 + b8ed466 commit 966b5c8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 22 deletions.
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

0 comments on commit 966b5c8

Please sign in to comment.