1 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
2 --> $DIR/must_outlive_least_region_or_bound.rs:3:23
4 LL | fn elided(x: &i32) -> impl Copy { x }
7 | hidden type `&i32` captures the anonymous lifetime defined here
9 help: to declare that the `impl Trait` captures `'_`, you can add an explicit `'_` lifetime bound
11 LL | fn elided(x: &i32) -> impl Copy + '_ { x }
14 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
15 --> $DIR/must_outlive_least_region_or_bound.rs:6:32
17 LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
20 | hidden type `&'a i32` captures the lifetime `'a` as defined here
22 help: to declare that the `impl Trait` captures `'a`, you can add an explicit `'a` lifetime bound
24 LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x }
27 error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
28 --> $DIR/must_outlive_least_region_or_bound.rs:9:46
30 LL | fn elided2(x: &i32) -> impl Copy + 'static { x }
31 | ---- ^ ...is used here...
33 | this data with an anonymous lifetime `'_`...
35 note: ...and is required to live as long as `'static` here
36 --> $DIR/must_outlive_least_region_or_bound.rs:9:24
38 LL | fn elided2(x: &i32) -> impl Copy + 'static { x }
40 help: consider changing the `impl Trait`'s explicit `'static` bound to the lifetime of argument `x`
42 LL | fn elided2(x: &i32) -> impl Copy + '_ { x }
44 help: alternatively, add an explicit `'static` bound to this reference
46 LL | fn elided2(x: &'static i32) -> impl Copy + 'static { x }
49 error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
50 --> $DIR/must_outlive_least_region_or_bound.rs:11:55
52 LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
53 | ------- ^ ...is used here...
55 | this data with lifetime `'a`...
57 note: ...and is required to live as long as `'static` here
58 --> $DIR/must_outlive_least_region_or_bound.rs:11:33
60 LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
62 help: consider changing the `impl Trait`'s explicit `'static` bound to the lifetime of argument `x`
64 LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'a { x }
66 help: alternatively, add an explicit `'static` bound to this reference
68 LL | fn explicit2<'a>(x: &'static i32) -> impl Copy + 'static { x }
71 error[E0621]: explicit lifetime required in the type of `x`
72 --> $DIR/must_outlive_least_region_or_bound.rs:13:24
74 LL | fn foo<'a>(x: &i32) -> impl Copy + 'a { x }
75 | ---- ^^^^^^^^^^^^^^ lifetime `'a` required
77 | help: add explicit lifetime `'a` to the type of `x`: `&'a i32`
79 error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
80 --> $DIR/must_outlive_least_region_or_bound.rs:24:65
82 LL | fn elided5(x: &i32) -> (Box<dyn Debug>, impl Debug) { (Box::new(x), x) }
83 | ---- this data with an anonymous lifetime `'_`... ^ ...is used and required to live as long as `'static` here
85 help: to declare that the trait object captures data from argument `x`, you can add an explicit `'_` lifetime bound
87 LL | fn elided5(x: &i32) -> (Box<dyn Debug + '_>, impl Debug) { (Box::new(x), x) }
89 help: to declare that the `impl Trait` captures data from argument `x`, you can add an explicit `'_` lifetime bound
91 LL | fn elided5(x: &i32) -> (Box<dyn Debug>, impl Debug + '_) { (Box::new(x), x) }
94 error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
95 --> $DIR/must_outlive_least_region_or_bound.rs:29:69
97 LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
98 | ------- this data with lifetime `'a`... ^ ...is used here...
100 note: ...and is required to live as long as `'static` here
101 --> $DIR/must_outlive_least_region_or_bound.rs:29:34
103 LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
104 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
105 help: consider changing the `impl Trait`'s explicit `'static` bound to the lifetime of argument `x`
107 LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'a { x }
109 help: alternatively, add an explicit `'static` bound to this reference
111 LL | fn with_bound<'a>(x: &'static i32) -> impl LifetimeTrait<'a> + 'static { x }
114 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
115 --> $DIR/must_outlive_least_region_or_bound.rs:33:61
117 LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) {
118 | -- ^^^^^^^^^^^^^^^^
120 | hidden type `[closure@$DIR/must_outlive_least_region_or_bound.rs:35:5: 35:31]` captures the lifetime `'b` as defined here
122 help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound
124 LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) + 'b {
127 error[E0310]: the parameter type `T` may not live long enough
128 --> $DIR/must_outlive_least_region_or_bound.rs:38:51
130 LL | fn ty_param_wont_outlive_static<T:Debug>(x: T) -> impl Debug + 'static {
131 | -- ^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
133 | help: consider adding an explicit lifetime bound...: `T: 'static +`
135 error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
136 --> $DIR/must_outlive_least_region_or_bound.rs:16:50
138 LL | fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
139 | ---- ^ ...is used and required to live as long as `'static` here
141 | this data with an anonymous lifetime `'_`...
143 note: `'static` lifetime requirement introduced by the return type
144 --> $DIR/must_outlive_least_region_or_bound.rs:16:28
146 LL | fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
147 | ^^^^^^^^^ ----------- because of this returned expression
149 | `'static` requirement introduced here
150 help: to declare that the trait object captures data from argument `x`, you can add an explicit `'_` lifetime bound
152 LL | fn elided3(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
155 error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
156 --> $DIR/must_outlive_least_region_or_bound.rs:18:59
158 LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug> { Box::new(x) }
159 | ------- ^ ...is used and required to live as long as `'static` here
161 | this data with lifetime `'a`...
163 note: `'static` lifetime requirement introduced by the return type
164 --> $DIR/must_outlive_least_region_or_bound.rs:18:37
166 LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug> { Box::new(x) }
167 | ^^^^^^^^^ ----------- because of this returned expression
169 | `'static` requirement introduced here
170 help: to declare that the trait object captures data from argument `x`, you can add an explicit `'a` lifetime bound
172 LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
175 error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
176 --> $DIR/must_outlive_least_region_or_bound.rs:20:60
178 LL | fn elided4(x: &i32) -> Box<dyn Debug + 'static> { Box::new(x) }
179 | ---- ^ ...is used and required to live as long as `'static` here
181 | this data with an anonymous lifetime `'_`...
183 note: `'static` lifetime requirement introduced by the return type
184 --> $DIR/must_outlive_least_region_or_bound.rs:20:40
186 LL | fn elided4(x: &i32) -> Box<dyn Debug + 'static> { Box::new(x) }
187 | ^^^^^^^ ----------- because of this returned expression
189 | `'static` requirement introduced here
190 help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `x`
192 LL | fn elided4(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
194 help: alternatively, add an explicit `'static` bound to this reference
196 LL | fn elided4(x: &'static i32) -> Box<dyn Debug + 'static> { Box::new(x) }
199 error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
200 --> $DIR/must_outlive_least_region_or_bound.rs:22:69
202 LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) }
203 | ------- this data with lifetime `'a`... ^ ...is used and required to live as long as `'static` here
205 note: `'static` lifetime requirement introduced by the return type
206 --> $DIR/must_outlive_least_region_or_bound.rs:22:49
208 LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) }
209 | ^^^^^^^ ----------- because of this returned expression
211 | `'static` requirement introduced here
212 help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `x`
214 LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
216 help: alternatively, add an explicit `'static` bound to this reference
218 LL | fn explicit4<'a>(x: &'static i32) -> Box<dyn Debug + 'static> { Box::new(x) }
221 error: aborting due to 13 previous errors
223 Some errors have detailed explanations: E0310, E0621, E0700, E0759.
224 For more information about an error, try `rustc --explain E0310`.