Skip to content

Commit 16b33cc

Browse files
Point to argument if it's self type of unsatisfied projection predicate
1 parent 801821d commit 16b33cc

13 files changed

+125
-65
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1660,12 +1660,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16601660
ObligationCauseCode::ImplDerivedObligation(code) => {
16611661
code.derived.parent_trait_pred.self_ty().skip_binder().into()
16621662
}
1663-
_ if let ty::PredicateKind::Trait(predicate) =
1664-
error.obligation.predicate.kind().skip_binder() =>
1665-
{
1666-
predicate.self_ty().into()
1667-
}
1668-
_ => continue,
1663+
_ => match error.obligation.predicate.kind().skip_binder() {
1664+
ty::PredicateKind::Trait(predicate) => predicate.self_ty().into(),
1665+
ty::PredicateKind::Projection(predicate) => {
1666+
predicate.projection_ty.self_ty().into()
1667+
}
1668+
_ => continue,
1669+
},
16691670
};
16701671
let self_ = self.resolve_vars_if_possible(self_);
16711672
let ty_matches_self = |ty: Ty<'tcx>| ty.walk().any(|arg| arg == self_);

src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error[E0271]: type mismatch resolving `<ModelT as Vehicle>::Color == Blue`
2-
--> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:31:10
2+
--> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:31:19
33
|
44
LL | fn b() { blue_car(ModelT); }
5-
| ^^^^^^^^ type mismatch resolving `<ModelT as Vehicle>::Color == Blue`
5+
| -------- ^^^^^^ type mismatch resolving `<ModelT as Vehicle>::Color == Blue`
6+
| |
7+
| required by a bound introduced by this call
68
|
79
note: expected this to be `Blue`
810
--> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:16:40
@@ -16,10 +18,12 @@ LL | fn blue_car<C:Car<Color=Blue>>(c: C) {
1618
| ^^^^^^^^^^ required by this bound in `blue_car`
1719

1820
error[E0271]: type mismatch resolving `<ModelU as Vehicle>::Color == Black`
19-
--> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:32:10
21+
--> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:32:20
2022
|
2123
LL | fn c() { black_car(ModelU); }
22-
| ^^^^^^^^^ type mismatch resolving `<ModelU as Vehicle>::Color == Black`
24+
| --------- ^^^^^^ type mismatch resolving `<ModelU as Vehicle>::Color == Black`
25+
| |
26+
| required by a bound introduced by this call
2327
|
2428
note: expected this to be `Black`
2529
--> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:21:40

src/test/ui/associated-types/associated-types-eq-3.stderr

+7-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ LL | fn foo2<I: Foo<A = Bar>>(x: I) {
1414
| +++++++++
1515

1616
error[E0271]: type mismatch resolving `<isize as Foo>::A == Bar`
17-
--> $DIR/associated-types-eq-3.rs:38:5
17+
--> $DIR/associated-types-eq-3.rs:38:10
1818
|
1919
LL | foo1(a);
20-
| ^^^^ type mismatch resolving `<isize as Foo>::A == Bar`
20+
| ---- ^ type mismatch resolving `<isize as Foo>::A == Bar`
21+
| |
22+
| required by a bound introduced by this call
2123
|
2224
note: expected this to be `Bar`
2325
--> $DIR/associated-types-eq-3.rs:12:14
@@ -34,7 +36,9 @@ error[E0271]: type mismatch resolving `<isize as Foo>::A == Bar`
3436
--> $DIR/associated-types-eq-3.rs:40:9
3537
|
3638
LL | baz(&a);
37-
| ^^ type mismatch resolving `<isize as Foo>::A == Bar`
39+
| --- ^^ type mismatch resolving `<isize as Foo>::A == Bar`
40+
| |
41+
| required by a bound introduced by this call
3842
|
3943
note: expected this to be `Bar`
4044
--> $DIR/associated-types-eq-3.rs:12:14

src/test/ui/associated-types/associated-types-issue-20346.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
error[E0271]: type mismatch resolving `<Adapter<I> as Iterator>::Item == Option<T>`
2-
--> $DIR/associated-types-issue-20346.rs:34:5
2+
--> $DIR/associated-types-issue-20346.rs:34:36
33
|
44
LL | fn test_adapter<T, I: Iterator<Item=Option<T>>>(it: I) {
55
| - this type parameter
66
...
77
LL | is_iterator_of::<Option<T>, _>(&adapter);
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<Adapter<I> as Iterator>::Item == Option<T>`
8+
| ------------------------------ ^^^^^^^^ type mismatch resolving `<Adapter<I> as Iterator>::Item == Option<T>`
9+
| |
10+
| required by a bound introduced by this call
911
|
1012
note: expected this to be `Option<T>`
1113
--> $DIR/associated-types-issue-20346.rs:23:17

src/test/ui/associated-types/associated-types-multiple-types-one-trait.stderr

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error[E0271]: type mismatch resolving `<T as Foo>::Y == i32`
2-
--> $DIR/associated-types-multiple-types-one-trait.rs:13:5
2+
--> $DIR/associated-types-multiple-types-one-trait.rs:13:12
33
|
44
LL | want_y(t);
5-
| ^^^^^^ expected `i32`, found associated type
5+
| ------ ^ expected `i32`, found associated type
6+
| |
7+
| required by a bound introduced by this call
68
|
79
= note: expected type `i32`
810
found associated type `<T as Foo>::Y`
@@ -17,10 +19,12 @@ LL | fn have_x_want_y<T:Foo<X=u32, Y = i32>>(t: &T)
1719
| +++++++++
1820

1921
error[E0271]: type mismatch resolving `<T as Foo>::X == u32`
20-
--> $DIR/associated-types-multiple-types-one-trait.rs:18:5
22+
--> $DIR/associated-types-multiple-types-one-trait.rs:18:12
2123
|
2224
LL | want_x(t);
23-
| ^^^^^^ expected `u32`, found associated type
25+
| ------ ^ expected `u32`, found associated type
26+
| |
27+
| required by a bound introduced by this call
2428
|
2529
= note: expected type `u32`
2630
found associated type `<T as Foo>::X`

src/test/ui/associated-types/issue-87261.stderr

+56-28
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error[E0271]: type mismatch resolving `<A as Trait>::Associated == ()`
2-
--> $DIR/issue-87261.rs:56:5
2+
--> $DIR/issue-87261.rs:56:19
33
|
44
LL | accepts_trait(a);
5-
| ^^^^^^^^^^^^^ expected `()`, found associated type
5+
| ------------- ^ expected `()`, found associated type
6+
| |
7+
| required by a bound introduced by this call
68
|
79
= note: expected unit type `()`
810
found associated type `<A as Trait>::Associated`
@@ -17,10 +19,12 @@ LL | A: Trait<Associated = ()> + 'static,
1719
| +++++++++++++++++
1820

1921
error[E0271]: type mismatch resolving `<B as Trait>::Associated == ()`
20-
--> $DIR/issue-87261.rs:59:5
22+
--> $DIR/issue-87261.rs:59:19
2123
|
2224
LL | accepts_trait(b);
23-
| ^^^^^^^^^^^^^ expected `()`, found associated type
25+
| ------------- ^ expected `()`, found associated type
26+
| |
27+
| required by a bound introduced by this call
2428
|
2529
= note: expected unit type `()`
2630
found associated type `<B as Trait>::Associated`
@@ -33,10 +37,12 @@ LL | fn accepts_trait<T: Trait<Associated = ()>>(_: T) {}
3337
| ^^^^^^^^^^^^^^^ required by this bound in `accepts_trait`
3438

3539
error[E0271]: type mismatch resolving `<C as Trait>::Associated == ()`
36-
--> $DIR/issue-87261.rs:62:5
40+
--> $DIR/issue-87261.rs:62:19
3741
|
3842
LL | accepts_trait(c);
39-
| ^^^^^^^^^^^^^ expected `()`, found associated type
43+
| ------------- ^ expected `()`, found associated type
44+
| |
45+
| required by a bound introduced by this call
4046
|
4147
= note: expected unit type `()`
4248
found associated type `<C as Trait>::Associated`
@@ -51,10 +57,12 @@ LL | C: Trait<Associated = ()> + Foo,
5157
| +++++++++++++++++
5258

5359
error[E0271]: type mismatch resolving `<D as Trait>::Associated == ()`
54-
--> $DIR/issue-87261.rs:65:5
60+
--> $DIR/issue-87261.rs:65:19
5561
|
5662
LL | accepts_trait(d);
57-
| ^^^^^^^^^^^^^ expected `()`, found associated type
63+
| ------------- ^ expected `()`, found associated type
64+
| |
65+
| required by a bound introduced by this call
5866
|
5967
= note: expected unit type `()`
6068
found associated type `<D as Trait>::Associated`
@@ -67,10 +75,12 @@ LL | fn accepts_trait<T: Trait<Associated = ()>>(_: T) {}
6775
| ^^^^^^^^^^^^^^^ required by this bound in `accepts_trait`
6876

6977
error[E0271]: type mismatch resolving `<E as GenericTrait<()>>::Associated == ()`
70-
--> $DIR/issue-87261.rs:68:5
78+
--> $DIR/issue-87261.rs:68:27
7179
|
7280
LL | accepts_generic_trait(e);
73-
| ^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type
81+
| --------------------- ^ expected `()`, found associated type
82+
| |
83+
| required by a bound introduced by this call
7484
|
7585
= note: expected unit type `()`
7686
found associated type `<E as GenericTrait<()>>::Associated`
@@ -85,10 +95,12 @@ LL | E: GenericTrait<(), Associated = ()> + 'static,
8595
| +++++++++++++++++
8696

8797
error[E0271]: type mismatch resolving `<F as GenericTrait<()>>::Associated == ()`
88-
--> $DIR/issue-87261.rs:71:5
98+
--> $DIR/issue-87261.rs:71:27
8999
|
90100
LL | accepts_generic_trait(f);
91-
| ^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type
101+
| --------------------- ^ expected `()`, found associated type
102+
| |
103+
| required by a bound introduced by this call
92104
|
93105
= note: expected unit type `()`
94106
found associated type `<F as GenericTrait<()>>::Associated`
@@ -103,10 +115,12 @@ LL | F: GenericTrait<(), Associated = ()> + Foo,
103115
| +++++++++++++++++
104116

105117
error[E0271]: type mismatch resolving `<G as GenericTrait<()>>::Associated == ()`
106-
--> $DIR/issue-87261.rs:74:5
118+
--> $DIR/issue-87261.rs:74:27
107119
|
108120
LL | accepts_generic_trait(g);
109-
| ^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type
121+
| --------------------- ^ expected `()`, found associated type
122+
| |
123+
| required by a bound introduced by this call
110124
|
111125
= note: expected unit type `()`
112126
found associated type `<G as GenericTrait<()>>::Associated`
@@ -119,13 +133,15 @@ LL | fn accepts_generic_trait<T: GenericTrait<(), Associated = ()>>(_: T) {}
119133
| ^^^^^^^^^^^^^^^ required by this bound in `accepts_generic_trait`
120134

121135
error[E0271]: type mismatch resolving `<impl Trait as Trait>::Associated == ()`
122-
--> $DIR/issue-87261.rs:79:5
136+
--> $DIR/issue-87261.rs:79:19
123137
|
124138
LL | fn returns_opaque() -> impl Trait + 'static {
125139
| -------------------- the found opaque type
126140
...
127141
LL | accepts_trait(returns_opaque());
128-
| ^^^^^^^^^^^^^ expected `()`, found associated type
142+
| ------------- ^^^^^^^^^^^^^^^^ expected `()`, found associated type
143+
| |
144+
| required by a bound introduced by this call
129145
|
130146
= note: expected unit type `()`
131147
found associated type `<impl Trait as Trait>::Associated`
@@ -140,13 +156,15 @@ LL | fn returns_opaque() -> impl Trait<Associated = ()> + 'static {
140156
| +++++++++++++++++
141157

142158
error[E0271]: type mismatch resolving `<impl DerivedTrait as Trait>::Associated == ()`
143-
--> $DIR/issue-87261.rs:82:5
159+
--> $DIR/issue-87261.rs:82:19
144160
|
145161
LL | fn returns_opaque_derived() -> impl DerivedTrait + 'static {
146162
| --------------------------- the found opaque type
147163
...
148164
LL | accepts_trait(returns_opaque_derived());
149-
| ^^^^^^^^^^^^^ expected `()`, found associated type
165+
| ------------- ^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type
166+
| |
167+
| required by a bound introduced by this call
150168
|
151169
= note: expected unit type `()`
152170
found associated type `<impl DerivedTrait as Trait>::Associated`
@@ -161,13 +179,15 @@ LL | fn returns_opaque_derived() -> impl DerivedTrait<Associated = ()> + 'static
161179
| +++++++++++++++++
162180

163181
error[E0271]: type mismatch resolving `<impl Trait + Foo as Trait>::Associated == ()`
164-
--> $DIR/issue-87261.rs:85:5
182+
--> $DIR/issue-87261.rs:85:19
165183
|
166184
LL | fn returns_opaque_foo() -> impl Trait + Foo {
167185
| ---------------- the found opaque type
168186
...
169187
LL | accepts_trait(returns_opaque_foo());
170-
| ^^^^^^^^^^^^^ expected `()`, found associated type
188+
| ------------- ^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type
189+
| |
190+
| required by a bound introduced by this call
171191
|
172192
= note: expected unit type `()`
173193
found associated type `<impl Trait + Foo as Trait>::Associated`
@@ -182,13 +202,15 @@ LL | fn returns_opaque_foo() -> impl Trait<Associated = ()> + Foo {
182202
| +++++++++++++++++
183203

184204
error[E0271]: type mismatch resolving `<impl DerivedTrait + Foo as Trait>::Associated == ()`
185-
--> $DIR/issue-87261.rs:88:5
205+
--> $DIR/issue-87261.rs:88:19
186206
|
187207
LL | fn returns_opaque_derived_foo() -> impl DerivedTrait + Foo {
188208
| ----------------------- the found opaque type
189209
...
190210
LL | accepts_trait(returns_opaque_derived_foo());
191-
| ^^^^^^^^^^^^^ expected `()`, found associated type
211+
| ------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type
212+
| |
213+
| required by a bound introduced by this call
192214
|
193215
= note: expected unit type `()`
194216
found associated type `<impl DerivedTrait + Foo as Trait>::Associated`
@@ -201,13 +223,15 @@ LL | fn accepts_trait<T: Trait<Associated = ()>>(_: T) {}
201223
| ^^^^^^^^^^^^^^^ required by this bound in `accepts_trait`
202224

203225
error[E0271]: type mismatch resolving `<impl GenericTrait<()> as GenericTrait<()>>::Associated == ()`
204-
--> $DIR/issue-87261.rs:91:5
226+
--> $DIR/issue-87261.rs:91:27
205227
|
206228
LL | fn returns_opaque_generic() -> impl GenericTrait<()> + 'static {
207229
| ------------------------------- the found opaque type
208230
...
209231
LL | accepts_generic_trait(returns_opaque_generic());
210-
| ^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type
232+
| --------------------- ^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type
233+
| |
234+
| required by a bound introduced by this call
211235
|
212236
= note: expected unit type `()`
213237
found associated type `<impl GenericTrait<()> as GenericTrait<()>>::Associated`
@@ -222,13 +246,15 @@ LL | fn returns_opaque_generic() -> impl GenericTrait<(), Associated = ()> + 'st
222246
| +++++++++++++++++
223247

224248
error[E0271]: type mismatch resolving `<impl GenericTrait<()> + Foo as GenericTrait<()>>::Associated == ()`
225-
--> $DIR/issue-87261.rs:94:5
249+
--> $DIR/issue-87261.rs:94:27
226250
|
227251
LL | fn returns_opaque_generic_foo() -> impl GenericTrait<()> + Foo {
228252
| --------------------------- the found opaque type
229253
...
230254
LL | accepts_generic_trait(returns_opaque_generic_foo());
231-
| ^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type
255+
| --------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type
256+
| |
257+
| required by a bound introduced by this call
232258
|
233259
= note: expected unit type `()`
234260
found associated type `<impl GenericTrait<()> + Foo as GenericTrait<()>>::Associated`
@@ -243,13 +269,15 @@ LL | fn returns_opaque_generic_foo() -> impl GenericTrait<(), Associated = ()> +
243269
| +++++++++++++++++
244270

245271
error[E0271]: type mismatch resolving `<impl GenericTrait<()> + GenericTrait<u8> as GenericTrait<()>>::Associated == ()`
246-
--> $DIR/issue-87261.rs:97:5
272+
--> $DIR/issue-87261.rs:97:27
247273
|
248274
LL | fn returns_opaque_generic_duplicate() -> impl GenericTrait<()> + GenericTrait<u8> {
249275
| ---------------------------------------- the found opaque type
250276
...
251277
LL | accepts_generic_trait(returns_opaque_generic_duplicate());
252-
| ^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type
278+
| --------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type
279+
| |
280+
| required by a bound introduced by this call
253281
|
254282
= note: expected unit type `()`
255283
found associated type `<impl GenericTrait<()> + GenericTrait<u8> as GenericTrait<()>>::Associated`

src/test/ui/error-codes/E0271.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error[E0271]: type mismatch resolving `<i8 as Trait>::AssociatedType == u32`
2-
--> $DIR/E0271.rs:10:5
2+
--> $DIR/E0271.rs:10:9
33
|
44
LL | foo(3_i8);
5-
| ^^^ type mismatch resolving `<i8 as Trait>::AssociatedType == u32`
5+
| --- ^^^^ type mismatch resolving `<i8 as Trait>::AssociatedType == u32`
6+
| |
7+
| required by a bound introduced by this call
68
|
79
note: expected this to be `u32`
810
--> $DIR/E0271.rs:7:43

src/test/ui/generic-associated-types/issue-74684-2.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error[E0271]: type mismatch resolving `<{integer} as Fun>::F<'_> == [u8]`
2-
--> $DIR/issue-74684-2.rs:23:5
2+
--> $DIR/issue-74684-2.rs:23:9
33
|
44
LL | bug(Box::new(x));
5-
| ^^^ type mismatch resolving `<{integer} as Fun>::F<'_> == [u8]`
5+
| --- ^^^^^^^^^^^ type mismatch resolving `<{integer} as Fun>::F<'_> == [u8]`
6+
| |
7+
| required by a bound introduced by this call
68
|
79
note: expected this to be `[u8]`
810
--> $DIR/issue-74684-2.rs:10:18

src/test/ui/higher-rank-trait-bounds/issue-62203-hrtb-ice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ trait Ty<'a> {
3636

3737
fn main() {
3838
let v = Unit2.m(
39-
//~^ ERROR type mismatch
4039
L {
4140
//~^ ERROR to be a closure that returns `Unit3`, but it returns `Unit4`
41+
//~| ERROR type mismatch
4242
f: |x| {
4343
drop(x);
4444
Unit4

0 commit comments

Comments
 (0)