File: must_outlive_least_region_or_bound.stderr

package info (click to toggle)
rustc 1.89.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 906,624 kB
  • sloc: xml: 158,148; python: 34,888; javascript: 19,595; sh: 19,221; ansic: 13,046; cpp: 7,144; asm: 4,376; makefile: 692; lisp: 174; sql: 15
file content (200 lines) | stat: -rw-r--r-- 9,158 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
error[E0700]: hidden type for `impl Copy` captures lifetime that does not appear in bounds
  --> $DIR/must_outlive_least_region_or_bound.rs:3:35
   |
LL | fn elided(x: &i32) -> impl Copy { x }
   |              ----     ---------   ^
   |              |        |
   |              |        opaque type defined here
   |              hidden type `&i32` captures the anonymous lifetime defined here
   |
help: add a `use<...>` bound to explicitly capture `'_`
   |
LL | fn elided(x: &i32) -> impl Copy + use<'_> { x }
   |                                 +++++++++

error[E0700]: hidden type for `impl Copy` captures lifetime that does not appear in bounds
  --> $DIR/must_outlive_least_region_or_bound.rs:6:44
   |
LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
   |             --                 ---------   ^
   |             |                  |
   |             |                  opaque type defined here
   |             hidden type `&'a i32` captures the lifetime `'a` as defined here
   |
help: add a `use<...>` bound to explicitly capture `'a`
   |
LL | fn explicit<'a>(x: &'a i32) -> impl Copy + use<'a> { x }
   |                                          +++++++++

error: lifetime may not live long enough
  --> $DIR/must_outlive_least_region_or_bound.rs:9:46
   |
LL | fn elided2(x: &i32) -> impl Copy + 'static { x }
   |               -                              ^ returning this value requires that `'1` must outlive `'static`
   |               |
   |               let's call the lifetime of this reference `'1`
   |
help: consider changing `impl Copy + 'static`'s explicit `'static` bound to the lifetime of argument `x`
   |
LL - fn elided2(x: &i32) -> impl Copy + 'static { x }
LL + fn elided2(x: &i32) -> impl Copy + '_ { x }
   |
help: alternatively, add an explicit `'static` bound to this reference
   |
LL | fn elided2(x: &'static i32) -> impl Copy + 'static { x }
   |                +++++++

error: lifetime may not live long enough
  --> $DIR/must_outlive_least_region_or_bound.rs:12:55
   |
LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
   |              -- lifetime `'a` defined here            ^ returning this value requires that `'a` must outlive `'static`
   |
help: consider changing `impl Copy + 'static`'s explicit `'static` bound to the lifetime of argument `x`
   |
LL - fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
LL + fn explicit2<'a>(x: &'a i32) -> impl Copy + 'a { x }
   |
help: alternatively, add an explicit `'static` bound to this reference
   |
LL - fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
LL + fn explicit2<'a>(x: &'static i32) -> impl Copy + 'static { x }
   |

error[E0621]: explicit lifetime required in the type of `x`
  --> $DIR/must_outlive_least_region_or_bound.rs:15:41
   |
LL | fn foo<'a>(x: &i32) -> impl Copy + 'a { x }
   |                                         ^ lifetime `'a` required
   |
help: add explicit lifetime `'a` to the type of `x`
   |
LL | fn foo<'a>(x: &'a i32) -> impl Copy + 'a { x }
   |                ++

error: lifetime may not live long enough
  --> $DIR/must_outlive_least_region_or_bound.rs:30:55
   |
LL | fn elided5(x: &i32) -> (Box<dyn Debug>, impl Debug) { (Box::new(x), x) }
   |               -                                       ^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'static`
   |               |
   |               let's call the lifetime of this reference `'1`
   |
help: to declare that the trait object captures data from argument `x`, you can add an explicit `'_` lifetime bound
   |
LL | fn elided5(x: &i32) -> (Box<dyn Debug + '_>, impl Debug) { (Box::new(x), x) }
   |                                       ++++
help: to declare that `impl Debug` captures data from argument `x`, you can add an explicit `'_` lifetime bound
   |
LL | fn elided5(x: &i32) -> (Box<dyn Debug>, impl Debug + '_) { (Box::new(x), x) }
   |                                                    ++++

error: lifetime may not live long enough
  --> $DIR/must_outlive_least_region_or_bound.rs:36:69
   |
LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
   |               -- lifetime `'a` defined here                         ^ returning this value requires that `'a` must outlive `'static`
   |
help: consider changing `impl LifetimeTrait<'a> + 'static`'s explicit `'static` bound to the lifetime of argument `x`
   |
LL - fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
LL + fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'a { x }
   |
help: alternatively, add an explicit `'static` bound to this reference
   |
LL - fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
LL + fn with_bound<'a>(x: &'static i32) -> impl LifetimeTrait<'a> + 'static { x }
   |

error[E0700]: hidden type for `impl Fn(&'a u32)` captures lifetime that does not appear in bounds
  --> $DIR/must_outlive_least_region_or_bound.rs:42:5
   |
LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) {
   |                              --                             ---------------- opaque type defined here
   |                              |
   |                              hidden type `{closure@$DIR/must_outlive_least_region_or_bound.rs:42:5: 42:13}` captures the lifetime `'b` as defined here
LL |     move |_| println!("{}", y)
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: add a `use<...>` bound to explicitly capture `'b`
   |
LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) + use<'a, 'b> {
   |                                                                              +++++++++++++

error[E0310]: the parameter type `T` may not live long enough
  --> $DIR/must_outlive_least_region_or_bound.rs:47:5
   |
LL |     x
   |     ^
   |     |
   |     the parameter type `T` must be valid for the static lifetime...
   |     ...so that the type `T` will meet its required lifetime bounds
   |
help: consider adding an explicit lifetime bound
   |
LL | fn ty_param_wont_outlive_static<T:Debug + 'static>(x: T) -> impl Debug + 'static {
   |                                         +++++++++

error: lifetime may not live long enough
  --> $DIR/must_outlive_least_region_or_bound.rs:18:41
   |
LL | fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
   |               -                         ^^^^^^^^^^^ returning this value requires that `'1` must outlive `'static`
   |               |
   |               let's call the lifetime of this reference `'1`
   |
help: to declare that the trait object captures data from argument `x`, you can add an explicit `'_` lifetime bound
   |
LL | fn elided3(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
   |                                      ++++

error: lifetime may not live long enough
  --> $DIR/must_outlive_least_region_or_bound.rs:21:50
   |
LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug> { Box::new(x) }
   |              -- lifetime `'a` defined here       ^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static`
   |
help: to declare that the trait object captures data from argument `x`, you can add an explicit `'a` lifetime bound
   |
LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
   |                                               ++++

error: lifetime may not live long enough
  --> $DIR/must_outlive_least_region_or_bound.rs:24:51
   |
LL | fn elided4(x: &i32) -> Box<dyn Debug + 'static> { Box::new(x) }
   |               -                                   ^^^^^^^^^^^ returning this value requires that `'1` must outlive `'static`
   |               |
   |               let's call the lifetime of this reference `'1`
   |
help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `x`
   |
LL - fn elided4(x: &i32) -> Box<dyn Debug + 'static> { Box::new(x) }
LL + fn elided4(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
   |
help: alternatively, add an explicit `'static` bound to this reference
   |
LL | fn elided4(x: &'static i32) -> Box<dyn Debug + 'static> { Box::new(x) }
   |                +++++++

error: lifetime may not live long enough
  --> $DIR/must_outlive_least_region_or_bound.rs:27:60
   |
LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) }
   |              -- lifetime `'a` defined here                 ^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static`
   |
help: consider changing the trait object's explicit `'static` bound to the lifetime of argument `x`
   |
LL - fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) }
LL + fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
   |
help: alternatively, add an explicit `'static` bound to this reference
   |
LL - fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) }
LL + fn explicit4<'a>(x: &'static i32) -> Box<dyn Debug + 'static> { Box::new(x) }
   |

error: aborting due to 13 previous errors

Some errors have detailed explanations: E0310, E0621, E0700.
For more information about an error, try `rustc --explain E0310`.