Skip to content

Commit dbdc03c

Browse files
author
Lukas Markeffsky
committed
add tests for mismatched super projections with nested obligations
1 parent 06a72d2 commit dbdc03c

File tree

2 files changed

+259
-39
lines changed

2 files changed

+259
-39
lines changed

tests/ui/trait-bounds/super-assoc-mismatch.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ impl Super for () {
66
}
77
trait Sub: Super<Assoc = u16> {}
88

9+
// direct impls (no nested obligations):
10+
911
trait BoundOnSelf: Sub {}
1012
impl BoundOnSelf for () {}
1113
//~^ ERROR the trait bound `(): Sub` is not satisfied
@@ -25,14 +27,46 @@ impl BoundOnAssoc for () {
2527
trait BoundOnGat where Self::Assoc<u8>: Sub {
2628
type Assoc<T>;
2729
}
28-
impl BoundOnGat for u8 {
30+
impl BoundOnGat for () {
2931
type Assoc<T> = ();
3032
//~^ ERROR the trait bound `(): Sub` is not satisfied
3133
}
3234

3335
fn trivial_bound() where (): Sub {}
3436
//~^ ERROR the trait bound `(): Sub` is not satisfied
3537

38+
// blanket impls with nested obligations:
39+
40+
struct Wrapper<T>(T);
41+
impl<T: Super> Super for Wrapper<T> {
42+
type Assoc = T::Assoc;
43+
}
44+
impl<T: Sub> Sub for Wrapper<T> {}
45+
46+
impl BoundOnSelf for Wrapper<()> {}
47+
//~^ ERROR the trait bound `(): Sub` is not satisfied
48+
//~| ERROR type mismatch resolving `<Wrapper<()> as Super>::Assoc == u16
49+
50+
impl BoundOnParam<Wrapper<()>> for Wrapper<()> {}
51+
//~^ ERROR the trait bound `(): Sub` is not satisfied
52+
//~| ERROR type mismatch resolving `<Wrapper<()> as Super>::Assoc == u16
53+
54+
impl BoundOnAssoc for Wrapper<()> {
55+
type Assoc = Wrapper<()>;
56+
//~^ ERROR the trait bound `(): Sub` is not satisfied
57+
//~| ERROR type mismatch resolving `<Wrapper<()> as Super>::Assoc == u16
58+
}
59+
60+
impl BoundOnGat for Wrapper<()> {
61+
type Assoc<T> = Wrapper<()>;
62+
//~^ ERROR the trait bound `(): Sub` is not satisfied
63+
//~| ERROR type mismatch resolving `<Wrapper<()> as Super>::Assoc == u16
64+
}
65+
66+
fn trivial_bound_wrapper() where Wrapper<()>: Sub {}
67+
//~^ ERROR the trait bound `(): Sub` is not satisfied
68+
//~| ERROR type mismatch resolving `<Wrapper<()> as Super>::Assoc == u16
69+
3670
// The following is an edge case where the unsatisfied projection predicate
3771
// `<<u8 as MultiAssoc>::Assoc1<()> as SuperGeneric<u16>>::Assoc == <u8 as MultiAssoc>::Assoc2`
3872
// contains both associated types of `MultiAssoc`. To suppress the error about the unsatisfied
Lines changed: 224 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,294 @@
11
error[E0277]: the trait bound `(): Sub` is not satisfied
2-
--> $DIR/super-assoc-mismatch.rs:10:22
2+
--> $DIR/super-assoc-mismatch.rs:12:22
33
|
44
LL | impl BoundOnSelf for () {}
55
| ^^ the trait `Sub` is not implemented for `()`
66
|
7-
help: this trait has no implementations, consider adding one
8-
--> $DIR/super-assoc-mismatch.rs:7:1
9-
|
10-
LL | trait Sub: Super<Assoc = u16> {}
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7+
= help: the trait `Sub` is implemented for `Wrapper<T>`
128
note: required by a bound in `BoundOnSelf`
13-
--> $DIR/super-assoc-mismatch.rs:9:20
9+
--> $DIR/super-assoc-mismatch.rs:11:20
1410
|
1511
LL | trait BoundOnSelf: Sub {}
1612
| ^^^ required by this bound in `BoundOnSelf`
1713

1814
error[E0277]: the trait bound `(): Sub` is not satisfied
19-
--> $DIR/super-assoc-mismatch.rs:14:27
15+
--> $DIR/super-assoc-mismatch.rs:16:27
2016
|
2117
LL | impl BoundOnParam<()> for () {}
2218
| ^^ the trait `Sub` is not implemented for `()`
2319
|
24-
help: this trait has no implementations, consider adding one
25-
--> $DIR/super-assoc-mismatch.rs:7:1
26-
|
27-
LL | trait Sub: Super<Assoc = u16> {}
28-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
= help: the trait `Sub` is implemented for `Wrapper<T>`
2921
note: required by a bound in `BoundOnParam`
30-
--> $DIR/super-assoc-mismatch.rs:13:23
22+
--> $DIR/super-assoc-mismatch.rs:15:23
3123
|
3224
LL | trait BoundOnParam<T: Sub> {}
3325
| ^^^ required by this bound in `BoundOnParam`
3426

3527
error[E0277]: the trait bound `(): Sub` is not satisfied
36-
--> $DIR/super-assoc-mismatch.rs:21:18
28+
--> $DIR/super-assoc-mismatch.rs:23:18
3729
|
3830
LL | type Assoc = ();
3931
| ^^ the trait `Sub` is not implemented for `()`
4032
|
41-
help: this trait has no implementations, consider adding one
42-
--> $DIR/super-assoc-mismatch.rs:7:1
43-
|
44-
LL | trait Sub: Super<Assoc = u16> {}
45-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33+
= help: the trait `Sub` is implemented for `Wrapper<T>`
4634
note: required by a bound in `BoundOnAssoc::Assoc`
47-
--> $DIR/super-assoc-mismatch.rs:18:17
35+
--> $DIR/super-assoc-mismatch.rs:20:17
4836
|
4937
LL | type Assoc: Sub;
5038
| ^^^ required by this bound in `BoundOnAssoc::Assoc`
5139

5240
error[E0277]: the trait bound `(): Sub` is not satisfied
53-
--> $DIR/super-assoc-mismatch.rs:29:21
41+
--> $DIR/super-assoc-mismatch.rs:31:21
5442
|
5543
LL | type Assoc<T> = ();
56-
| ^^ the trait `Sub` is not implemented for `()`, which is required by `<u8 as BoundOnGat>::Assoc<u8>: Sub`
57-
|
58-
help: this trait has no implementations, consider adding one
59-
--> $DIR/super-assoc-mismatch.rs:7:1
44+
| ^^ the trait `Sub` is not implemented for `()`, which is required by `<() as BoundOnGat>::Assoc<u8>: Sub`
6045
|
61-
LL | trait Sub: Super<Assoc = u16> {}
62-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
46+
= help: the trait `Sub` is implemented for `Wrapper<T>`
6347
note: required by a bound in `BoundOnGat`
64-
--> $DIR/super-assoc-mismatch.rs:25:41
48+
--> $DIR/super-assoc-mismatch.rs:27:41
6549
|
6650
LL | trait BoundOnGat where Self::Assoc<u8>: Sub {
6751
| ^^^ required by this bound in `BoundOnGat`
6852

6953
error[E0277]: the trait bound `(): Sub` is not satisfied
70-
--> $DIR/super-assoc-mismatch.rs:33:26
54+
--> $DIR/super-assoc-mismatch.rs:35:26
7155
|
7256
LL | fn trivial_bound() where (): Sub {}
7357
| ^^^^^^^ the trait `Sub` is not implemented for `()`
7458
|
75-
help: this trait has no implementations, consider adding one
76-
--> $DIR/super-assoc-mismatch.rs:7:1
59+
= help: the trait `Sub` is implemented for `Wrapper<T>`
60+
= help: see issue #48214
61+
help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
62+
|
63+
LL + #![feature(trivial_bounds)]
64+
|
65+
66+
error[E0271]: type mismatch resolving `<Wrapper<()> as Super>::Assoc == u16`
67+
--> $DIR/super-assoc-mismatch.rs:46:22
68+
|
69+
LL | impl BoundOnSelf for Wrapper<()> {}
70+
| ^^^^^^^^^^^ type mismatch resolving `<Wrapper<()> as Super>::Assoc == u16`
71+
|
72+
note: expected this to be `u16`
73+
--> $DIR/super-assoc-mismatch.rs:42:18
74+
|
75+
LL | type Assoc = T::Assoc;
76+
| ^^^^^^^^
77+
note: required for `Wrapper<()>` to implement `Sub`
78+
--> $DIR/super-assoc-mismatch.rs:7:7
79+
|
80+
LL | trait Sub: Super<Assoc = u16> {}
81+
| ^^^
82+
note: required by a bound in `BoundOnSelf`
83+
--> $DIR/super-assoc-mismatch.rs:11:20
84+
|
85+
LL | trait BoundOnSelf: Sub {}
86+
| ^^^ required by this bound in `BoundOnSelf`
87+
88+
error[E0277]: the trait bound `(): Sub` is not satisfied
89+
--> $DIR/super-assoc-mismatch.rs:46:22
90+
|
91+
LL | impl BoundOnSelf for Wrapper<()> {}
92+
| ^^^^^^^^^^^ the trait `Sub` is not implemented for `()`, which is required by `Wrapper<()>: Sub`
93+
|
94+
= help: the trait `Sub` is implemented for `Wrapper<T>`
95+
note: required for `Wrapper<()>` to implement `Sub`
96+
--> $DIR/super-assoc-mismatch.rs:44:14
97+
|
98+
LL | impl<T: Sub> Sub for Wrapper<T> {}
99+
| --- ^^^ ^^^^^^^^^^
100+
| |
101+
| unsatisfied trait bound introduced here
102+
note: required by a bound in `BoundOnSelf`
103+
--> $DIR/super-assoc-mismatch.rs:11:20
104+
|
105+
LL | trait BoundOnSelf: Sub {}
106+
| ^^^ required by this bound in `BoundOnSelf`
107+
108+
error[E0271]: type mismatch resolving `<Wrapper<()> as Super>::Assoc == u16`
109+
--> $DIR/super-assoc-mismatch.rs:50:36
110+
|
111+
LL | impl BoundOnParam<Wrapper<()>> for Wrapper<()> {}
112+
| ^^^^^^^^^^^ type mismatch resolving `<Wrapper<()> as Super>::Assoc == u16`
113+
|
114+
note: expected this to be `u16`
115+
--> $DIR/super-assoc-mismatch.rs:42:18
116+
|
117+
LL | type Assoc = T::Assoc;
118+
| ^^^^^^^^
119+
note: required for `Wrapper<()>` to implement `Sub`
120+
--> $DIR/super-assoc-mismatch.rs:7:7
121+
|
122+
LL | trait Sub: Super<Assoc = u16> {}
123+
| ^^^
124+
note: required by a bound in `BoundOnParam`
125+
--> $DIR/super-assoc-mismatch.rs:15:23
126+
|
127+
LL | trait BoundOnParam<T: Sub> {}
128+
| ^^^ required by this bound in `BoundOnParam`
129+
130+
error[E0277]: the trait bound `(): Sub` is not satisfied
131+
--> $DIR/super-assoc-mismatch.rs:50:36
132+
|
133+
LL | impl BoundOnParam<Wrapper<()>> for Wrapper<()> {}
134+
| ^^^^^^^^^^^ the trait `Sub` is not implemented for `()`, which is required by `Wrapper<()>: Sub`
135+
|
136+
= help: the trait `Sub` is implemented for `Wrapper<T>`
137+
note: required for `Wrapper<()>` to implement `Sub`
138+
--> $DIR/super-assoc-mismatch.rs:44:14
139+
|
140+
LL | impl<T: Sub> Sub for Wrapper<T> {}
141+
| --- ^^^ ^^^^^^^^^^
142+
| |
143+
| unsatisfied trait bound introduced here
144+
note: required by a bound in `BoundOnParam`
145+
--> $DIR/super-assoc-mismatch.rs:15:23
146+
|
147+
LL | trait BoundOnParam<T: Sub> {}
148+
| ^^^ required by this bound in `BoundOnParam`
149+
150+
error[E0271]: type mismatch resolving `<Wrapper<()> as Super>::Assoc == u16`
151+
--> $DIR/super-assoc-mismatch.rs:55:18
152+
|
153+
LL | type Assoc = Wrapper<()>;
154+
| ^^^^^^^^^^^ type mismatch resolving `<Wrapper<()> as Super>::Assoc == u16`
155+
|
156+
note: expected this to be `u16`
157+
--> $DIR/super-assoc-mismatch.rs:42:18
158+
|
159+
LL | type Assoc = T::Assoc;
160+
| ^^^^^^^^
161+
note: required for `<Wrapper<()> as BoundOnAssoc>::Assoc` to implement `Sub`
162+
--> $DIR/super-assoc-mismatch.rs:7:7
77163
|
78164
LL | trait Sub: Super<Assoc = u16> {}
79-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
165+
| ^^^
166+
note: required by a bound in `BoundOnAssoc::Assoc`
167+
--> $DIR/super-assoc-mismatch.rs:20:17
168+
|
169+
LL | type Assoc: Sub;
170+
| ^^^ required by this bound in `BoundOnAssoc::Assoc`
171+
172+
error[E0277]: the trait bound `(): Sub` is not satisfied
173+
--> $DIR/super-assoc-mismatch.rs:55:18
174+
|
175+
LL | type Assoc = Wrapper<()>;
176+
| ^^^^^^^^^^^ the trait `Sub` is not implemented for `()`, which is required by `Wrapper<()>: Sub`
177+
|
178+
= help: the trait `Sub` is implemented for `Wrapper<T>`
179+
note: required for `Wrapper<()>` to implement `Sub`
180+
--> $DIR/super-assoc-mismatch.rs:44:14
181+
|
182+
LL | impl<T: Sub> Sub for Wrapper<T> {}
183+
| --- ^^^ ^^^^^^^^^^
184+
| |
185+
| unsatisfied trait bound introduced here
186+
note: required by a bound in `BoundOnAssoc::Assoc`
187+
--> $DIR/super-assoc-mismatch.rs:20:17
188+
|
189+
LL | type Assoc: Sub;
190+
| ^^^ required by this bound in `BoundOnAssoc::Assoc`
191+
192+
error[E0271]: type mismatch resolving `<Wrapper<()> as Super>::Assoc == u16`
193+
--> $DIR/super-assoc-mismatch.rs:61:21
194+
|
195+
LL | type Assoc<T> = Wrapper<()>;
196+
| ^^^^^^^^^^^ type mismatch resolving `<Wrapper<()> as Super>::Assoc == u16`
197+
|
198+
note: expected this to be `u16`
199+
--> $DIR/super-assoc-mismatch.rs:42:18
200+
|
201+
LL | type Assoc = T::Assoc;
202+
| ^^^^^^^^
203+
note: required for `<Wrapper<()> as BoundOnGat>::Assoc<u8>` to implement `Sub`
204+
--> $DIR/super-assoc-mismatch.rs:7:7
205+
|
206+
LL | trait Sub: Super<Assoc = u16> {}
207+
| ^^^
208+
note: required by a bound in `BoundOnGat`
209+
--> $DIR/super-assoc-mismatch.rs:27:41
210+
|
211+
LL | trait BoundOnGat where Self::Assoc<u8>: Sub {
212+
| ^^^ required by this bound in `BoundOnGat`
213+
214+
error[E0277]: the trait bound `(): Sub` is not satisfied
215+
--> $DIR/super-assoc-mismatch.rs:61:21
216+
|
217+
LL | type Assoc<T> = Wrapper<()>;
218+
| ^^^^^^^^^^^ the trait `Sub` is not implemented for `()`, which is required by `<Wrapper<()> as BoundOnGat>::Assoc<u8>: Sub`
219+
|
220+
= help: the trait `Sub` is implemented for `Wrapper<T>`
221+
note: required for `Wrapper<()>` to implement `Sub`
222+
--> $DIR/super-assoc-mismatch.rs:44:14
223+
|
224+
LL | impl<T: Sub> Sub for Wrapper<T> {}
225+
| --- ^^^ ^^^^^^^^^^
226+
| |
227+
| unsatisfied trait bound introduced here
228+
note: required by a bound in `BoundOnGat`
229+
--> $DIR/super-assoc-mismatch.rs:27:41
230+
|
231+
LL | trait BoundOnGat where Self::Assoc<u8>: Sub {
232+
| ^^^ required by this bound in `BoundOnGat`
233+
234+
error[E0271]: type mismatch resolving `<Wrapper<()> as Super>::Assoc == u16`
235+
--> $DIR/super-assoc-mismatch.rs:66:34
236+
|
237+
LL | fn trivial_bound_wrapper() where Wrapper<()>: Sub {}
238+
| ^^^^^^^^^^^^^^^^ type mismatch resolving `<Wrapper<()> as Super>::Assoc == u16`
239+
|
240+
note: expected this to be `u8`
241+
--> $DIR/super-assoc-mismatch.rs:42:18
242+
|
243+
LL | type Assoc = T::Assoc;
244+
| ^^^^^^^^
245+
= help: see issue #48214
246+
help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
247+
|
248+
LL + #![feature(trivial_bounds)]
249+
|
250+
251+
error[E0277]: the trait bound `(): Sub` is not satisfied
252+
--> $DIR/super-assoc-mismatch.rs:66:34
253+
|
254+
LL | fn trivial_bound_wrapper() where Wrapper<()>: Sub {}
255+
| ^^^^^^^^^^^^^^^^ the trait `Sub` is not implemented for `()`, which is required by `Wrapper<()>: Sub`
256+
|
257+
= help: the trait `Sub` is implemented for `Wrapper<T>`
258+
note: required for `Wrapper<()>` to implement `Sub`
259+
--> $DIR/super-assoc-mismatch.rs:44:14
260+
|
261+
LL | impl<T: Sub> Sub for Wrapper<T> {}
262+
| --- ^^^ ^^^^^^^^^^
263+
| |
264+
| unsatisfied trait bound introduced here
80265
= help: see issue #48214
81266
help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
82267
|
83268
LL + #![feature(trivial_bounds)]
84269
|
85270

86271
error[E0277]: the trait bound `(): SubGeneric<u16>` is not satisfied
87-
--> $DIR/super-assoc-mismatch.rs:55:22
272+
--> $DIR/super-assoc-mismatch.rs:89:22
88273
|
89274
LL | type Assoc1<T> = ();
90275
| ^^ the trait `SubGeneric<u16>` is not implemented for `()`, which is required by `<u8 as MultiAssoc>::Assoc1<()>: SubGeneric<<u8 as MultiAssoc>::Assoc2>`
91276
|
92277
help: this trait has no implementations, consider adding one
93-
--> $DIR/super-assoc-mismatch.rs:43:1
278+
--> $DIR/super-assoc-mismatch.rs:77:1
94279
|
95280
LL | trait SubGeneric<T>: SuperGeneric<T, Assoc = T> {}
96281
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
97282
note: required by a bound in `MultiAssoc`
98-
--> $DIR/super-assoc-mismatch.rs:46:23
283+
--> $DIR/super-assoc-mismatch.rs:80:23
99284
|
100285
LL | trait MultiAssoc
101286
| ---------- required by a bound in this trait
102287
LL | where
103288
LL | Self::Assoc1<()>: SubGeneric<Self::Assoc2>
104289
| ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `MultiAssoc`
105290

106-
error: aborting due to 6 previous errors
291+
error: aborting due to 16 previous errors
107292

108-
For more information about this error, try `rustc --explain E0277`.
293+
Some errors have detailed explanations: E0271, E0277.
294+
For more information about an error, try `rustc --explain E0271`.

0 commit comments

Comments
 (0)