-error: cannot infer an appropriate lifetime
+error[E0759]: cannot infer an appropriate lifetime
--> $DIR/static-return-lifetime-infered.rs:7:16
|
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> {
- | ----- ----------------------- ...is required to be `'static` by this...
- | |
- | data with this lifetime...
+ | ----- this data with an anonymous lifetime `'_`...
LL | self.x.iter().map(|a| a.0)
| ------ ^^^^
| |
- | ...and is captured here
+ | ...is captured here...
|
-help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for the anonymous lifetime #1 defined on the method body at 6:5
+note: ...and is required to live as long as `'static` here
+ --> $DIR/static-return-lifetime-infered.rs:6:35
+ |
+LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+help: to declare that the `impl Trait` captures data from argument `self`, you can add an explicit `'_` lifetime bound
|
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> + '_ {
| ^^^^
-error: cannot infer an appropriate lifetime
+error[E0759]: cannot infer an appropriate lifetime
--> $DIR/static-return-lifetime-infered.rs:11:16
|
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
- | -------- ----------------------- ...is required to be `'static` by this...
- | |
- | data with this lifetime...
+ | -------- this data with lifetime `'a`...
LL | self.x.iter().map(|a| a.0)
| ------ ^^^^
| |
- | ...and is captured here
+ | ...is captured here...
|
-help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for the lifetime `'a` as defined on the method body at 10:20
+note: ...and is required to live as long as `'static` here
+ --> $DIR/static-return-lifetime-infered.rs:10:37
+ |
+LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+help: to declare that the `impl Trait` captures data from argument `self`, you can add an explicit `'a` lifetime bound
|
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> + 'a {
| ^^^^
error: aborting due to 2 previous errors
+For more information about this error, try `rustc --explain E0759`.