about summary refs log tree commit diff
path: root/tests/ui/impl-trait/method/would-constrain-opaque.rs
blob: 8dd322825296bbfe5c9db7e2275437ae097f8bee (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
//@ revisions: current next
//@[next] compile-flags: -Znext-solver

// If we don't treat `impl Sized` as rigid, the first call would
// resolve to the trait method, constraining the opaque, while the
// second call would resolve to the inherent method.
//
// We avoid cases like this by rejecting candidates which constrain
// opaque types encountered in the autoderef chain.
//
// FIXME(-Znext-solver): ideally we would note that the inference variable
// is an opaque type in the error message and change this to a type annotations
// needed error.

trait Trait: Sized {
    fn method(self) {}
}
impl Trait for &Foo {}

struct Foo;
impl Foo {
    fn method(&self) {}
}

fn define_opaque(b: bool) -> impl Sized {
    if b {
        let x = &define_opaque(false);
        x.method();
        //~^ ERROR no method named `method` found for reference
        x.method();
        //~^ ERROR no method named `method` found for reference
    }

    Foo
}

fn main() {
    define_opaque(true);
}