Skip to content

Commit 4189525

Browse files
committed
add some more tests and test comments
1 parent f63aee5 commit 4189525

File tree

4 files changed

+83
-6
lines changed

4 files changed

+83
-6
lines changed

chalk-ir/src/debug.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ impl<I: Interner> Debug for DynTy<I> {
210210
write!(fmt, "dyn {:?} + {:?}", bounds, lifetime)
211211
}
212212
}
213+
213214
impl Debug for InferenceVar {
214215
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
215216
write!(fmt, "?{}", self.index)

tests/test/builtin_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
mod clone;
22
mod copy;
3+
mod fn_family;
34
mod sized;
45
mod unsize;
5-
mod fn_family;

tests/test/builtin_impls/fn_family.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,4 @@ fn function_implement_fn_traits() {
179179
"Floundered"
180180
}
181181
}
182-
}
182+
}

tests/test/builtin_impls/unsize.rs

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ fn dyn_to_dyn_unsizing() {
2929
trait Auto3 {}
3030
}
3131

32+
// Tests with the same principal and auto traits
3233
goal {
3334
forall<'a> {
3435
forall<'b> {
@@ -39,6 +40,17 @@ fn dyn_to_dyn_unsizing() {
3940
"Unique; substitution [], lifetime constraints [InEnvironment { environment: Env([]), goal: '!1_0: '!2_0 }]"
4041
}
4142

43+
goal {
44+
forall<'a> {
45+
forall<'b> {
46+
dyn Principal + Auto1 + Auto2 + Auto3 + 'a: Unsize<dyn Principal + Auto1 + Auto2 + Auto3 + 'b>
47+
}
48+
}
49+
} yields {
50+
"Unique; substitution [], lifetime constraints [InEnvironment { environment: Env([]), goal: '!1_0: '!2_0 }]"
51+
}
52+
53+
// Target has a subset of source auto traits
4254
goal {
4355
forall<'a> {
4456
dyn Principal + Auto1 + Auto2 + 'a: Unsize<dyn Principal + Auto1 + 'a>
@@ -47,6 +59,7 @@ fn dyn_to_dyn_unsizing() {
4759
"Unique; substitution [], lifetime constraints [InEnvironment { environment: Env([]), goal: '!1_0: '!1_0 }]"
4860
}
4961

62+
// Both target and source don't have principal as their first trait
5063
goal {
5164
forall<'a> {
5265
dyn Auto1 + Principal + 'a: Unsize<dyn Auto1 + Principal + 'a>
@@ -55,6 +68,7 @@ fn dyn_to_dyn_unsizing() {
5568
"Unique; substitution [], lifetime constraints [InEnvironment { environment: Env([]), goal: '!1_0: '!1_0 }]"
5669
}
5770

71+
// Different order of traits in target and source
5872
// FIXME: this doesn't work because trait object unification
5973
// respects where clause order, which it shouldn't
6074
goal {
@@ -65,7 +79,7 @@ fn dyn_to_dyn_unsizing() {
6579
"No possible solution"
6680
}
6781

68-
// Same as above
82+
// See above
6983
goal {
7084
forall<'a> {
7185
dyn Principal + Auto2 + Auto1 + 'a: Unsize<dyn Principal + Auto1 + Auto2 + 'a>
@@ -74,6 +88,7 @@ fn dyn_to_dyn_unsizing() {
7488
"No possible solution"
7589
}
7690

91+
// Source has a subset of auto traits of target
7792
goal {
7893
forall<'a> {
7994
dyn Principal + Auto2 + 'a: Unsize<dyn Principal + Auto1 + Auto2 + 'a>
@@ -82,6 +97,7 @@ fn dyn_to_dyn_unsizing() {
8297
"No possible solution"
8398
}
8499

100+
// Source and target have different set of auto traits
85101
goal {
86102
forall<'a> {
87103
dyn Principal + Auto1 + Auto2 + 'a: Unsize<dyn Principal + Auto1 + Auto3 + 'a>
@@ -90,6 +106,7 @@ fn dyn_to_dyn_unsizing() {
90106
"No possible solution"
91107
}
92108

109+
// Source has a principal trait, while target doesnt, both have the same auto traits.
93110
goal {
94111
forall<'a> {
95112
dyn Principal + Auto1 + 'a: Unsize<dyn Auto1 + 'a>
@@ -98,6 +115,7 @@ fn dyn_to_dyn_unsizing() {
98115
"No possible solution"
99116
}
100117

118+
// Non-matching principal traits
101119
goal {
102120
forall<'a> {
103121
dyn Principal + 'a: Unsize<dyn OtherPrincipal + 'a>
@@ -106,6 +124,7 @@ fn dyn_to_dyn_unsizing() {
106124
"No possible solution"
107125
}
108126

127+
// Matching generic principal traits
109128
goal {
110129
forall<'a> {
111130
dyn GenericPrincipal<u64, Item = u64> + 'a: Unsize<dyn GenericPrincipal<u64, Item = u64> + 'a>
@@ -114,6 +133,7 @@ fn dyn_to_dyn_unsizing() {
114133
"Unique; substitution [], lifetime constraints [InEnvironment { environment: Env([]), goal: '!1_0: '!1_0 }]"
115134
}
116135

136+
// Non-matching generic principal traits
117137
goal {
118138
forall<'a> {
119139
dyn GenericPrincipal<u32, Item = u32> + 'a: Unsize<dyn GenericPrincipal<u32, Item = u64> + 'a>
@@ -147,21 +167,21 @@ fn ty_to_dyn_unsizing() {
147167
trait Auto {}
148168

149169
struct Foo {}
170+
struct FooLifetime<'a> {}
150171
struct Bar {}
151172
struct Baz {}
152173
struct FooNotSized<T> {
153174
t: T
154175
}
155176

156177
impl Principal for Foo {}
157-
impl Auto for Foo {}
158178
impl UnsafePrincipal for Foo {}
159179

180+
impl<'a> Principal for FooLifetime<'a> {}
181+
160182
impl Principal for Bar {}
161183
impl !Auto for Bar {}
162184

163-
impl Auto for Baz {}
164-
165185
impl<T> Principal for FooNotSized<T> {}
166186

167187
impl GenericPrincipal<u32> for Foo {
@@ -177,6 +197,7 @@ fn ty_to_dyn_unsizing() {
177197
"Unique; substitution [], lifetime constraints []"
178198
}
179199

200+
// Principal is not the first trait
180201
goal {
181202
forall<'a> {
182203
Foo: Unsize<dyn Auto + Principal + 'a>
@@ -185,6 +206,7 @@ fn ty_to_dyn_unsizing() {
185206
"Unique; substitution [], lifetime constraints []"
186207
}
187208

209+
// Auto-only trait object
188210
goal {
189211
forall<'a> {
190212
Foo: Unsize<dyn Auto + 'a>
@@ -193,6 +215,29 @@ fn ty_to_dyn_unsizing() {
193215
"Unique; substitution [], lifetime constraints []"
194216
}
195217

218+
// TypeOutlives test
219+
// FIXME: this should create a constraint 'a: 'a, but currently
220+
// we have no `TypeOutlives` goal to produce it
221+
goal {
222+
forall<'a> {
223+
FooLifetime<'a>: Unsize<dyn Principal + Auto + 'a>
224+
}
225+
} yields {
226+
"Unique; substitution [], lifetime constraints []"
227+
}
228+
229+
// See above
230+
goal {
231+
forall<'a> {
232+
exists<'b> {
233+
FooLifetime<'a>: Unsize<dyn Principal + Auto + 'b>
234+
}
235+
}
236+
} yields {
237+
"Unique; for<?U1> { substitution [?0 := '^0.0], lifetime constraints [] }"
238+
}
239+
240+
// Source does not implement auto trait (with principal)
196241
goal {
197242
forall<'a> {
198243
Bar: Unsize<dyn Principal + Auto + 'a>
@@ -201,6 +246,16 @@ fn ty_to_dyn_unsizing() {
201246
"No possible solution"
202247
}
203248

249+
// Source does not implement auto trait (without principal)
250+
goal {
251+
forall<'a> {
252+
Bar: Unsize<dyn Auto + 'a>
253+
}
254+
} yields {
255+
"No possible solution"
256+
}
257+
258+
// Source does not implement principal
204259
goal {
205260
forall<'a> {
206261
Baz: Unsize<dyn Principal + Auto + 'a>
@@ -209,6 +264,7 @@ fn ty_to_dyn_unsizing() {
209264
"No possible solution"
210265
}
211266

267+
// Implemeted generic principal
212268
goal {
213269
forall<'a> {
214270
Foo: Unsize<dyn GenericPrincipal<u32, Item = u32> + 'a>
@@ -217,6 +273,8 @@ fn ty_to_dyn_unsizing() {
217273
"Unique; substitution [], lifetime constraints []"
218274
}
219275

276+
277+
// Non-implemeted generic principal
220278
goal {
221279
forall<'a> {
222280
Foo: Unsize<dyn GenericPrincipal<u32, Item = u64> + 'a>
@@ -225,6 +283,7 @@ fn ty_to_dyn_unsizing() {
225283
"No possible solution"
226284
}
227285

286+
// Not object-safe principal trait
228287
goal {
229288
forall<'a> {
230289
Foo: Unsize<dyn UnsafePrincipal + 'a>
@@ -233,6 +292,7 @@ fn ty_to_dyn_unsizing() {
233292
"No possible solution"
234293
}
235294

295+
// Source ty is not Sized
236296
goal {
237297
forall<'a> {
238298
forall<T> {
@@ -243,6 +303,7 @@ fn ty_to_dyn_unsizing() {
243303
"No possible solution"
244304
}
245305

306+
// Sized counterpart for the previous test
246307
goal {
247308
forall<'a> {
248309
forall<T> {
@@ -296,6 +357,7 @@ fn tuple_unsizing() {
296357
"Unique; substitution [], lifetime constraints []"
297358
}
298359

360+
// Last field does not implement `Unsize`
299361
goal {
300362
forall<'a> {
301363
(u32, Foo): Unsize<(u32, dyn OtherPrincipal + 'a)>
@@ -304,6 +366,7 @@ fn tuple_unsizing() {
304366
"No possible solution"
305367
}
306368

369+
// Mismatch of head fields
307370
goal {
308371
forall<'a> {
309372
(u32, Foo): Unsize<(u64, dyn Principal + 'a)>
@@ -312,6 +375,7 @@ fn tuple_unsizing() {
312375
"No possible solution"
313376
}
314377

378+
// Tuple length mismatch
315379
goal {
316380
forall<'a> {
317381
(u32, u32, Foo): Unsize<(u32, dyn Principal + 'a)>
@@ -320,6 +384,7 @@ fn tuple_unsizing() {
320384
"No possible solution"
321385
}
322386

387+
// Multilevel tuple test
323388
goal {
324389
forall<'a> {
325390
(u32, (u32, Foo)): Unsize<(u32, (u32, dyn Principal + 'a))>
@@ -424,6 +489,7 @@ fn struct_unsizing() {
424489
impl Principal for Foo {}
425490
}
426491

492+
// Single field struct tests
427493
goal {
428494
Foo: Unsize<Foo>
429495
} yields {
@@ -446,6 +512,7 @@ fn struct_unsizing() {
446512
"No possible solution"
447513
}
448514

515+
// Unsizing parameter is used in head fields
449516
goal {
450517
forall<'a> {
451518
SParamsInMultipleFields<Foo>:
@@ -455,6 +522,7 @@ fn struct_unsizing() {
455522
"No possible solution"
456523
}
457524

525+
// Two-field struct test
458526
goal {
459527
forall<'a> {
460528
S12<Foo, Foo>: Unsize<S12<Foo, dyn Principal + 'a>>
@@ -463,6 +531,8 @@ fn struct_unsizing() {
463531
"Unique; substitution [], lifetime constraints []"
464532
}
465533

534+
// Test for the unsizing parameters collector
535+
// (checking that it ignores the binder inside `SWithBinders`)
466536
goal {
467537
forall<'a> {
468538
SWithBinders<Foo, Foo>: Unsize<SWithBinders<dyn Principal + 'a, Foo>>
@@ -471,6 +541,7 @@ fn struct_unsizing() {
471541
"Unique; substitution [], lifetime constraints []"
472542
}
473543

544+
// Non-trivial unsizing of the last field
474545
goal {
475546
forall<'a> {
476547
SNested<Foo, Bar<Foo>, Foo>: Unsize<SNested<Foo, Bar<Foo>, dyn Principal + 'a>>
@@ -487,6 +558,7 @@ fn struct_unsizing() {
487558
"No possible solution"
488559
}
489560

561+
// Check that lifetimes can't be used as unsizing parameters
490562
goal {
491563
forall<'a> {
492564
SLifetime<'a, Foo>: Unsize<SLifetime<'a, dyn Principal + 'a>>
@@ -495,18 +567,22 @@ fn struct_unsizing() {
495567
"Unique; substitution [], lifetime constraints []"
496568
}
497569

570+
// Tests with constant as an unsizing parameter
498571
goal {
499572
SGoodConst<5, [u32; 2]>: Unsize<SGoodConst<5, [u32]>>
500573
} yields {
501574
"Unique; substitution [], lifetime constraints []"
502575
}
503576

577+
578+
// Target does not match source
504579
goal {
505580
SGoodConst<4, [u32; 2]>: Unsize<SGoodConst<5, [u32]>>
506581
} yields {
507582
"No possible solution"
508583
}
509584

585+
// Unsizing parameter is used in head fields
510586
goal {
511587
SBadConst<5, [u32; 2]>: Unsize<SBadConst<5, [u32]>>
512588
} yields {

0 commit comments

Comments
 (0)