]> git.lizzy.rs Git - rust.git/blob - src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr
Rollup merge of #95352 - jyn514:full-relative-path, r=Mark-Simulacrum
[rust.git] / src / test / ui / impl-trait / must_outlive_least_region_or_bound.stderr
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
3    |
4 LL | fn elided(x: &i32) -> impl Copy { x }
5    |              ----                 ^
6    |              |
7    |              hidden type `&i32` captures the anonymous lifetime defined here
8    |
9 help: to declare that the `impl Trait` captures `'_`, you can add an explicit `'_` lifetime bound
10    |
11 LL | fn elided(x: &i32) -> impl Copy + '_ { x }
12    |                                 ++++
13
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
16    |
17 LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
18    |             --                             ^
19    |             |
20    |             hidden type `&'a i32` captures the lifetime `'a` as defined here
21    |
22 help: to declare that the `impl Trait` captures `'a`, you can add an explicit `'a` lifetime bound
23    |
24 LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x }
25    |                                          ++++
26
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
29    |
30 LL | fn elided2(x: &i32) -> impl Copy + 'static { x }
31    |               ----                           ^ ...is used here...
32    |               |
33    |               this data with an anonymous lifetime `'_`...
34    |
35 note: ...and is required to live as long as `'static` here
36   --> $DIR/must_outlive_least_region_or_bound.rs:9:24
37    |
38 LL | fn elided2(x: &i32) -> impl Copy + 'static { x }
39    |                        ^^^^^^^^^^^^^^^^^^^
40 help: consider changing the `impl Trait`'s explicit `'static` bound to the lifetime of argument `x`
41    |
42 LL | fn elided2(x: &i32) -> impl Copy + '_ { x }
43    |                                    ~~
44 help: alternatively, add an explicit `'static` bound to this reference
45    |
46 LL | fn elided2(x: &'static i32) -> impl Copy + 'static { x }
47    |               ~~~~~~~~~~~~
48
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
51    |
52 LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
53    |                     -------                           ^ ...is used here...
54    |                     |
55    |                     this data with lifetime `'a`...
56    |
57 note: ...and is required to live as long as `'static` here
58   --> $DIR/must_outlive_least_region_or_bound.rs:11:33
59    |
60 LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
61    |                                 ^^^^^^^^^^^^^^^^^^^
62 help: consider changing the `impl Trait`'s explicit `'static` bound to the lifetime of argument `x`
63    |
64 LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'a { x }
65    |                                             ~~
66 help: alternatively, add an explicit `'static` bound to this reference
67    |
68 LL | fn explicit2<'a>(x: &'static i32) -> impl Copy + 'static { x }
69    |                     ~~~~~~~~~~~~
70
71 error[E0621]: explicit lifetime required in the type of `x`
72   --> $DIR/must_outlive_least_region_or_bound.rs:13:24
73    |
74 LL | fn foo<'a>(x: &i32) -> impl Copy + 'a { x }
75    |               ----     ^^^^^^^^^^^^^^ lifetime `'a` required
76    |               |
77    |               help: add explicit lifetime `'a` to the type of `x`: `&'a i32`
78
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
81    |
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
84    |
85 help: to declare that the trait object captures data from argument `x`, you can add an explicit `'_` lifetime bound
86    |
87 LL | fn elided5(x: &i32) -> (Box<dyn Debug + '_>, impl Debug) { (Box::new(x), x) }
88    |                                       ++++
89 help: to declare that the `impl Trait` captures data from argument `x`, you can add an explicit `'_` lifetime bound
90    |
91 LL | fn elided5(x: &i32) -> (Box<dyn Debug>, impl Debug + '_) { (Box::new(x), x) }
92    |                                                    ++++
93
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
96    |
97 LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
98    |                      ------- this data with lifetime `'a`...        ^ ...is used here...
99    |
100 note: ...and is required to live as long as `'static` here
101   --> $DIR/must_outlive_least_region_or_bound.rs:29:34
102    |
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`
106    |
107 LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'a { x }
108    |                                                           ~~
109 help: alternatively, add an explicit `'static` bound to this reference
110    |
111 LL | fn with_bound<'a>(x: &'static i32) -> impl LifetimeTrait<'a> + 'static { x }
112    |                      ~~~~~~~~~~~~
113
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
116    |
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    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
121    |
122 help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound
123    |
124 LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) + 'b {
125    |                                                                              ++++
126
127 error[E0310]: the parameter type `T` may not live long enough
128   --> $DIR/must_outlive_least_region_or_bound.rs:38:51
129    |
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
132    |                                 |
133    |                                 help: consider adding an explicit lifetime bound...: `T: 'static +`
134
135 error[E0310]: the parameter type `T` may not live long enough
136   --> $DIR/must_outlive_least_region_or_bound.rs:38:72
137    |
138 LL |   fn ty_param_wont_outlive_static<T:Debug>(x: T) -> impl Debug + 'static {
139    |  _________________________________--_____________________________________^
140    | |                                 |
141    | |                                 help: consider adding an explicit lifetime bound...: `T: 'static +`
142 LL | |
143 LL | |
144 LL | |     x
145 LL | | }
146    | |_^ ...so that the type `T` will meet its required lifetime bounds
147
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
150    |
151 LL | fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
152    |               ----                               ^ ...is used and required to live as long as `'static` here
153    |               |
154    |               this data with an anonymous lifetime `'_`...
155    |
156 note: `'static` lifetime requirement introduced by the return type
157   --> $DIR/must_outlive_least_region_or_bound.rs:16:28
158    |
159 LL | fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
160    |                            ^^^^^^^^^    ----------- because of this returned expression
161    |                            |
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
164    |
165 LL | fn elided3(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
166    |                                      ++++
167
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
170    |
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
173    |                     |
174    |                     this data with lifetime `'a`...
175    |
176 note: `'static` lifetime requirement introduced by the return type
177   --> $DIR/must_outlive_least_region_or_bound.rs:18:37
178    |
179 LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug> { Box::new(x) }
180    |                                     ^^^^^^^^^    ----------- because of this returned expression
181    |                                     |
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
184    |
185 LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
186    |                                               ++++
187
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
190    |
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
193    |               |
194    |               this data with an anonymous lifetime `'_`...
195    |
196 note: `'static` lifetime requirement introduced by the return type
197   --> $DIR/must_outlive_least_region_or_bound.rs:20:40
198    |
199 LL | fn elided4(x: &i32) -> Box<dyn Debug + 'static> { Box::new(x) }
200    |                                        ^^^^^^^    ----------- because of this returned expression
201    |                                        |
202    |                                        `'static` requirement introduced here
203 help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `x`
204    |
205 LL | fn elided4(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
206    |                                        ~~
207 help: alternatively, add an explicit `'static` bound to this reference
208    |
209 LL | fn elided4(x: &'static i32) -> Box<dyn Debug + 'static> { Box::new(x) }
210    |               ~~~~~~~~~~~~
211
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
214    |
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
217    |
218 note: `'static` lifetime requirement introduced by the return type
219   --> $DIR/must_outlive_least_region_or_bound.rs:22:49
220    |
221 LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) }
222    |                                                 ^^^^^^^    ----------- because of this returned expression
223    |                                                 |
224    |                                                 `'static` requirement introduced here
225 help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `x`
226    |
227 LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
228    |                                                 ~~
229 help: alternatively, add an explicit `'static` bound to this reference
230    |
231 LL | fn explicit4<'a>(x: &'static i32) -> Box<dyn Debug + 'static> { Box::new(x) }
232    |                     ~~~~~~~~~~~~
233
234 error: aborting due to 14 previous errors
235
236 Some errors have detailed explanations: E0310, E0621, E0700, E0759.
237 For more information about an error, try `rustc --explain E0310`.