Skip to content

Commit 99c946c

Browse files
committed
Better suggestion span for missing type parameter
1 parent 783c4b9 commit 99c946c

File tree

7 files changed

+10
-11
lines changed

7 files changed

+10
-11
lines changed

compiler/rustc_hir_analysis/src/errors.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,10 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for MissingTypeParams {
454454
// The user wrote `Iterator`, so we don't have a type we can suggest, but at
455455
// least we can clue them to the correct syntax `Iterator<Type>`.
456456
err.span_suggestion(
457-
self.span,
457+
self.span.shrink_to_hi(),
458458
fluent::hir_analysis_suggestion,
459459
format!(
460-
"{}<{}>",
461-
snippet,
460+
"<{}>",
462461
self.missing_type_params
463462
.iter()
464463
.map(|n| n.to_string())

tests/ui/associated-types/issue-22560.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ LL | type Test = dyn Add + Sub;
4141
help: set the type parameter to the desired type
4242
|
4343
LL | type Test = dyn Add<Rhs> + Sub;
44-
| ~~~~~~~~
44+
| +++++
4545

4646
error[E0393]: the type parameter `Rhs` must be explicitly specified
4747
--> $DIR/issue-22560.rs:9:23
@@ -56,7 +56,7 @@ LL | type Test = dyn Add + Sub;
5656
help: set the type parameter to the desired type
5757
|
5858
LL | type Test = dyn Add + Sub<Rhs>;
59-
| ~~~~~~~~
59+
| +++++
6060

6161
error: aborting due to 4 previous errors
6262

tests/ui/const-generics/generic_const_exprs/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ LL | ) -> impl Iterator<Item = SubAssign> {
2929
help: set the type parameter to the desired type
3030
|
3131
LL | ) -> impl Iterator<Item = SubAssign<Rhs>> {
32-
| ~~~~~~~~~~~~~~
32+
| +++++
3333

3434
error[E0393]: the type parameter `Rhs` must be explicitly specified
3535
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:27
@@ -45,7 +45,7 @@ LL | ) -> impl Iterator<Item = SubAssign> {
4545
help: set the type parameter to the desired type
4646
|
4747
LL | ) -> impl Iterator<Item = SubAssign<Rhs>> {
48-
| ~~~~~~~~~~~~~~
48+
| +++++
4949

5050
error[E0277]: `()` is not an iterator
5151
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:6

tests/ui/error-codes/E0393.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | fn together_we_will_rule_the_galaxy(son: &dyn A) {}
1111
help: set the type parameter to the desired type
1212
|
1313
LL | fn together_we_will_rule_the_galaxy(son: &dyn A<T>) {}
14-
| ~~~~
14+
| +++
1515

1616
error: aborting due to 1 previous error
1717

tests/ui/issues/issue-21950.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ LL | let x = &10 as &dyn Add;
2020
help: set the type parameter to the desired type
2121
|
2222
LL | let x = &10 as &dyn Add<Rhs>;
23-
| ~~~~~~~~
23+
| +++++
2424

2525
error: aborting due to 2 previous errors
2626

tests/ui/issues/issue-22370.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | fn f(a: &dyn A) {}
1111
help: set the type parameter to the desired type
1212
|
1313
LL | fn f(a: &dyn A<T>) {}
14-
| ~~~~
14+
| +++
1515

1616
error: aborting due to 1 previous error
1717

tests/ui/type/type-parameter-defaults-referencing-Self.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | fn foo(x: &dyn Foo) { }
1111
help: set the type parameter to the desired type
1212
|
1313
LL | fn foo(x: &dyn Foo<T>) { }
14-
| ~~~~~~
14+
| +++
1515

1616
error: aborting due to 1 previous error
1717

0 commit comments

Comments
 (0)