Better suggestion span for missing type parameter
This commit is contained in:
parent
89ecae5d85
commit
f63d2bc657
@ -453,12 +453,11 @@ fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
|
||||
} else {
|
||||
// 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>`.
|
||||
err.span_suggestion(
|
||||
self.span,
|
||||
err.span_suggestion_verbose(
|
||||
self.span.shrink_to_hi(),
|
||||
fluent::hir_analysis_suggestion,
|
||||
format!(
|
||||
"{}<{}>",
|
||||
snippet,
|
||||
"<{}>",
|
||||
self.missing_type_params
|
||||
.iter()
|
||||
.map(|n| n.to_string())
|
||||
|
@ -35,9 +35,13 @@ LL | trait Add<Rhs=Self> {
|
||||
| ------------------- type parameter `Rhs` must be specified for this
|
||||
...
|
||||
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
|
||||
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
|
||||
--> $DIR/issue-22560.rs:9:23
|
||||
@ -46,9 +50,13 @@ LL | trait Sub<Rhs=Self> {
|
||||
| ------------------- type parameter `Rhs` must be specified for this
|
||||
...
|
||||
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
|
||||
help: set the type parameter to the desired type
|
||||
|
|
||||
LL | type Test = dyn Add + Sub<Rhs>;
|
||||
| +++++
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
@ -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
|
||||
|
|
||||
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
|
||||
|
|
||||
= note: type parameter `Rhs` must be specified for this
|
||||
|
|
||||
= 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
|
||||
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:27
|
||||
|
|
||||
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
|
||||
|
|
||||
= 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: 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
|
||||
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:6
|
||||
|
@ -5,9 +5,13 @@ LL | trait A<T=Self> {}
|
||||
| --------------- type parameter `T` must be specified for this
|
||||
LL |
|
||||
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
|
||||
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
|
||||
|
||||
|
@ -14,9 +14,13 @@ LL | trait Add<Rhs=Self> {
|
||||
| ------------------- type parameter `Rhs` must be specified for this
|
||||
...
|
||||
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
|
||||
help: set the type parameter to the desired type
|
||||
|
|
||||
LL | let x = &10 as &dyn Add<Rhs>;
|
||||
| +++++
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
@ -5,9 +5,13 @@ LL | trait A<T=Self> {}
|
||||
| --------------- type parameter `T` must be specified for this
|
||||
LL |
|
||||
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
|
||||
help: set the type parameter to the desired type
|
||||
|
|
||||
LL | fn f(a: &dyn A<T>) {}
|
||||
| +++
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
@ -5,9 +5,13 @@ LL | trait Foo<T=Self> {
|
||||
| ----------------- type parameter `T` must be specified for this
|
||||
...
|
||||
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
|
||||
help: set the type parameter to the desired type
|
||||
|
|
||||
LL | fn foo(x: &dyn Foo<T>) { }
|
||||
| +++
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user