File: path_lookup_wf_constraints.rs

package info (click to toggle)
rustc 1.86.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 913,560 kB
  • sloc: xml: 158,127; python: 35,921; javascript: 19,689; sh: 19,600; cpp: 18,906; ansic: 13,124; asm: 4,376; makefile: 708; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (39 lines) | stat: -rw-r--r-- 949 bytes parent folder | download | duplicates (3)
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::<()>();
}