On type mismatch involving associated type, suggest constraint
When an associated type is found when a specific type was expected, if
possible provide a structured suggestion constraining the associated
type in a bound.
```
error[E0271]: type mismatch resolving `<T as Foo>::Y == i32`
--> $DIR/associated-types-multiple-types-one-trait.rs:13:5
|
LL | want_y(t);
| ^^^^^^ expected `i32`, found associated type
...
LL | fn want_y<T:Foo<Y=i32>>(t: &T) { }
| ----- required by this bound in `want_y`
|
= note: expected type `i32`
found associated type `<T as Foo>::Y`
help: consider constraining the associated type `<T as Foo>::Y` to `i32`
|
LL | fn have_x_want_y<T:Foo<X=u32, Y = i32>>(t: &T)
| ^^^^^^^^^
```
```
error[E0308]: mismatched types
--> $DIR/trait-with-missing-associated-type-restriction.rs:12:9
|
LL | qux(x.func())
| ^^^^^^^^ expected `usize`, found associated type
|
= note: expected type `usize`
found associated type `<impl Trait as Trait>::A`
help: consider constraining the associated type `<impl Trait as Trait>::A` to `usize`
|
LL | fn foo(x: impl Trait<A = usize>) {
| ^^^^^^^^^^
```
This commit is contained in:
parent
f05a524044
commit
3a795fba03
22 changed files with 469 additions and 66 deletions
|
|
@ -9,8 +9,6 @@ LL | self.iter()
|
|||
|
|
||||
= note: expected type parameter `I`
|
||||
found struct `std::slice::Iter<'_, N>`
|
||||
= help: type parameters must be constrained to match other types
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
|
||||
|
||||
error[E0599]: no method named `iter` found for reference `&G` in the current scope
|
||||
--> $DIR/issue-13853.rs:27:23
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@ LL | extern "rust-call" fn call(&self, (_,): (T,)) {}
|
|||
|
|
||||
= note: expected fn pointer `extern "rust-call" fn(&Foo, (&'a T,))`
|
||||
found fn pointer `extern "rust-call" fn(&Foo, (T,))`
|
||||
= help: type parameters must be constrained to match other types
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
|
||||
|
||||
error[E0053]: method `call_mut` has an incompatible type for trait
|
||||
--> $DIR/issue-20225.rs:11:3
|
||||
|
|
@ -21,8 +19,6 @@ LL | extern "rust-call" fn call_mut(&mut self, (_,): (T,)) {}
|
|||
|
|
||||
= note: expected fn pointer `extern "rust-call" fn(&mut Foo, (&'a T,))`
|
||||
found fn pointer `extern "rust-call" fn(&mut Foo, (T,))`
|
||||
= help: type parameters must be constrained to match other types
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
|
||||
|
||||
error[E0053]: method `call_once` has an incompatible type for trait
|
||||
--> $DIR/issue-20225.rs:18:3
|
||||
|
|
@ -35,8 +31,6 @@ LL | extern "rust-call" fn call_once(self, (_,): (T,)) {}
|
|||
|
|
||||
= note: expected fn pointer `extern "rust-call" fn(Foo, (&'a T,))`
|
||||
found fn pointer `extern "rust-call" fn(Foo, (T,))`
|
||||
= help: type parameters must be constrained to match other types
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@ LL | const C: S0<u8> = Self(0);
|
|||
|
|
||||
= note: expected type parameter `T`
|
||||
found type `{integer}`
|
||||
= help: type parameters must be constrained to match other types
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-69306.rs:5:23
|
||||
|
|
@ -21,8 +19,6 @@ LL | const C: S0<u8> = Self(0);
|
|||
|
|
||||
= note: expected struct `S0<u8>`
|
||||
found struct `S0<T>`
|
||||
= help: type parameters must be constrained to match other types
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-69306.rs:10:14
|
||||
|
|
@ -35,8 +31,6 @@ LL | Self(0);
|
|||
|
|
||||
= note: expected type parameter `T`
|
||||
found type `{integer}`
|
||||
= help: type parameters must be constrained to match other types
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-69306.rs:27:14
|
||||
|
|
@ -49,8 +43,6 @@ LL | Self(0);
|
|||
|
|
||||
= note: expected type parameter `T`
|
||||
found type `{integer}`
|
||||
= help: type parameters must be constrained to match other types
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-69306.rs:33:32
|
||||
|
|
@ -62,8 +54,6 @@ LL | const C: S1<u8, u8> = Self(0, 1);
|
|||
|
|
||||
= note: expected type parameter `T`
|
||||
found type `{integer}`
|
||||
= help: type parameters must be constrained to match other types
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-69306.rs:33:27
|
||||
|
|
@ -75,8 +65,6 @@ LL | const C: S1<u8, u8> = Self(0, 1);
|
|||
|
|
||||
= note: expected struct `S1<u8, _>`
|
||||
found struct `S1<T, _>`
|
||||
= help: type parameters must be constrained to match other types
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-69306.rs:41:14
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue