@@ -29,6 +29,7 @@ fn dyn_to_dyn_unsizing() {
29
29
trait Auto3 { }
30
30
}
31
31
32
+ // Tests with the same principal and auto traits
32
33
goal {
33
34
forall<' a> {
34
35
forall<' b> {
@@ -39,6 +40,17 @@ fn dyn_to_dyn_unsizing() {
39
40
"Unique; substitution [], lifetime constraints [InEnvironment { environment: Env([]), goal: '!1_0: '!2_0 }]"
40
41
}
41
42
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
42
54
goal {
43
55
forall<' a> {
44
56
dyn Principal + Auto1 + Auto2 + ' a: Unsize <dyn Principal + Auto1 + ' a>
@@ -47,6 +59,7 @@ fn dyn_to_dyn_unsizing() {
47
59
"Unique; substitution [], lifetime constraints [InEnvironment { environment: Env([]), goal: '!1_0: '!1_0 }]"
48
60
}
49
61
62
+ // Both target and source don't have principal as their first trait
50
63
goal {
51
64
forall<' a> {
52
65
dyn Auto1 + Principal + ' a: Unsize <dyn Auto1 + Principal + ' a>
@@ -55,6 +68,7 @@ fn dyn_to_dyn_unsizing() {
55
68
"Unique; substitution [], lifetime constraints [InEnvironment { environment: Env([]), goal: '!1_0: '!1_0 }]"
56
69
}
57
70
71
+ // Different order of traits in target and source
58
72
// FIXME: this doesn't work because trait object unification
59
73
// respects where clause order, which it shouldn't
60
74
goal {
@@ -65,7 +79,7 @@ fn dyn_to_dyn_unsizing() {
65
79
"No possible solution"
66
80
}
67
81
68
- // Same as above
82
+ // See above
69
83
goal {
70
84
forall<' a> {
71
85
dyn Principal + Auto2 + Auto1 + ' a: Unsize <dyn Principal + Auto1 + Auto2 + ' a>
@@ -74,6 +88,7 @@ fn dyn_to_dyn_unsizing() {
74
88
"No possible solution"
75
89
}
76
90
91
+ // Source has a subset of auto traits of target
77
92
goal {
78
93
forall<' a> {
79
94
dyn Principal + Auto2 + ' a: Unsize <dyn Principal + Auto1 + Auto2 + ' a>
@@ -82,6 +97,7 @@ fn dyn_to_dyn_unsizing() {
82
97
"No possible solution"
83
98
}
84
99
100
+ // Source and target have different set of auto traits
85
101
goal {
86
102
forall<' a> {
87
103
dyn Principal + Auto1 + Auto2 + ' a: Unsize <dyn Principal + Auto1 + Auto3 + ' a>
@@ -90,6 +106,7 @@ fn dyn_to_dyn_unsizing() {
90
106
"No possible solution"
91
107
}
92
108
109
+ // Source has a principal trait, while target doesnt, both have the same auto traits.
93
110
goal {
94
111
forall<' a> {
95
112
dyn Principal + Auto1 + ' a: Unsize <dyn Auto1 + ' a>
@@ -98,6 +115,7 @@ fn dyn_to_dyn_unsizing() {
98
115
"No possible solution"
99
116
}
100
117
118
+ // Non-matching principal traits
101
119
goal {
102
120
forall<' a> {
103
121
dyn Principal + ' a: Unsize <dyn OtherPrincipal + ' a>
@@ -106,6 +124,7 @@ fn dyn_to_dyn_unsizing() {
106
124
"No possible solution"
107
125
}
108
126
127
+ // Matching generic principal traits
109
128
goal {
110
129
forall<' a> {
111
130
dyn GenericPrincipal <u64 , Item = u64 > + ' a: Unsize <dyn GenericPrincipal <u64 , Item = u64 > + ' a>
@@ -114,6 +133,7 @@ fn dyn_to_dyn_unsizing() {
114
133
"Unique; substitution [], lifetime constraints [InEnvironment { environment: Env([]), goal: '!1_0: '!1_0 }]"
115
134
}
116
135
136
+ // Non-matching generic principal traits
117
137
goal {
118
138
forall<' a> {
119
139
dyn GenericPrincipal <u32 , Item = u32 > + ' a: Unsize <dyn GenericPrincipal <u32 , Item = u64 > + ' a>
@@ -147,21 +167,21 @@ fn ty_to_dyn_unsizing() {
147
167
trait Auto { }
148
168
149
169
struct Foo { }
170
+ struct FooLifetime <' a> { }
150
171
struct Bar { }
151
172
struct Baz { }
152
173
struct FooNotSized <T > {
153
174
t: T
154
175
}
155
176
156
177
impl Principal for Foo { }
157
- impl Auto for Foo { }
158
178
impl UnsafePrincipal for Foo { }
159
179
180
+ impl <' a> Principal for FooLifetime <' a> { }
181
+
160
182
impl Principal for Bar { }
161
183
impl !Auto for Bar { }
162
184
163
- impl Auto for Baz { }
164
-
165
185
impl <T > Principal for FooNotSized <T > { }
166
186
167
187
impl GenericPrincipal <u32 > for Foo {
@@ -177,6 +197,7 @@ fn ty_to_dyn_unsizing() {
177
197
"Unique; substitution [], lifetime constraints []"
178
198
}
179
199
200
+ // Principal is not the first trait
180
201
goal {
181
202
forall<' a> {
182
203
Foo : Unsize <dyn Auto + Principal + ' a>
@@ -185,6 +206,7 @@ fn ty_to_dyn_unsizing() {
185
206
"Unique; substitution [], lifetime constraints []"
186
207
}
187
208
209
+ // Auto-only trait object
188
210
goal {
189
211
forall<' a> {
190
212
Foo : Unsize <dyn Auto + ' a>
@@ -193,6 +215,38 @@ fn ty_to_dyn_unsizing() {
193
215
"Unique; substitution [], lifetime constraints []"
194
216
}
195
217
218
+ // TypeOutlives tests
219
+ goal {
220
+ forall<' a> {
221
+ FooLifetime <' a>: Unsize <dyn Principal + Auto + ' a>
222
+ }
223
+ } yields {
224
+ "Unique; substitution [], lifetime constraints []"
225
+ }
226
+
227
+ // FIXME: this shouldn't be provable, but currently
228
+ // we have no `TypeOutlives` goal to check it
229
+ goal {
230
+ forall<' a, ' b> {
231
+ FooLifetime <' a>: Unsize <dyn Principal + Auto + ' b>
232
+ }
233
+ } yields {
234
+ "Unique; substitution [], lifetime constraints []"
235
+ }
236
+
237
+ // This should produce 'a: 'b constraint, but for the reasons
238
+ // above it doesn't
239
+ goal {
240
+ forall<' a> {
241
+ exists<' b> {
242
+ FooLifetime <' a>: Unsize <dyn Principal + Auto + ' b>
243
+ }
244
+ }
245
+ } yields {
246
+ "Unique; for<?U1> { substitution [?0 := '^0.0], lifetime constraints [] }"
247
+ }
248
+
249
+ // Source does not implement auto trait (with principal)
196
250
goal {
197
251
forall<' a> {
198
252
Bar : Unsize <dyn Principal + Auto + ' a>
@@ -201,6 +255,16 @@ fn ty_to_dyn_unsizing() {
201
255
"No possible solution"
202
256
}
203
257
258
+ // Source does not implement auto trait (without principal)
259
+ goal {
260
+ forall<' a> {
261
+ Bar : Unsize <dyn Auto + ' a>
262
+ }
263
+ } yields {
264
+ "No possible solution"
265
+ }
266
+
267
+ // Source does not implement principal
204
268
goal {
205
269
forall<' a> {
206
270
Baz : Unsize <dyn Principal + Auto + ' a>
@@ -209,6 +273,7 @@ fn ty_to_dyn_unsizing() {
209
273
"No possible solution"
210
274
}
211
275
276
+ // Implemeted generic principal
212
277
goal {
213
278
forall<' a> {
214
279
Foo : Unsize <dyn GenericPrincipal <u32 , Item = u32 > + ' a>
@@ -217,6 +282,8 @@ fn ty_to_dyn_unsizing() {
217
282
"Unique; substitution [], lifetime constraints []"
218
283
}
219
284
285
+
286
+ // Non-implemeted generic principal
220
287
goal {
221
288
forall<' a> {
222
289
Foo : Unsize <dyn GenericPrincipal <u32 , Item = u64 > + ' a>
@@ -225,6 +292,7 @@ fn ty_to_dyn_unsizing() {
225
292
"No possible solution"
226
293
}
227
294
295
+ // Not object-safe principal trait
228
296
goal {
229
297
forall<' a> {
230
298
Foo : Unsize <dyn UnsafePrincipal + ' a>
@@ -233,6 +301,7 @@ fn ty_to_dyn_unsizing() {
233
301
"No possible solution"
234
302
}
235
303
304
+ // Source ty is not Sized
236
305
goal {
237
306
forall<' a> {
238
307
forall<T > {
@@ -243,6 +312,7 @@ fn ty_to_dyn_unsizing() {
243
312
"No possible solution"
244
313
}
245
314
315
+ // Sized counterpart for the previous test
246
316
goal {
247
317
forall<' a> {
248
318
forall<T > {
@@ -296,6 +366,7 @@ fn tuple_unsizing() {
296
366
"Unique; substitution [], lifetime constraints []"
297
367
}
298
368
369
+ // Last field does not implement `Unsize`
299
370
goal {
300
371
forall<' a> {
301
372
( u32 , Foo ) : Unsize <( u32 , dyn OtherPrincipal + ' a) >
@@ -304,6 +375,7 @@ fn tuple_unsizing() {
304
375
"No possible solution"
305
376
}
306
377
378
+ // Mismatch of head fields
307
379
goal {
308
380
forall<' a> {
309
381
( u32 , Foo ) : Unsize <( u64 , dyn Principal + ' a) >
@@ -312,6 +384,7 @@ fn tuple_unsizing() {
312
384
"No possible solution"
313
385
}
314
386
387
+ // Tuple length mismatch
315
388
goal {
316
389
forall<' a> {
317
390
( u32 , u32 , Foo ) : Unsize <( u32 , dyn Principal + ' a) >
@@ -320,6 +393,7 @@ fn tuple_unsizing() {
320
393
"No possible solution"
321
394
}
322
395
396
+ // Multilevel tuple test
323
397
goal {
324
398
forall<' a> {
325
399
( u32 , ( u32 , Foo ) ) : Unsize <( u32 , ( u32 , dyn Principal + ' a) ) >
@@ -424,6 +498,7 @@ fn struct_unsizing() {
424
498
impl Principal for Foo { }
425
499
}
426
500
501
+ // Single field struct tests
427
502
goal {
428
503
Foo : Unsize <Foo >
429
504
} yields {
@@ -446,6 +521,7 @@ fn struct_unsizing() {
446
521
"No possible solution"
447
522
}
448
523
524
+ // Unsizing parameter is used in head fields
449
525
goal {
450
526
forall<' a> {
451
527
SParamsInMultipleFields <Foo >:
@@ -455,6 +531,7 @@ fn struct_unsizing() {
455
531
"No possible solution"
456
532
}
457
533
534
+ // Two-field struct test
458
535
goal {
459
536
forall<' a> {
460
537
S12 <Foo , Foo >: Unsize <S12 <Foo , dyn Principal + ' a>>
@@ -463,6 +540,8 @@ fn struct_unsizing() {
463
540
"Unique; substitution [], lifetime constraints []"
464
541
}
465
542
543
+ // Test for the unsizing parameters collector
544
+ // (checking that it ignores the binder inside `SWithBinders`)
466
545
goal {
467
546
forall<' a> {
468
547
SWithBinders <Foo , Foo >: Unsize <SWithBinders <dyn Principal + ' a, Foo >>
@@ -471,6 +550,7 @@ fn struct_unsizing() {
471
550
"Unique; substitution [], lifetime constraints []"
472
551
}
473
552
553
+ // Non-trivial unsizing of the last field
474
554
goal {
475
555
forall<' a> {
476
556
SNested <Foo , Bar <Foo >, Foo >: Unsize <SNested <Foo , Bar <Foo >, dyn Principal + ' a>>
@@ -487,6 +567,7 @@ fn struct_unsizing() {
487
567
"No possible solution"
488
568
}
489
569
570
+ // Check that lifetimes can't be used as unsizing parameters
490
571
goal {
491
572
forall<' a> {
492
573
SLifetime <' a, Foo >: Unsize <SLifetime <' a, dyn Principal + ' a>>
@@ -495,18 +576,22 @@ fn struct_unsizing() {
495
576
"Unique; substitution [], lifetime constraints []"
496
577
}
497
578
579
+ // Tests with constant as an unsizing parameter
498
580
goal {
499
581
SGoodConst <5 , [ u32 ; 2 ] >: Unsize <SGoodConst <5 , [ u32 ] >>
500
582
} yields {
501
583
"Unique; substitution [], lifetime constraints []"
502
584
}
503
585
586
+
587
+ // Target does not match source
504
588
goal {
505
589
SGoodConst <4 , [ u32 ; 2 ] >: Unsize <SGoodConst <5 , [ u32 ] >>
506
590
} yields {
507
591
"No possible solution"
508
592
}
509
593
594
+ // Unsizing parameter is used in head fields
510
595
goal {
511
596
SBadConst <5 , [ u32 ; 2 ] >: Unsize <SBadConst <5 , [ u32 ] >>
512
597
} yields {
0 commit comments