Skip to content

Commit 5abfbaa

Browse files
author
Lukas Markeffsky
committed
add tests for mismatched super projections with nested obligations
1 parent 83179ae commit 5abfbaa

File tree

2 files changed

+253
-39
lines changed

2 files changed

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

83262
error[E0277]: the trait bound `(): SubGeneric<u16>` is not satisfied
84-
--> $DIR/super-assoc-mismatch.rs:55:22
263+
--> $DIR/super-assoc-mismatch.rs:89:22
85264
|
86265
LL | type Assoc1<T> = ();
87266
| ^^ the trait `SubGeneric<u16>` is not implemented for `()`, which is required by `<u8 as MultiAssoc>::Assoc1<()>: SubGeneric<<u8 as MultiAssoc>::Assoc2>`
88267
|
89268
help: this trait has no implementations, consider adding one
90-
--> $DIR/super-assoc-mismatch.rs:43:1
269+
--> $DIR/super-assoc-mismatch.rs:77:1
91270
|
92271
LL | trait SubGeneric<T>: SuperGeneric<T, Assoc = T> {}
93272
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
94273
note: required by a bound in `MultiAssoc`
95-
--> $DIR/super-assoc-mismatch.rs:46:23
274+
--> $DIR/super-assoc-mismatch.rs:80:23
96275
|
97276
LL | trait MultiAssoc
98277
| ---------- required by a bound in this trait
99278
LL | where
100279
LL | Self::Assoc1<()>: SubGeneric<Self::Assoc2>
101280
| ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `MultiAssoc`
102281

103-
error: aborting due to 6 previous errors
282+
error: aborting due to 16 previous errors
104283

105-
For more information about this error, try `rustc --explain E0277`.
284+
Some errors have detailed explanations: E0271, E0277.
285+
For more information about an error, try `rustc --explain E0271`.

0 commit comments

Comments
 (0)