1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![feature(conservative_impl_trait)]
16 fn any_lifetime<'a>() -> &'a u32 { &5 }
18 fn static_lifetime() -> &'static u32 { &5 }
20 fn any_lifetime_as_static_impl_trait() -> impl Debug {
24 fn lifetimes_as_static_impl_trait() -> impl Debug {
28 fn no_params_or_lifetimes_is_static() -> impl Debug + 'static {
29 lifetimes_as_static_impl_trait()
32 fn static_input_type_is_static<T: Debug + 'static>(x: T) -> impl Debug + 'static { x }
34 fn type_outlives_reference_lifetime<'a, T: Debug>(x: &'a T) -> impl Debug + 'a { x }
36 trait SingleRegionTrait<'a> {}
37 impl<'a> SingleRegionTrait<'a> for u32 {}
39 fn simple_type_hrtb<'b>() -> impl for<'a> SingleRegionTrait<'a> { 5 }
40 fn closure_hrtb() -> impl for<'a> Fn(&'a u32) { |_| () }
42 fn mixed_lifetimes<'a>() -> impl for<'b: 'a> Fn(&'b u32) { |_| () }
43 fn mixed_as_static() -> impl Fn(&'static u32) { mixed_lifetimes() }
45 trait MultiRegionTrait<'a, 'b>: Debug {}
48 struct MultiRegionStruct<'a, 'b>(&'a u32, &'b u32);
49 impl<'a, 'b> MultiRegionTrait<'a, 'b> for MultiRegionStruct<'a, 'b> {}
52 struct NoRegionStruct;
53 impl<'a, 'b> MultiRegionTrait<'a, 'b> for NoRegionStruct {}
55 fn finds_least_region<'a: 'b, 'b>(x: &'a u32, y: &'b u32) -> impl MultiRegionTrait<'a, 'b> {
56 MultiRegionStruct(x, y)
59 fn finds_explicit_bound<'a: 'b, 'b>
60 (x: &'a u32, y: &'b u32) -> impl MultiRegionTrait<'a, 'b> + 'b
62 MultiRegionStruct(x, y)
65 fn finds_explicit_bound_even_without_least_region<'a, 'b>
66 (x: &'a u32, y: &'b u32) -> impl MultiRegionTrait<'a, 'b> + 'b
71 /* FIXME: `impl Trait<'a> + 'b` should live as long as 'b, even if 'b outlives 'a
72 fn outlives_bounds_even_with_contained_regions<'a, 'b>
73 (x: &'a u32, y: &'b u32) -> impl Debug + 'b
75 finds_explicit_bound_even_without_least_region(x, y)
79 fn unnamed_lifetimes_arent_contained_in_impl_trait_and_will_unify<'a, 'b>
80 (x: &'a u32, y: &'b u32) -> impl Debug
82 fn deref<'lt>(x: &'lt u32) -> impl Debug { *x }
84 if true { deref(x) } else { deref(y) }
87 fn can_add_region_bound_to_static_type<'a, 'b>(_: &'a u32) -> impl Debug + 'a { 5 }
89 struct MyVec(Vec<Vec<u8>>);
91 impl<'unnecessary_lifetime> MyVec {
92 fn iter_doesnt_capture_unnecessary_lifetime<'s>(&'s self) -> impl Iterator<Item = &'s u8> {
93 self.0.iter().flat_map(|inner_vec| inner_vec.iter())