|
| 1 | +//@ check-pass |
| 2 | + |
| 3 | +#![feature(generic_arg_infer)] |
| 4 | + |
| 5 | +// Test that if we defer repeat expr copy checks to end of typechecking they're |
| 6 | +// checked before integer fallback occurs. We accomplish this by contriving a |
| 7 | +// situation where we have a goal that can be proven either via another repeat expr |
| 8 | +// check or by integer fallback. In the integer fallback case an array length would |
| 9 | +// be inferred to `2` requiring `NotCopy: Copy`, and in the repeat expr case it would |
| 10 | +// be inferred to `1`. |
| 11 | + |
| 12 | +use std::marker::PhantomData; |
| 13 | + |
| 14 | +struct NotCopy; |
| 15 | + |
| 16 | +struct Foo<T>(PhantomData<T>); |
| 17 | + |
| 18 | +impl Clone for Foo<u32> { |
| 19 | + fn clone(&self) -> Self { |
| 20 | + Foo(PhantomData) |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +impl Copy for Foo<u32> {} |
| 25 | + |
| 26 | +fn tie<T>(_: &T, _: [Foo<T>; 2]) {} |
| 27 | + |
| 28 | +trait Trait<const N: usize> {} |
| 29 | + |
| 30 | +impl Trait<2> for i32 {} |
| 31 | +impl Trait<1> for u32 {} |
| 32 | + |
| 33 | +fn make_goal<T: Trait<N>, const N: usize>(_: &T, _: [NotCopy; N]) {} |
| 34 | + |
| 35 | +fn main() { |
| 36 | + let a = 1; |
| 37 | + let b: [Foo<_>; 2] = [Foo(PhantomData); _]; |
| 38 | + tie(&a, b); |
| 39 | + let c = [NotCopy; _]; |
| 40 | + |
| 41 | + // a is of type `?y` |
| 42 | + // b is of type `[Foo<?y>; 2]` |
| 43 | + // c is of type `[NotCopy; ?x]` |
| 44 | + // there is a goal ?y: Trait<?x>` with two candidates: |
| 45 | + // - `i32: Trait<2>`, ?y=i32 ?x=2 which requires `NotCopy: Copy` when expr checks happen |
| 46 | + // - `u32: Trait<1>` ?y=u32 ?x=1 which doesnt require `NotCopy: Copy` |
| 47 | + make_goal(&a, c); |
| 48 | + |
| 49 | + // final repeat expr checks: |
| 50 | + // |
| 51 | + // `Foo<?y>; 2` |
| 52 | + // - Foo<?y>: Copy |
| 53 | + // - requires ?y=u32 |
| 54 | + // |
| 55 | + // `NotCopy; ?x` |
| 56 | + // - fails if fallback happens before repeat exprs as `i32: Trait<?x>` infers `?x=2` |
| 57 | + // - succeeds if repeat expr checks happen first as `?y=u32` means `u32: Trait<?x>` |
| 58 | + // infers `?x=1` |
| 59 | +} |
0 commit comments