#![feature(type_alias_impl_trait)] trait Static: 'static {} impl Static for () {} type Gal = impl Static; fn _defining() -> Gal {} trait Callable { type Output; } /// We can infer `>::Output: 'static`, /// because we know `C: 'static` and `Arg: 'static`, fn box_str(s: C::Output) -> Box + 'static> where Arg: Static, C: ?Sized + Callable + 'static, C::Output: AsRef, { Box::new(s) } fn extend_lifetime(s: &str) -> Box + 'static> { type MalformedTy = dyn for<'a> Callable, Output = &'a str>; //~^ ERROR binding for associated type `Output` references lifetime `'a` box_str::(s) } fn main() { let extended = extend_lifetime(&String::from("hello")); println!("{}", extended.as_ref().as_ref()); }