// Taken from https://github.com/rust-lang/rust/issues/44454#issuecomment-1332781290 use std::any::Any; trait Animal: 'static {} trait Projector { type Foo; } impl Projector for dyn Animal { type Foo = X; } fn make_static<'a, T>(t: &'a T) -> &'static T { let x: as Projector>::Foo = t; let any = generic::, &'a T>(x); //~^ ERROR: lifetime may not live long enough any.downcast_ref::<&'static T>().unwrap() } fn generic + ?Sized, U>(x: ::Foo) -> Box { make_static_any(x) } fn make_static_any(u: U) -> Box { Box::new(u) } fn main() { let a = make_static(&"salut".to_string()); println!("{}", *a); }