From 92aa0e6295c39db945966d080236931396e59939 Mon Sep 17 00:00:00 2001 From: ThePuzzlemaker Date: Sun, 15 Nov 2020 14:36:07 -0600 Subject: [PATCH 1/2] Use `span_suggestion_verbose` instead of `span_suggestion` for `fn` with qualifiers inside an `extern "C"` block --- compiler/rustc_ast_passes/src/ast_validation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index bb1d2967d6a4e..08ebcbf381a15 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -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(), From b8ed466b240887c871909f5e30ea3662a356d19a Mon Sep 17 00:00:00 2001 From: ThePuzzlemaker Date: Sun, 15 Nov 2020 15:34:51 -0600 Subject: [PATCH 2/2] Fix ui tests for `fn`s with qualifiers in `extern` blocks --- .../ui/parser/fn-header-semantic-fail.stderr | 45 ++++++++++++------- .../parser/no-const-fn-in-extern-block.stderr | 18 +++++--- 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/src/test/ui/parser/fn-header-semantic-fail.stderr b/src/test/ui/parser/fn-header-semantic-fail.stderr index 4193b3ee695bc..2f11f95bf4a7f 100644 --- a/src/test/ui/parser/fn-header-semantic-fail.stderr +++ b/src/test/ui/parser/fn-header-semantic-fail.stderr @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/test/ui/parser/no-const-fn-in-extern-block.stderr b/src/test/ui/parser/no-const-fn-in-extern-block.stderr index de653987e406d..af92f2d94f2cc 100644 --- a/src/test/ui/parser/no-const-fn-in-extern-block.stderr +++ b/src/test/ui/parser/no-const-fn-in-extern-block.stderr @@ -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 @@ -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