]> git.lizzy.rs Git - rust.git/blob - src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr
e1fa4f02b6fcf770f2585118eae9c58c507983f4
[rust.git] / src / test / ui / impl-trait / must_outlive_least_region_or_bound.stderr
1 error[E0759]: cannot infer an appropriate lifetime
2   --> $DIR/must_outlive_least_region_or_bound.rs:3:35
3    |
4 LL | fn elided(x: &i32) -> impl Copy { x }
5    |              ----                 ^ ...is captured here...
6    |              |
7    |              this data with an anonymous lifetime `'_`...
8    |
9 note: ...and is required to live as long as `'static` here
10   --> $DIR/must_outlive_least_region_or_bound.rs:3:23
11    |
12 LL | fn elided(x: &i32) -> impl Copy { x }
13    |                       ^^^^^^^^^
14 help: to declare that the `impl Trait` captures data from argument `x`, you can add an explicit `'_` lifetime bound
15    |
16 LL | fn elided(x: &i32) -> impl Copy + '_ { x }
17    |                                 ^^^^
18
19 error[E0759]: cannot infer an appropriate lifetime
20   --> $DIR/must_outlive_least_region_or_bound.rs:6:44
21    |
22 LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
23    |                    -------                 ^ ...is captured here...
24    |                    |
25    |                    this data with lifetime `'a`...
26    |
27 note: ...and is required to live as long as `'static` here
28   --> $DIR/must_outlive_least_region_or_bound.rs:6:32
29    |
30 LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
31    |                                ^^^^^^^^^
32 help: to declare that the `impl Trait` captures data from argument `x`, you can add an explicit `'a` lifetime bound
33    |
34 LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x }
35    |                                          ^^^^
36
37 error[E0759]: cannot infer an appropriate lifetime
38   --> $DIR/must_outlive_least_region_or_bound.rs:9:46
39    |
40 LL | fn elided2(x: &i32) -> impl Copy + 'static { x }
41    |               ----                           ^ ...is captured here...
42    |               |
43    |               this data with an anonymous lifetime `'_`...
44    |
45 note: ...and is required to live as long as `'static` here
46   --> $DIR/must_outlive_least_region_or_bound.rs:9:24
47    |
48 LL | fn elided2(x: &i32) -> impl Copy + 'static { x }
49    |                        ^^^^^^^^^^^^^^^^^^^
50 help: consider changing the `impl Trait`'s explicit `'static` bound to the lifetime of argument `x`
51    |
52 LL | fn elided2(x: &i32) -> impl Copy + '_ { x }
53    |                                    ^^
54 help: alternatively, add an explicit `'static` bound to this reference
55    |
56 LL | fn elided2(x: &'static i32) -> impl Copy + 'static { x }
57    |               ^^^^^^^^^^^^
58
59 error[E0759]: cannot infer an appropriate lifetime
60   --> $DIR/must_outlive_least_region_or_bound.rs:12:55
61    |
62 LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
63    |                     -------                           ^ ...is captured here...
64    |                     |
65    |                     this data with lifetime `'a`...
66    |
67 note: ...and is required to live as long as `'static` here
68   --> $DIR/must_outlive_least_region_or_bound.rs:12:33
69    |
70 LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
71    |                                 ^^^^^^^^^^^^^^^^^^^
72 help: consider changing the `impl Trait`'s explicit `'static` bound to the lifetime of argument `x`
73    |
74 LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'a { x }
75    |                                             ^^
76 help: alternatively, add an explicit `'static` bound to this reference
77    |
78 LL | fn explicit2<'a>(x: &'static i32) -> impl Copy + 'static { x }
79    |                     ^^^^^^^^^^^^
80
81 error[E0621]: explicit lifetime required in the type of `x`
82   --> $DIR/must_outlive_least_region_or_bound.rs:15:24
83    |
84 LL | fn foo<'a>(x: &i32) -> impl Copy + 'a { x }
85    |               ----     ^^^^^^^^^^^^^^ lifetime `'a` required
86    |               |
87    |               help: add explicit lifetime `'a` to the type of `x`: `&'a i32`
88
89 error[E0759]: cannot infer an appropriate lifetime
90   --> $DIR/must_outlive_least_region_or_bound.rs:33:69
91    |
92 LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
93    |                      ------- this data with lifetime `'a`...        ^ ...is captured here...
94    |
95 note: ...and is required to live as long as `'static` here
96   --> $DIR/must_outlive_least_region_or_bound.rs:33:34
97    |
98 LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
99    |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
100 help: consider changing the `impl Trait`'s explicit `'static` bound to the lifetime of argument `x`
101    |
102 LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'a { x }
103    |                                                           ^^
104 help: alternatively, add an explicit `'static` bound to this reference
105    |
106 LL | fn with_bound<'a>(x: &'static i32) -> impl LifetimeTrait<'a> + 'static { x }
107    |                      ^^^^^^^^^^^^
108
109 error[E0623]: lifetime mismatch
110   --> $DIR/must_outlive_least_region_or_bound.rs:38:61
111    |
112 LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) {
113    |                                                 -------     ^^^^^^^^^^^^^^^^
114    |                                                 |           |
115    |                                                 |           ...but data from `y` is returned here
116    |                                                 this parameter and the return type are declared with different lifetimes...
117
118 error[E0310]: the parameter type `T` may not live long enough
119   --> $DIR/must_outlive_least_region_or_bound.rs:43:51
120    |
121 LL | fn ty_param_wont_outlive_static<T:Debug>(x: T) -> impl Debug + 'static {
122    |                                 --                ^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
123    |                                 |
124    |                                 help: consider adding an explicit lifetime bound...: `T: 'static +`
125
126 error[E0759]: cannot infer an appropriate lifetime
127   --> $DIR/must_outlive_least_region_or_bound.rs:18:50
128    |
129 LL | fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
130    |               ----                               ^ ...is captured here, requiring it to live as long as `'static`
131    |               |
132    |               this data with an anonymous lifetime `'_`...
133    |
134 help: to declare that the trait object captures data from argument `x`, you can add an explicit `'_` lifetime bound
135    |
136 LL | fn elided3(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
137    |                                      ^^^^
138
139 error[E0759]: cannot infer an appropriate lifetime
140   --> $DIR/must_outlive_least_region_or_bound.rs:21:59
141    |
142 LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug> { Box::new(x) }
143    |                     -------                               ^ ...is captured here, requiring it to live as long as `'static`
144    |                     |
145    |                     this data with lifetime `'a`...
146    |
147 help: to declare that the trait object captures data from argument `x`, you can add an explicit `'a` lifetime bound
148    |
149 LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
150    |                                               ^^^^
151
152 error[E0759]: cannot infer an appropriate lifetime
153   --> $DIR/must_outlive_least_region_or_bound.rs:24:60
154    |
155 LL | fn elided4(x: &i32) -> Box<dyn Debug + 'static> { Box::new(x) }
156    |               ----                                         ^ ...is captured here, requiring it to live as long as `'static`
157    |               |
158    |               this data with an anonymous lifetime `'_`...
159    |
160 help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `x`
161    |
162 LL | fn elided4(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
163    |                                        ^^
164 help: alternatively, add an explicit `'static` bound to this reference
165    |
166 LL | fn elided4(x: &'static i32) -> Box<dyn Debug + 'static> { Box::new(x) }
167    |               ^^^^^^^^^^^^
168
169 error[E0759]: cannot infer an appropriate lifetime
170   --> $DIR/must_outlive_least_region_or_bound.rs:27:69
171    |
172 LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) }
173    |                     ------- this data with lifetime `'a`...         ^ ...is captured here, requiring it to live as long as `'static`
174    |
175 help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `x`
176    |
177 LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
178    |                                                 ^^
179 help: alternatively, add an explicit `'static` bound to this reference
180    |
181 LL | fn explicit4<'a>(x: &'static i32) -> Box<dyn Debug + 'static> { Box::new(x) }
182    |                     ^^^^^^^^^^^^
183
184 error: aborting due to 12 previous errors
185
186 Some errors have detailed explanations: E0310, E0621, E0623, E0759.
187 For more information about an error, try `rustc --explain E0310`.