3 fn elided(x: &i32) -> impl Copy { x }
4 //~^ ERROR: captures lifetime that does not appear in bounds
6 fn explicit<'a>(x: &'a i32) -> impl Copy { x }
7 //~^ ERROR: captures lifetime that does not appear in bounds
9 fn elided2(x: &i32) -> impl Copy + 'static { x }
10 //~^ ERROR lifetime may not live long enough
12 fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
13 //~^ ERROR lifetime may not live long enough
15 fn foo<'a>(x: &i32) -> impl Copy + 'a { x }
16 //~^ ERROR explicit lifetime required in the type of `x`
18 fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
20 fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug> { Box::new(x) }
22 fn elided4(x: &i32) -> Box<dyn Debug + 'static> { Box::new(x) }
24 fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) }
26 fn elided5(x: &i32) -> (Box<dyn Debug>, impl Debug) { (Box::new(x), x) }
27 //~^ ERROR lifetime may not live long enough
29 trait LifetimeTrait<'a> {}
30 impl<'a> LifetimeTrait<'a> for &'a i32 {}
32 fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
33 //~^ ERROR lifetime may not live long enough
35 // Tests that a closure type containing 'b cannot be returned from a type where
36 // only 'a was expected.
37 fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) {
38 move |_| println!("{}", y)
39 //~^ ERROR: captures lifetime that does not appear in bounds
42 fn ty_param_wont_outlive_static<T:Debug>(x: T) -> impl Debug + 'static {
44 //~^ ERROR the parameter type `T` may not live long enough