// Taken from https://github.com/rust-lang/rust/issues/44454#issuecomment-1175925928 trait Trait: 'static { type Assoc: AsRef; } fn hr(x: T::Assoc) -> Box + 'static> where T: Trait { Box::new(x) } fn extend_lt<'a>(x: &'a str) -> Box + 'static> { type DynTrait = dyn for<'a> Trait<&'a str, Assoc = &'a str>; hr::(x) //~ ERROR: borrowed data escapes outside of function } fn main() { let extended = extend_lt(&String::from("hello")); println!("{}", extended.as_ref().as_ref()); }