4 #![feature(generators)]
8 fn any_lifetime<'a>() -> &'a u32 { &5 }
10 fn static_lifetime() -> &'static u32 { &5 }
12 fn any_lifetime_as_static_impl_trait() -> impl Debug {
16 fn lifetimes_as_static_impl_trait() -> impl Debug {
20 fn no_params_or_lifetimes_is_static() -> impl Debug + 'static {
21 lifetimes_as_static_impl_trait()
24 fn static_input_type_is_static<T: Debug + 'static>(x: T) -> impl Debug + 'static { x }
26 fn type_outlives_reference_lifetime<'a, T: Debug>(x: &'a T) -> impl Debug + 'a { x }
27 fn type_outlives_reference_lifetime_elided<T: Debug>(x: &T) -> impl Debug + '_ { x }
29 trait SingleRegionTrait<'a> {}
30 impl<'a> SingleRegionTrait<'a> for u32 {}
31 impl<'a> SingleRegionTrait<'a> for &'a u32 {}
32 struct SingleRegionStruct<'a>(&'a u32);
34 fn simple_type_hrtb<'b>() -> impl for<'a> SingleRegionTrait<'a> { 5 }
35 fn elision_single_region_trait(x: &u32) -> impl SingleRegionTrait { x }
36 fn elision_single_region_struct(x: SingleRegionStruct) -> impl Into<SingleRegionStruct> { x }
38 fn closure_hrtb() -> impl for<'a> Fn(&'a u32) { |_| () }
39 fn closure_hr_elided() -> impl Fn(&u32) { |_| () }
40 fn closure_hr_elided_return() -> impl Fn(&u32) -> &u32 { |x| x }
41 fn closure_pass_through_elided_return(x: impl Fn(&u32) -> &u32) -> impl Fn(&u32) -> &u32 { x }
42 fn closure_pass_through_reference_elided(x: &impl Fn(&u32) -> &u32) -> &impl Fn(&u32) -> &u32 { x }
44 fn nested_lifetime<'a>(input: &'a str)
45 -> impl Iterator<Item = impl Iterator<Item = i32> + 'a> + 'a
47 input.lines().map(|line| {
48 line.split_whitespace().map(|cell| cell.parse().unwrap())
52 fn pass_through_elision(x: &u32) -> impl Into<&u32> { x }
53 fn pass_through_elision_with_fn_ptr(x: &fn(&u32) -> &u32) -> impl Into<&fn(&u32) -> &u32> { x }
55 fn pass_through_elision_with_fn_path<T: Fn(&u32) -> &u32>(
57 ) -> &impl Fn(&u32) -> &u32 { x }
59 fn foo(x: &impl Debug) -> &impl Debug { x }
60 fn foo_explicit_lifetime<'a>(x: &'a impl Debug) -> &'a impl Debug { x }
61 fn foo_explicit_arg<T: Debug>(x: &T) -> &impl Debug { x }
63 fn mixed_lifetimes<'a>() -> impl for<'b> Fn(&'b &'a u32) { |_| () }
64 fn mixed_as_static() -> impl Fn(&'static &'static u32) { mixed_lifetimes() }
66 trait MultiRegionTrait<'a, 'b>: Debug {}
69 struct MultiRegionStruct<'a, 'b>(&'a u32, &'b u32);
70 impl<'a, 'b> MultiRegionTrait<'a, 'b> for MultiRegionStruct<'a, 'b> {}
73 struct NoRegionStruct;
74 impl<'a, 'b> MultiRegionTrait<'a, 'b> for NoRegionStruct {}
76 fn finds_least_region<'a: 'b, 'b>(x: &'a u32, y: &'b u32) -> impl MultiRegionTrait<'a, 'b> {
77 MultiRegionStruct(x, y)
80 fn finds_explicit_bound<'a: 'b, 'b>
81 (x: &'a u32, y: &'b u32) -> impl MultiRegionTrait<'a, 'b> + 'b
83 MultiRegionStruct(x, y)
86 fn finds_explicit_bound_even_without_least_region<'a, 'b>
87 (x: &'a u32, y: &'b u32) -> impl MultiRegionTrait<'a, 'b> + 'b
92 /* FIXME: `impl Trait<'a> + 'b` should live as long as 'b, even if 'b outlives 'a
93 fn outlives_bounds_even_with_contained_regions<'a, 'b>
94 (x: &'a u32, y: &'b u32) -> impl Debug + 'b
96 finds_explicit_bound_even_without_least_region(x, y)
100 fn unnamed_lifetimes_arent_contained_in_impl_trait_and_will_unify<'a, 'b>
101 (x: &'a u32, y: &'b u32) -> impl Debug
103 fn deref<'lt>(x: &'lt u32) -> impl Debug { *x }
105 if true { deref(x) } else { deref(y) }
108 fn can_add_region_bound_to_static_type<'a, 'b>(_: &'a u32) -> impl Debug + 'a { 5 }
110 struct MyVec(Vec<Vec<u8>>);
112 impl<'unnecessary_lifetime> MyVec {
113 fn iter_doesnt_capture_unnecessary_lifetime<'s>(&'s self) -> impl Iterator<Item = &'s u8> {
114 self.0.iter().flat_map(|inner_vec| inner_vec.iter())
117 fn generator_doesnt_capture_unnecessary_lifetime<'s: 's>() -> impl Sized {