Commit d6823ba
committed
Auto merge of rust-lang#71108 - estebank:suggest-proj-type-mismatch-constraint, r=oli-obk
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>) {
| ^^^^^^^^^^
```
Fix rust-lang#71035. Related to rust-lang#70908.File tree
35 files changed
+859
-136
lines changed- src
- librustc_infer/infer/error_reporting
- librustc_middle
- traits
- ty
- librustc_trait_selection/traits/error_reporting
- librustc_typeck/check
- test/ui
- associated-const
- associated-types
- generic-associated-types
- hrtb
- impl-trait
- issues
- mismatched_types
- specialization
- suggestions
- type-alias-enum-variants
35 files changed
+859
-136
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1388 | 1388 | | |
1389 | 1389 | | |
1390 | 1390 | | |
| 1391 | + | |
1391 | 1392 | | |
1392 | 1393 | | |
1393 | 1394 | | |
| |||
1599 | 1600 | | |
1600 | 1601 | | |
1601 | 1602 | | |
1602 | | - | |
| 1603 | + | |
1603 | 1604 | | |
1604 | 1605 | | |
1605 | 1606 | | |
1606 | | - | |
| 1607 | + | |
1607 | 1608 | | |
1608 | 1609 | | |
1609 | 1610 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
196 | 199 | | |
197 | 200 | | |
198 | 201 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| 167 | + | |
167 | 168 | | |
168 | 169 | | |
169 | 170 | | |
| |||
0 commit comments