Better suggestion span for missing type parameter

This commit is contained in:
Esteban Küber 2024-07-03 21:02:27 +00:00
parent 89ecae5d85
commit f63d2bc657
7 changed files with 43 additions and 12 deletions

View File

@ -453,12 +453,11 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
} else { } else {
// The user wrote `Iterator`, so we don't have a type we can suggest, but at // The user wrote `Iterator`, so we don't have a type we can suggest, but at
// least we can clue them to the correct syntax `Iterator<Type>`. // least we can clue them to the correct syntax `Iterator<Type>`.
err.span_suggestion( err.span_suggestion_verbose(
self.span, self.span.shrink_to_hi(),
fluent::hir_analysis_suggestion, fluent::hir_analysis_suggestion,
format!( format!(
"{}<{}>", "<{}>",
snippet,
self.missing_type_params self.missing_type_params
.iter() .iter()
.map(|n| n.to_string()) .map(|n| n.to_string())

View File

@ -35,9 +35,13 @@ LL | trait Add<Rhs=Self> {
| ------------------- type parameter `Rhs` must be specified for this | ------------------- type parameter `Rhs` must be specified for this
... ...
LL | type Test = dyn Add + Sub; LL | type Test = dyn Add + Sub;
| ^^^ help: set the type parameter to the desired type: `Add<Rhs>` | ^^^
| |
= note: because of the default `Self` reference, type parameters must be specified on object types = note: because of the default `Self` reference, type parameters must be specified on object types
help: set the type parameter to the desired type
|
LL | type Test = dyn Add<Rhs> + Sub;
| +++++
error[E0393]: the type parameter `Rhs` must be explicitly specified error[E0393]: the type parameter `Rhs` must be explicitly specified
--> $DIR/issue-22560.rs:9:23 --> $DIR/issue-22560.rs:9:23
@ -46,9 +50,13 @@ LL | trait Sub<Rhs=Self> {
| ------------------- type parameter `Rhs` must be specified for this | ------------------- type parameter `Rhs` must be specified for this
... ...
LL | type Test = dyn Add + Sub; LL | type Test = dyn Add + Sub;
| ^^^ help: set the type parameter to the desired type: `Sub<Rhs>` | ^^^
| |
= note: because of the default `Self` reference, type parameters must be specified on object types = note: because of the default `Self` reference, type parameters must be specified on object types
help: set the type parameter to the desired type
|
LL | type Test = dyn Add + Sub<Rhs>;
| +++++
error: aborting due to 4 previous errors error: aborting due to 4 previous errors

View File

@ -20,24 +20,32 @@ error[E0393]: the type parameter `Rhs` must be explicitly specified
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:27 --> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:27
| |
LL | ) -> impl Iterator<Item = SubAssign> { LL | ) -> impl Iterator<Item = SubAssign> {
| ^^^^^^^^^ help: set the type parameter to the desired type: `SubAssign<Rhs>` | ^^^^^^^^^
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL --> $SRC_DIR/core/src/ops/arith.rs:LL:COL
| |
= note: type parameter `Rhs` must be specified for this = note: type parameter `Rhs` must be specified for this
| |
= note: because of the default `Self` reference, type parameters must be specified on object types = note: because of the default `Self` reference, type parameters must be specified on object types
help: set the type parameter to the desired type
|
LL | ) -> impl Iterator<Item = SubAssign<Rhs>> {
| +++++
error[E0393]: the type parameter `Rhs` must be explicitly specified error[E0393]: the type parameter `Rhs` must be explicitly specified
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:27 --> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:27
| |
LL | ) -> impl Iterator<Item = SubAssign> { LL | ) -> impl Iterator<Item = SubAssign> {
| ^^^^^^^^^ help: set the type parameter to the desired type: `SubAssign<Rhs>` | ^^^^^^^^^
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL --> $SRC_DIR/core/src/ops/arith.rs:LL:COL
| |
= note: type parameter `Rhs` must be specified for this = note: type parameter `Rhs` must be specified for this
| |
= note: because of the default `Self` reference, type parameters must be specified on object types = note: because of the default `Self` reference, type parameters must be specified on object types
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: set the type parameter to the desired type
|
LL | ) -> impl Iterator<Item = SubAssign<Rhs>> {
| +++++
error[E0277]: `()` is not an iterator error[E0277]: `()` is not an iterator
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:6 --> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:6

View File

@ -5,9 +5,13 @@ LL | trait A<T=Self> {}
| --------------- type parameter `T` must be specified for this | --------------- type parameter `T` must be specified for this
LL | LL |
LL | fn together_we_will_rule_the_galaxy(son: &dyn A) {} LL | fn together_we_will_rule_the_galaxy(son: &dyn A) {}
| ^ help: set the type parameter to the desired type: `A<T>` | ^
| |
= note: because of the default `Self` reference, type parameters must be specified on object types = note: because of the default `Self` reference, type parameters must be specified on object types
help: set the type parameter to the desired type
|
LL | fn together_we_will_rule_the_galaxy(son: &dyn A<T>) {}
| +++
error: aborting due to 1 previous error error: aborting due to 1 previous error

View File

@ -14,9 +14,13 @@ LL | trait Add<Rhs=Self> {
| ------------------- type parameter `Rhs` must be specified for this | ------------------- type parameter `Rhs` must be specified for this
... ...
LL | let x = &10 as &dyn Add; LL | let x = &10 as &dyn Add;
| ^^^ help: set the type parameter to the desired type: `Add<Rhs>` | ^^^
| |
= note: because of the default `Self` reference, type parameters must be specified on object types = note: because of the default `Self` reference, type parameters must be specified on object types
help: set the type parameter to the desired type
|
LL | let x = &10 as &dyn Add<Rhs>;
| +++++
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View File

@ -5,9 +5,13 @@ LL | trait A<T=Self> {}
| --------------- type parameter `T` must be specified for this | --------------- type parameter `T` must be specified for this
LL | LL |
LL | fn f(a: &dyn A) {} LL | fn f(a: &dyn A) {}
| ^ help: set the type parameter to the desired type: `A<T>` | ^
| |
= note: because of the default `Self` reference, type parameters must be specified on object types = note: because of the default `Self` reference, type parameters must be specified on object types
help: set the type parameter to the desired type
|
LL | fn f(a: &dyn A<T>) {}
| +++
error: aborting due to 1 previous error error: aborting due to 1 previous error

View File

@ -5,9 +5,13 @@ LL | trait Foo<T=Self> {
| ----------------- type parameter `T` must be specified for this | ----------------- type parameter `T` must be specified for this
... ...
LL | fn foo(x: &dyn Foo) { } LL | fn foo(x: &dyn Foo) { }
| ^^^ help: set the type parameter to the desired type: `Foo<T>` | ^^^
| |
= note: because of the default `Self` reference, type parameters must be specified on object types = note: because of the default `Self` reference, type parameters must be specified on object types
help: set the type parameter to the desired type
|
LL | fn foo(x: &dyn Foo<T>) { }
| +++
error: aborting due to 1 previous error error: aborting due to 1 previous error