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:35
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:44
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:34:5
117 LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) {
118 | -- hidden type `[closure@$DIR/must_outlive_least_region_or_bound.rs:34:5: 34:31]` captures the lifetime `'b` as defined here
119 LL | move |_| println!("{}", y)
120 | ^^^^^^^^^^^^^^^^^^^^^^^^^^
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[E0310]: the parameter type `T` may not live long enough
136 --> $DIR/must_outlive_least_region_or_bound.rs:38:72
138 LL | fn ty_param_wont_outlive_static<T:Debug>(x: T) -> impl Debug + 'static {
139 | _________________________________--_____________________________________^
141 | | help: consider adding an explicit lifetime bound...: `T: 'static +`
146 | |_^ ...so that the type `T` will meet its required lifetime bounds
148 error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
149 --> $DIR/must_outlive_least_region_or_bound.rs:16:50
151 LL | fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
152 | ---- ^ ...is used and required to live as long as `'static` here
154 | this data with an anonymous lifetime `'_`...
156 note: `'static` lifetime requirement introduced by the return type
157 --> $DIR/must_outlive_least_region_or_bound.rs:16:28
159 LL | fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
160 | ^^^^^^^^^ ----------- because of this returned expression
162 | `'static` requirement introduced here
163 help: to declare that the trait object captures data from argument `x`, you can add an explicit `'_` lifetime bound
165 LL | fn elided3(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
168 error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
169 --> $DIR/must_outlive_least_region_or_bound.rs:18:59
171 LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug> { Box::new(x) }
172 | ------- ^ ...is used and required to live as long as `'static` here
174 | this data with lifetime `'a`...
176 note: `'static` lifetime requirement introduced by the return type
177 --> $DIR/must_outlive_least_region_or_bound.rs:18:37
179 LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug> { Box::new(x) }
180 | ^^^^^^^^^ ----------- because of this returned expression
182 | `'static` requirement introduced here
183 help: to declare that the trait object captures data from argument `x`, you can add an explicit `'a` lifetime bound
185 LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
188 error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
189 --> $DIR/must_outlive_least_region_or_bound.rs:20:60
191 LL | fn elided4(x: &i32) -> Box<dyn Debug + 'static> { Box::new(x) }
192 | ---- ^ ...is used and required to live as long as `'static` here
194 | this data with an anonymous lifetime `'_`...
196 note: `'static` lifetime requirement introduced by the return type
197 --> $DIR/must_outlive_least_region_or_bound.rs:20:40
199 LL | fn elided4(x: &i32) -> Box<dyn Debug + 'static> { Box::new(x) }
200 | ^^^^^^^ ----------- because of this returned expression
202 | `'static` requirement introduced here
203 help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `x`
205 LL | fn elided4(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
207 help: alternatively, add an explicit `'static` bound to this reference
209 LL | fn elided4(x: &'static i32) -> Box<dyn Debug + 'static> { Box::new(x) }
212 error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
213 --> $DIR/must_outlive_least_region_or_bound.rs:22:69
215 LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) }
216 | ------- this data with lifetime `'a`... ^ ...is used and required to live as long as `'static` here
218 note: `'static` lifetime requirement introduced by the return type
219 --> $DIR/must_outlive_least_region_or_bound.rs:22:49
221 LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) }
222 | ^^^^^^^ ----------- because of this returned expression
224 | `'static` requirement introduced here
225 help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `x`
227 LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
229 help: alternatively, add an explicit `'static` bound to this reference
231 LL | fn explicit4<'a>(x: &'static i32) -> Box<dyn Debug + 'static> { Box::new(x) }
234 error: aborting due to 14 previous errors
236 Some errors have detailed explanations: E0310, E0621, E0700, E0759.
237 For more information about an error, try `rustc --explain E0310`.