From 4447949e400822a02cc9945fc39f06842e6b9439 Mon Sep 17 00:00:00 2001 From: SpanishPear Date: Sun, 22 Jan 2023 16:45:56 +1100 Subject: [PATCH] revert to previous span --- compiler/rustc_parse/src/parser/diagnostics.rs | 7 ++++--- src/test/ui/parser/suggest_misplaced_generics/enum.stderr | 2 +- .../suggest_misplaced_generics/fn-complex-generics.stderr | 2 +- .../ui/parser/suggest_misplaced_generics/fn-simple.stderr | 2 +- .../ui/parser/suggest_misplaced_generics/struct.stderr | 2 +- src/test/ui/parser/suggest_misplaced_generics/trait.stderr | 2 +- src/test/ui/parser/suggest_misplaced_generics/type.stderr | 2 +- 7 files changed, 10 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 94bedc07ba1..9ac3bb946dc 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -352,11 +352,12 @@ impl<'a> Parser<'a> { // if there is a `<` after the fn name, then don't show a suggestion, show help if !self.look_ahead(1, |t| *t == token::Lt) && - let Ok(snippet) = self.sess.source_map().span_to_snippet(generic.span) { + let Ok(snippet) = self.sess.source_map().span_to_snippet(generic.span) && + let Ok(ident) = self.sess.source_map().span_to_snippet(self.token.span) { err.span_suggestion_verbose( - self.token.span.shrink_to_hi(), + generic.span.to(self.token.span), format!("place the generic parameter name after the {ident_name} name"), - snippet, + format!(" {ident}{snippet}"), Applicability::MaybeIncorrect, ); } else { diff --git a/src/test/ui/parser/suggest_misplaced_generics/enum.stderr b/src/test/ui/parser/suggest_misplaced_generics/enum.stderr index 8af94856a4a..521cee4f728 100644 --- a/src/test/ui/parser/suggest_misplaced_generics/enum.stderr +++ b/src/test/ui/parser/suggest_misplaced_generics/enum.stderr @@ -7,7 +7,7 @@ LL | enum Foo { Variant(T) } help: place the generic parameter name after the enum name | LL | enum Foo { Variant(T) } - | ~~~ + | ~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/parser/suggest_misplaced_generics/fn-complex-generics.stderr b/src/test/ui/parser/suggest_misplaced_generics/fn-complex-generics.stderr index 196769cb2b5..7d1b44c4494 100644 --- a/src/test/ui/parser/suggest_misplaced_generics/fn-complex-generics.stderr +++ b/src/test/ui/parser/suggest_misplaced_generics/fn-complex-generics.stderr @@ -7,7 +7,7 @@ LL | fn<'a, B: 'a + std::ops::Add> f(_x: B) { } help: place the generic parameter name after the fn name | LL | fn f<'a, B: 'a + std::ops::Add>(_x: B) { } - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/parser/suggest_misplaced_generics/fn-simple.stderr b/src/test/ui/parser/suggest_misplaced_generics/fn-simple.stderr index 0d09d8967b8..40c4581e513 100644 --- a/src/test/ui/parser/suggest_misplaced_generics/fn-simple.stderr +++ b/src/test/ui/parser/suggest_misplaced_generics/fn-simple.stderr @@ -7,7 +7,7 @@ LL | fn id(x: T) -> T { x } help: place the generic parameter name after the fn name | LL | fn id(x: T) -> T { x } - | ~~~ + | ~~~~~ error: aborting due to previous error diff --git a/src/test/ui/parser/suggest_misplaced_generics/struct.stderr b/src/test/ui/parser/suggest_misplaced_generics/struct.stderr index 32ffdb5e9c3..ab17ee57e0b 100644 --- a/src/test/ui/parser/suggest_misplaced_generics/struct.stderr +++ b/src/test/ui/parser/suggest_misplaced_generics/struct.stderr @@ -7,7 +7,7 @@ LL | struct Foo { x: T } help: place the generic parameter name after the struct name | LL | struct Foo { x: T } - | ~~~ + | ~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/parser/suggest_misplaced_generics/trait.stderr b/src/test/ui/parser/suggest_misplaced_generics/trait.stderr index 01a31b7a85a..069683bda1b 100644 --- a/src/test/ui/parser/suggest_misplaced_generics/trait.stderr +++ b/src/test/ui/parser/suggest_misplaced_generics/trait.stderr @@ -7,7 +7,7 @@ LL | trait Foo { help: place the generic parameter name after the trait name | LL | trait Foo { - | ~~~ + | ~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/parser/suggest_misplaced_generics/type.stderr b/src/test/ui/parser/suggest_misplaced_generics/type.stderr index 1ae73fae7f9..a2832965c6d 100644 --- a/src/test/ui/parser/suggest_misplaced_generics/type.stderr +++ b/src/test/ui/parser/suggest_misplaced_generics/type.stderr @@ -7,7 +7,7 @@ LL | type Foo = T; help: place the generic parameter name after the type name | LL | type Foo = T; - | ~~~ + | ~~~~~~ error: aborting due to previous error