Closed
Description
Code
I tried this code:
struct Test {
field: Vec<&'static str>
}
impl Test {
fn field<'field>(&self) -> impl Iterator<Item = &&'field str> {
self.field.iter()
}
}
I expected to see this happen: no compilation error
Instead, this happened:
error: lifetime may not live long enough
--> src/lib.rs:21:9
|
20 | fn field<'field>(&self) -> impl Iterator<Item = &&'field str> {
| ------ - let's call the lifetime of this reference `'1`
| |
| lifetime `'field` defined here
21 | self.field.iter()
| ^^^^^^^^^^^^^^^^^ method was supposed to return data with lifetime `'1` but it is returning data with lifetime `'field`
error: could not compile `playground` (lib) due to 1 previous error
It most recently works on nightly-2024-03-06
but returns error on nightly-2024-03-07