#![deny(deref_into_dyn_supertrait)] use std::ops::Deref; trait Bar {} impl Bar for T {} trait Foo: Bar { fn as_dyn_bar_u32<'a>(&self) -> &(dyn Bar + 'a); } impl Foo for () { fn as_dyn_bar_u32<'a>(&self) -> &(dyn Bar + 'a) { self } } impl<'a> Deref for dyn Foo + 'a { type Target = dyn Bar + 'a; fn deref(&self) -> &Self::Target { self.as_dyn_bar_u32() } } fn take_dyn(x: &dyn Bar) -> T { todo!() } fn main() { let x: &dyn Foo = &(); let y = take_dyn(x); let z: u32 = y; //~^ ERROR mismatched types }