Skip to content

Commit

Permalink
move to multipart spans
Browse files Browse the repository at this point in the history
  • Loading branch information
SpanishPear committed Jan 31, 2023
1 parent 8292d07 commit 70bfcc2
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 17 deletions.
11 changes: 6 additions & 5 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,13 @@ 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(ident) = self.sess.source_map().span_to_snippet(self.token.span) {
err.span_suggestion_verbose(
generic.span.to(self.token.span),
let Ok(snippet) = self.sess.source_map().span_to_snippet(generic.span) {
err.multipart_suggestion_verbose(
format!("place the generic parameter name after the {ident_name} name"),
format!(" {ident}{snippet}"),
vec![
(self.token.span.shrink_to_hi(), snippet),
(generic.span, String::new())
],
Applicability::MaybeIncorrect,
);
} else {
Expand Down
5 changes: 3 additions & 2 deletions tests/ui/parser/suggest_misplaced_generics/enum.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ LL | enum<T> Foo { Variant(T) }
|
help: place the generic parameter name after the enum name
|
LL | enum Foo<T> { Variant(T) }
| ~~~~~~
LL - enum<T> Foo { Variant(T) }
LL + enum Foo<T> { Variant(T) }
|

error: aborting due to previous error

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ LL | fn<'a, B: 'a + std::ops::Add<Output = u32>> f(_x: B) { }
|
help: place the generic parameter name after the fn name
|
LL | fn f<'a, B: 'a + std::ops::Add<Output = u32>>(_x: B) { }
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LL - fn<'a, B: 'a + std::ops::Add<Output = u32>> f(_x: B) { }
LL + fn f<'a, B: 'a + std::ops::Add<Output = u32>>(_x: B) { }
|

error: aborting due to previous error

5 changes: 3 additions & 2 deletions tests/ui/parser/suggest_misplaced_generics/fn-simple.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ LL | fn<T> id(x: T) -> T { x }
|
help: place the generic parameter name after the fn name
|
LL | fn id<T>(x: T) -> T { x }
| ~~~~~
LL - fn<T> id(x: T) -> T { x }
LL + fn id<T>(x: T) -> T { x }
|

error: aborting due to previous error

5 changes: 3 additions & 2 deletions tests/ui/parser/suggest_misplaced_generics/struct.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ LL | struct<T> Foo { x: T }
|
help: place the generic parameter name after the struct name
|
LL | struct Foo<T> { x: T }
| ~~~~~~
LL - struct<T> Foo { x: T }
LL + struct Foo<T> { x: T }
|

error: aborting due to previous error

5 changes: 3 additions & 2 deletions tests/ui/parser/suggest_misplaced_generics/trait.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ LL | trait<T> Foo {
|
help: place the generic parameter name after the trait name
|
LL | trait Foo<T> {
| ~~~~~~
LL - trait<T> Foo {
LL + trait Foo<T> {
|

error: aborting due to previous error

5 changes: 3 additions & 2 deletions tests/ui/parser/suggest_misplaced_generics/type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ LL | type<T> Foo = T;
|
help: place the generic parameter name after the type name
|
LL | type Foo<T> = T;
| ~~~~~~
LL - type<T> Foo = T;
LL + type Foo<T> = T;
|

error: aborting due to previous error

0 comments on commit 70bfcc2

Please sign in to comment.