Skip to content

Lifetime may not live enough regression #122230

Closed

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

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Mar 9, 2024
  2. lqd commented on Mar 9, 2024

    @lqd
    Member

    I believe this should be due to the soundness fix in #121679.

  3. added
    A-lifetimesArea: Lifetimes / regions
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    C-discussionCategory: Discussion or questions that doesn't represent real issues.
    and removed
    C-bugCategory: This is a bug.
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Mar 9, 2024
  4. oli-obk commented on Mar 10, 2024

    @oli-obk
    Contributor

    Yes, that PR was a follow up to #115008 (comment)

    Your code example can be used unsoundly, even if a smarter analysis could infer the right lifetimes.

    We should have cratered the change and opened a fix PR against your repo, apologies about the unannounced breakage. I'll start a crater run now

  5. oli-obk commented on Mar 10, 2024

    @oli-obk
  6. craterbot commented on Mar 10, 2024

    @craterbot
  7. oli-obk commented on Mar 10, 2024

    @oli-obk
    Contributor

    @craterbot run name=opaque-soundness-fix start=80399064afa4a2cd153f30d02c25f7ea0383ed65 end=09bc67b9158392361780e779d32997f14cc75c39 mode=check-only

  8. craterbot commented on Mar 10, 2024

    @craterbot
    Collaborator

    👌 Experiment opaque-soundness-fix created and queued.
    🔍 You can check out the queue and this experiment's details.

    ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

  9. 3 remaining items

  10. craterbot commented on Mar 18, 2024

    @craterbot
    Collaborator

    🗑️ Experiment opaque-soundness-fix deleted!

    ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

  11. added
    S-waiting-on-reviewStatus: Awaiting review from the assignee but also interested parties.
    and removed
    S-waiting-on-craterStatus: Waiting on a crater run to be completed.
    on Mar 18, 2024
  12. Mark-Simulacrum commented on Mar 18, 2024

    @Mark-Simulacrum
    Member

    @craterbot run name=opaque-soundness-fix start=master#80399064afa4a2cd153f30d02c25f7ea0383ed65 end=master#09bc67b9158392361780e779d32997f14cc75c39 mode=check-only

  13. craterbot commented on Mar 18, 2024

    @craterbot
    Collaborator

    👌 Experiment opaque-soundness-fix created and queued.
    🔍 You can check out the queue and this experiment's details.

    ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

  14. added
    S-waiting-on-craterStatus: Waiting on a crater run to be completed.
    and removed
    S-waiting-on-reviewStatus: Awaiting review from the assignee but also interested parties.
    on Mar 18, 2024
  15. craterbot commented on Mar 23, 2024

    @craterbot
    Collaborator

    🚧 Experiment opaque-soundness-fix is now running

    ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

  16. craterbot commented on Mar 24, 2024

    @craterbot
    Collaborator

    🎉 Experiment opaque-soundness-fix is completed!
    📊 9 regressed and 1 fixed (428380 total)
    📰 Open the full report.

    ⚠️ If you notice any spurious failure please add them to the blacklist!
    ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

  17. added
    S-waiting-on-reviewStatus: Awaiting review from the assignee but also interested parties.
    and removed
    S-waiting-on-craterStatus: Waiting on a crater run to be completed.
    on Mar 24, 2024
  18. oli-obk commented on Mar 25, 2024

    @oli-obk
    Contributor

    I opened PRs against all affected crates. The original reporter's crate did not show up since it was already fixed before crater started running

  19. added 2 commits that reference this issue on Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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