Skip to content

Lifetime may not live enough regression #122230

Closed
@iamsauravsharma

Description

@iamsauravsharma

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-borrow-checkerArea: The borrow checkerA-lifetimesArea: Lifetimes / regionsC-discussionCategory: Discussion or questions that doesn't represent real issues.S-waiting-on-reviewStatus: Awaiting review from the assignee but also interested parties.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions