@@ -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,29 @@ fn ty_to_dyn_unsizing() {
193
215
"Unique; substitution [], lifetime constraints []"
194
216
}
195
217
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)
196
241
goal {
197
242
forall<' a> {
198
243
Bar : Unsize <dyn Principal + Auto + ' a>
@@ -201,6 +246,16 @@ fn ty_to_dyn_unsizing() {
201
246
"No possible solution"
202
247
}
203
248
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
204
259
goal {
205
260
forall<' a> {
206
261
Baz : Unsize <dyn Principal + Auto + ' a>
@@ -209,6 +264,7 @@ fn ty_to_dyn_unsizing() {
209
264
"No possible solution"
210
265
}
211
266
267
+ // Implemeted generic principal
212
268
goal {
213
269
forall<' a> {
214
270
Foo : Unsize <dyn GenericPrincipal <u32 , Item = u32 > + ' a>
@@ -217,6 +273,8 @@ fn ty_to_dyn_unsizing() {
217
273
"Unique; substitution [], lifetime constraints []"
218
274
}
219
275
276
+
277
+ // Non-implemeted generic principal
220
278
goal {
221
279
forall<' a> {
222
280
Foo : Unsize <dyn GenericPrincipal <u32 , Item = u64 > + ' a>
@@ -225,6 +283,7 @@ fn ty_to_dyn_unsizing() {
225
283
"No possible solution"
226
284
}
227
285
286
+ // Not object-safe principal trait
228
287
goal {
229
288
forall<' a> {
230
289
Foo : Unsize <dyn UnsafePrincipal + ' a>
@@ -233,6 +292,7 @@ fn ty_to_dyn_unsizing() {
233
292
"No possible solution"
234
293
}
235
294
295
+ // Source ty is not Sized
236
296
goal {
237
297
forall<' a> {
238
298
forall<T > {
@@ -243,6 +303,7 @@ fn ty_to_dyn_unsizing() {
243
303
"No possible solution"
244
304
}
245
305
306
+ // Sized counterpart for the previous test
246
307
goal {
247
308
forall<' a> {
248
309
forall<T > {
@@ -296,6 +357,7 @@ fn tuple_unsizing() {
296
357
"Unique; substitution [], lifetime constraints []"
297
358
}
298
359
360
+ // Last field does not implement `Unsize`
299
361
goal {
300
362
forall<' a> {
301
363
( u32 , Foo ) : Unsize <( u32 , dyn OtherPrincipal + ' a) >
@@ -304,6 +366,7 @@ fn tuple_unsizing() {
304
366
"No possible solution"
305
367
}
306
368
369
+ // Mismatch of head fields
307
370
goal {
308
371
forall<' a> {
309
372
( u32 , Foo ) : Unsize <( u64 , dyn Principal + ' a) >
@@ -312,6 +375,7 @@ fn tuple_unsizing() {
312
375
"No possible solution"
313
376
}
314
377
378
+ // Tuple length mismatch
315
379
goal {
316
380
forall<' a> {
317
381
( u32 , u32 , Foo ) : Unsize <( u32 , dyn Principal + ' a) >
@@ -320,6 +384,7 @@ fn tuple_unsizing() {
320
384
"No possible solution"
321
385
}
322
386
387
+ // Multilevel tuple test
323
388
goal {
324
389
forall<' a> {
325
390
( u32 , ( u32 , Foo ) ) : Unsize <( u32 , ( u32 , dyn Principal + ' a) ) >
@@ -424,6 +489,7 @@ fn struct_unsizing() {
424
489
impl Principal for Foo { }
425
490
}
426
491
492
+ // Single field struct tests
427
493
goal {
428
494
Foo : Unsize <Foo >
429
495
} yields {
@@ -446,6 +512,7 @@ fn struct_unsizing() {
446
512
"No possible solution"
447
513
}
448
514
515
+ // Unsizing parameter is used in head fields
449
516
goal {
450
517
forall<' a> {
451
518
SParamsInMultipleFields <Foo >:
@@ -455,6 +522,7 @@ fn struct_unsizing() {
455
522
"No possible solution"
456
523
}
457
524
525
+ // Two-field struct test
458
526
goal {
459
527
forall<' a> {
460
528
S12 <Foo , Foo >: Unsize <S12 <Foo , dyn Principal + ' a>>
@@ -463,6 +531,8 @@ fn struct_unsizing() {
463
531
"Unique; substitution [], lifetime constraints []"
464
532
}
465
533
534
+ // Test for the unsizing parameters collector
535
+ // (checking that it ignores the binder inside `SWithBinders`)
466
536
goal {
467
537
forall<' a> {
468
538
SWithBinders <Foo , Foo >: Unsize <SWithBinders <dyn Principal + ' a, Foo >>
@@ -471,6 +541,7 @@ fn struct_unsizing() {
471
541
"Unique; substitution [], lifetime constraints []"
472
542
}
473
543
544
+ // Non-trivial unsizing of the last field
474
545
goal {
475
546
forall<' a> {
476
547
SNested <Foo , Bar <Foo >, Foo >: Unsize <SNested <Foo , Bar <Foo >, dyn Principal + ' a>>
@@ -487,6 +558,7 @@ fn struct_unsizing() {
487
558
"No possible solution"
488
559
}
489
560
561
+ // Check that lifetimes can't be used as unsizing parameters
490
562
goal {
491
563
forall<' a> {
492
564
SLifetime <' a, Foo >: Unsize <SLifetime <' a, dyn Principal + ' a>>
@@ -495,18 +567,22 @@ fn struct_unsizing() {
495
567
"Unique; substitution [], lifetime constraints []"
496
568
}
497
569
570
+ // Tests with constant as an unsizing parameter
498
571
goal {
499
572
SGoodConst <5 , [ u32 ; 2 ] >: Unsize <SGoodConst <5 , [ u32 ] >>
500
573
} yields {
501
574
"Unique; substitution [], lifetime constraints []"
502
575
}
503
576
577
+
578
+ // Target does not match source
504
579
goal {
505
580
SGoodConst <4 , [ u32 ; 2 ] >: Unsize <SGoodConst <5 , [ u32 ] >>
506
581
} yields {
507
582
"No possible solution"
508
583
}
509
584
585
+ // Unsizing parameter is used in head fields
510
586
goal {
511
587
SBadConst <5 , [ u32 ; 2 ] >: Unsize <SBadConst <5 , [ u32 ] >>
512
588
} yields {
0 commit comments