about summary refs log tree commit diff
path: root/tests/ui/impl-trait/method/broken-deref-chain.rs
blob: 8b45e044f433258e7d7ec36d1c1394d436342748 (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
40
41
42
43
44
45
46
47
//@ revisions: current next
//@[next] compile-flags: -Znext-solver
//@[next] check-pass

// An annoying edge case of method selection. While computing the deref-chain
// constrains `T` to `u32`, the final method candidate does not and instead
// constrains to `i32`. In this case, we no longer check that the opaque
// remains unconstrained. Both method calls in this test constrain the opaque
// to `i32`.
use std::ops::Deref;

struct Foo<T, U>(T, U);
impl<U> Deref for Foo<u32, U> {
    type Target = U;
    fn deref(&self) -> &Self::Target {
        &self.1
    }
}

impl Foo<i32, i32> {
    fn method(&self) {}
}
fn inherent_method() -> impl Sized {
    if false {
        let x = Foo(Default::default(), inherent_method());
        x.method();
        let _: Foo<i32, _> = x; // Test that we did not apply the deref step
    }
    1i32
}

trait Trait {
    fn trait_method(&self) {}
}
impl Trait for Foo<i32, i32> {}
impl Trait for i32 {}
fn trait_method() -> impl Trait {
    if false {
        let x = Foo(Default::default(), trait_method());
        x.trait_method();
        let _: Foo<i32, _> = x; // Test that we did not apply the deref step
        //[current]~^ ERROR mismatched types
    }
    1i32
}

fn main() {}