Skip to content

Commit 5ea95e7

Browse files
super-tupledaboross
authored andcommitted
Add inverted (var on left side) subtype tests
Expanding on our earlier bugfix, we've added additional tests where the generalized inference var is on the left side. This will help catch any bugs where the variance or the parameters inadvertantly get flipped. Co-authored-by: David Ross <daboross@daboross.net>
1 parent 37c8340 commit 5ea95e7

File tree

1 file changed

+149
-0
lines changed

1 file changed

+149
-0
lines changed

tests/test/subtype.rs

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,20 @@ fn multi_lifetime_covariant_struct() {
224224
InEnvironment { environment: Env([]), goal: '!1_1: '^0.0 } \
225225
]}"
226226
}
227+
goal {
228+
forall<'a, 'b> {
229+
exists<U> {
230+
Subtype(Foo<U>, Foo<&'a u32>),
231+
Subtype(Foo<U>, Foo<&'b u32>)
232+
}
233+
}
234+
} yields {
235+
// Result should be identical to multi_lifetime result.
236+
"Unique; for<?U1> { substitution [?0 := (&'^0.0 Uint(U32))], lifetime constraints [\
237+
InEnvironment { environment: Env([]), goal: '^0.0: '!1_0 }, \
238+
InEnvironment { environment: Env([]), goal: '^0.0: '!1_1 } \
239+
]}"
240+
}
227241
}
228242
}
229243

@@ -250,6 +264,20 @@ fn multi_lifetime_contravariant_struct() {
250264
InEnvironment { environment: Env([]), goal: '^0.0: '!1_1 } \
251265
]}"
252266
}
267+
goal {
268+
forall<'a, 'b> {
269+
exists<U> {
270+
Subtype(Foo<U>, Foo<&'a u32>),
271+
Subtype(Foo<U>, Foo<&'b u32>)
272+
}
273+
}
274+
} yields {
275+
// Result should be opposite multi_lifetime result.
276+
"Unique; for<?U1> { substitution [?0 := (&'^0.0 Uint(U32))], lifetime constraints [\
277+
InEnvironment { environment: Env([]), goal: '!1_0: '^0.0 }, \
278+
InEnvironment { environment: Env([]), goal: '!1_1: '^0.0 } \
279+
]}"
280+
}
253281
}
254282
}
255283

@@ -282,6 +310,27 @@ fn multi_lifetime_invariant_struct() {
282310
InEnvironment { environment: Env([]), goal: '!1_1: '!1_0 } \
283311
]"
284312
}
313+
314+
goal {
315+
forall<'a, 'b> {
316+
exists<U> {
317+
Subtype(Foo<U>, Foo<&'a u32>),
318+
Subtype(Foo<U>, Foo<&'b u32>)
319+
}
320+
}
321+
} yields[SolverChoice::recursive()] {
322+
// Because A is invariant, we require the lifetimes to be equal
323+
"Unique; substitution [?0 := (&'!1_0 Uint(U32))], lifetime constraints [\
324+
InEnvironment { environment: Env([]), goal: '!1_0: '!1_1 }, \
325+
InEnvironment { environment: Env([]), goal: '!1_1: '!1_0 } \
326+
]"
327+
} yields[SolverChoice::slg_default()] {
328+
// Because A is invariant, we require the lifetimes to be equal
329+
"Unique; substitution [?0 := (&'!1_1 Uint(U32))], lifetime constraints [\
330+
InEnvironment { environment: Env([]), goal: '!1_0: '!1_1 }, \
331+
InEnvironment { environment: Env([]), goal: '!1_1: '!1_0 } \
332+
]"
333+
}
285334
}
286335
}
287336

@@ -306,6 +355,20 @@ fn multi_lifetime_slice() {
306355
InEnvironment { environment: Env([]), goal: '!1_1: '^0.0 } \
307356
]}"
308357
}
358+
goal {
359+
forall<'a, 'b> {
360+
exists<U> {
361+
Subtype([U], [&'a u32]),
362+
Subtype([U], [&'b u32])
363+
}
364+
}
365+
} yields {
366+
// Result should be identical to multi_lifetime result.
367+
"Unique; for<?U1> { substitution [?0 := (&'^0.0 Uint(U32))], lifetime constraints [\
368+
InEnvironment { environment: Env([]), goal: '^0.0: '!1_0 }, \
369+
InEnvironment { environment: Env([]), goal: '^0.0: '!1_1 } \
370+
]}"
371+
}
309372
}
310373
}
311374

@@ -330,6 +393,20 @@ fn multi_lifetime_tuple() {
330393
InEnvironment { environment: Env([]), goal: '!1_1: '^0.0 } \
331394
]}"
332395
}
396+
goal {
397+
forall<'a, 'b> {
398+
exists<U> {
399+
Subtype((U,), (&'a u32,)),
400+
Subtype((U,), (&'b u32,))
401+
}
402+
}
403+
} yields {
404+
// Result should be identical to multi_lifetime result.
405+
"Unique; for<?U1> { substitution [?0 := (&'^0.0 Uint(U32))], lifetime constraints [\
406+
InEnvironment { environment: Env([]), goal: '^0.0: '!1_0 }, \
407+
InEnvironment { environment: Env([]), goal: '^0.0: '!1_1 } \
408+
]}"
409+
}
333410
}
334411
}
335412

@@ -354,6 +431,20 @@ fn multi_lifetime_array() {
354431
InEnvironment { environment: Env([]), goal: '!1_1: '^0.0 } \
355432
]}"
356433
}
434+
goal {
435+
forall<'a, 'b> {
436+
exists<U> {
437+
Subtype([U; 16], [&'a u32; 16]),
438+
Subtype([U; 16], [&'b u32; 16])
439+
}
440+
}
441+
} yields {
442+
// Result should be identical to multi_lifetime result.
443+
"Unique; for<?U1> { substitution [?0 := (&'^0.0 Uint(U32))], lifetime constraints [\
444+
InEnvironment { environment: Env([]), goal: '^0.0: '!1_0 }, \
445+
InEnvironment { environment: Env([]), goal: '^0.0: '!1_1 } \
446+
]}"
447+
}
357448
}
358449
}
359450

@@ -460,6 +551,20 @@ fn generalize_slice() {
460551
InEnvironment { environment: Env([]), goal: '!1_1: '^0.0 } \
461552
] }"
462553
}
554+
goal {
555+
forall<'a, 'b> {
556+
exists<U> {
557+
Subtype(U, [&'a u32]),
558+
Subtype(U, [&'b u32])
559+
}
560+
}
561+
} yields {
562+
// Result should be identical to generalize_covariant_struct result.
563+
"Unique; for<?U1> { substitution [?0 := [(&'^0.0 Uint(U32))]], lifetime constraints [\
564+
InEnvironment { environment: Env([]), goal: '^0.0: '!1_0 }, \
565+
InEnvironment { environment: Env([]), goal: '^0.0: '!1_1 } \
566+
] }"
567+
}
463568
}
464569
}
465570

@@ -484,6 +589,20 @@ fn generalize_tuple() {
484589
InEnvironment { environment: Env([]), goal: '!1_1: '^0.0 } \
485590
] }"
486591
}
592+
goal {
593+
forall<'a, 'b> {
594+
exists<U> {
595+
Subtype(U, (&'a u32,)),
596+
Subtype(U, (&'b u32,))
597+
}
598+
}
599+
} yields {
600+
// Result should be identical to generalize_covariant_struct result.
601+
"Unique; for<?U1> { substitution [?0 := 1<(&'^0.0 Uint(U32))>], lifetime constraints [\
602+
InEnvironment { environment: Env([]), goal: '^0.0: '!1_0 }, \
603+
InEnvironment { environment: Env([]), goal: '^0.0: '!1_1 } \
604+
] }"
605+
}
487606
}
488607
}
489608

@@ -509,6 +628,21 @@ fn generalize_2tuple() {
509628
InEnvironment { environment: Env([]), goal: '!1_3: '^0.1 } \
510629
] }"
511630
}
631+
goal {
632+
forall<'a, 'b, 'c, 'd> {
633+
exists<U> {
634+
Subtype(U, (&'a u32, &'c u32)),
635+
Subtype(U, (&'b u32, &'d u32))
636+
}
637+
}
638+
} yields {
639+
"Unique; for<?U1, ?U1> { substitution [?0 := 2<(&'^0.0 Uint(U32)), (&'^0.1 Uint(U32))>], lifetime constraints [\
640+
InEnvironment { environment: Env([]), goal: '^0.0: '!1_0 }, \
641+
InEnvironment { environment: Env([]), goal: '^0.0: '!1_1 }, \
642+
InEnvironment { environment: Env([]), goal: '^0.1: '!1_2 }, \
643+
InEnvironment { environment: Env([]), goal: '^0.1: '!1_3 } \
644+
] }"
645+
}
512646
}
513647
}
514648

@@ -533,5 +667,20 @@ fn generalize_array() {
533667
InEnvironment { environment: Env([]), goal: '!1_1: '^0.0 } \
534668
] }"
535669
}
670+
671+
goal {
672+
forall<'a, 'b> {
673+
exists<U> {
674+
Subtype(U, [&'a u32; 16]),
675+
Subtype(U, [&'b u32; 16])
676+
}
677+
}
678+
} yields {
679+
// Result should be identical to generalize_covariant_struct result.
680+
"Unique; for<?U1> { substitution [?0 := [(&'^0.0 Uint(U32)); 16]], lifetime constraints [\
681+
InEnvironment { environment: Env([]), goal: '^0.0: '!1_0 }, \
682+
InEnvironment { environment: Env([]), goal: '^0.0: '!1_1 } \
683+
] }"
684+
}
536685
}
537686
}

0 commit comments

Comments
 (0)