// Test that transmuting from `&dyn Trait` to `&dyn Trait fn(&'a ())>` is UB. // // The vtable of `() as Trait` and `() as Trait fn(&'a ())>` can have // different entries and, because in the former the entry for `foo` is vacant, this test will // segfault at runtime. trait Trait { fn foo(&self) where U: HigherRanked, { } } impl Trait for T {} trait HigherRanked {} impl HigherRanked for for<'a> fn(&'a ()) {} // 2nd candidate is required so that selecting `(): Trait` will // evaluate the candidates and fail the leak check instead of returning the // only applicable candidate. trait Unsatisfied {} impl HigherRanked for T {} fn main() { let x: &dyn Trait = &(); let y: &dyn Trait fn(&'a ())> = unsafe { std::mem::transmute(x) }; //~^ ERROR: wrong trait in wide pointer vtable y.foo(); }