about summary refs log tree commit diff
path: root/tests/ui/traits/vtable/impossible-method.rs
blob: ff7910cfac86b8c663462ed0617a2c8d1f8eef5e (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
//@ run-pass
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver

trait Id {
    type This<'a>;
}
impl<T> Id for T {
    type This<'a> = T;
}

trait Trait<T> {}
impl<T: Id> Trait<for<'a> fn(T::This<'a>)> for T {}

trait Method<T: Id> {
    fn call_me(&self)
    where
        T: Trait<for<'a> fn(T::This<'a>)>;
}

impl<T, U> Method<U> for T {
    fn call_me(&self) {
        println!("method was reachable");
    }
}

fn generic<T: Id>(x: &dyn Method<T>) {
    // Proving `T: Trait<for<'a> fn(T::This<'a>)>` holds.
    x.call_me();
}

fn main() {
    // Proving `u32: Trait<fn(u32)>` fails due to incompleteness.
    // We don't add the method to the vtable of `dyn Method`, so
    // calling it causes UB.
    generic::<u32>(&());
}