about summary refs log tree commit diff
path: root/tests/ui/traits/next-solver/method/path_lookup_wf_constraints.rs
blob: fbe170b1990e7c2dc0d818697a7bbebfc4cbab6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//@ compile-flags: -Znext-solver
//@ check-pass

// A regression test for trait-system-refactor-initiative#161

trait Constrain<T> {
    type Assoc;
}
impl<T> Constrain<T> for () {
    type Assoc = ();
}
struct Foo<T, U = <() as Constrain<T>>::Assoc>(T, U);

impl<T: Copy> Foo<T> {
    fn foo() {}
}
struct B;
impl Foo<B> {
    fn foo() {}
}

type Alias<T> = Foo<T>;
fn via_guidance<T: Copy>()
where
    (): Constrain<T>,
{
    // Method selection on `Foo<?t, <() as Constrain<?t>>::Assoc>` is ambiguous.
    // only by unnecessarily constraining `?t` to `T` when proving `(): Constrain<?t>`
    // are we able to select the first impl.
    //
    // This happens in the old solver when normalizing `Alias<?t>`. The new solver doesn't try
    // to eagerly normalize `<() as Constrain<?t>>::Assoc` so we instead always prove that the
    // self type is well-formed before method lookup.
    Alias::foo();
}

fn main() {
    via_guidance::<()>();
}