You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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>) {
| ^^^^^^^^^^
```
Copy file name to clipboardExpand all lines: src/test/ui/generic-associated-types/iterable.stderr
+2-2
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ LL | type Item;
13
13
|
14
14
= note: expected reference `&T`
15
15
found associated type `<std::vec::Vec<T> as Iterable>::Item<'_>`
16
-
= note: consider constraining the associated type `<std::vec::Vec<T> as Iterable>::Item<'_>` to `&_`
16
+
= help: consider constraining the associated type `<std::vec::Vec<T> as Iterable>::Item<'_>` to `&_`
17
17
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
18
18
19
19
error[E0271]: type mismatch resolving `for<'a> <<[T] as Iterable>::Iter<'a> as std::iter::Iterator>::Item == <[T] as Iterable>::Item<'a>`
@@ -31,7 +31,7 @@ LL | type Item;
31
31
|
32
32
= note: expected reference `&T`
33
33
found associated type `<[T] as Iterable>::Item<'_>`
34
-
= note: consider constraining the associated type `<[T] as Iterable>::Item<'_>` to `&_`
34
+
= help: consider constraining the associated type `<[T] as Iterable>::Item<'_>` to `&_`
35
35
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
36
36
37
37
error[E0271]: type mismatch resolving `for<'a> <<std::vec::Vec<T> as Iterable>::Iter<'a> as std::iter::Iterator>::Item == <std::vec::Vec<T> as Iterable>::Item<'a>`
0 commit comments