Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lifetime may not live enough regression #122230

Closed
Tracked by #122502
iamsauravsharma opened this issue Mar 9, 2024 · 15 comments
Closed
Tracked by #122502

Lifetime may not live enough regression #122230

iamsauravsharma opened this issue Mar 9, 2024 · 15 comments
Labels
A-borrow-checker Area: The borrow checker A-lifetimes Area: Lifetimes / regions C-discussion Category: Discussion or questions that doesn't represent real issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@iamsauravsharma
Copy link

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

@iamsauravsharma iamsauravsharma added the C-bug Category: This is a bug. label Mar 9, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 9, 2024
@lqd
Copy link
Member

lqd commented Mar 9, 2024

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

@fmease fmease added A-lifetimes Area: Lifetimes / regions A-borrow-checker Area: The borrow checker T-types Relevant to the types team, which will review and decide on the PR/issue. C-discussion Category: Discussion or questions that doesn't represent real issues. and removed C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 9, 2024
@oli-obk
Copy link
Contributor

oli-obk commented Mar 10, 2024

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

@oli-obk

This comment was marked as resolved.

@craterbot

This comment was marked as resolved.

@oli-obk
Copy link
Contributor

oli-obk commented Mar 10, 2024

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

@craterbot
Copy link
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

@craterbot craterbot added the S-waiting-on-crater Status: Waiting on a crater run to be completed. label Mar 10, 2024
@iamsauravsharma
Copy link
Author

iamsauravsharma commented Mar 10, 2024

No problem, I noticed this issue only in one of the recently released updates of third-party crates that I've been using. I've already created PR for fix, cedar-policy/cedar#712, for it.

@compiler-errors compiler-errors mentioned this issue Mar 14, 2024
4 tasks
@craterbot
Copy link
Collaborator

🚧 Experiment opaque-soundness-fix is now running

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

@Mark-Simulacrum
Copy link
Member

@craterbot abort

@craterbot
Copy link
Collaborator

🗑️ Experiment opaque-soundness-fix deleted!

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

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Mar 18, 2024
@Mark-Simulacrum
Copy link
Member

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

@craterbot
Copy link
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

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 18, 2024
@craterbot
Copy link
Collaborator

🚧 Experiment opaque-soundness-fix is now running

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

@craterbot
Copy link
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

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Mar 24, 2024
@oli-obk
Copy link
Contributor

oli-obk commented Mar 25, 2024

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

@oli-obk oli-obk closed this as completed Mar 25, 2024
bors added a commit to rust-lang/crater that referenced this issue Mar 31, 2024
Forbid unprefixed SHAs for toolchains

This PR forbids unprefixed SHAs for toolchain arguments, to avoid crater hanging when they appear.

I'm not sure this is fully valid though: I don't know if SHAs could appear in a `Toolchain`'s name (and `RustwideToolchain::dist()`) without being an error 😓. This commonly happens with `rustup-toolchain-install-master` but I don't know if a similar situation could arise within common crater usage.

CI will surely fail: some of the used dependencies are broken on nightly right now, and clippy emits warnings -- both issues are fixed in #722.

<sub>(this is [for](rust-lang/rust#122230 (comment)) `@oli-obk` and [for](rust-lang/rust#122502 (comment)) `@compiler-errors)</sub>`
bors added a commit to rust-lang/crater that referenced this issue Mar 31, 2024
Forbid unprefixed SHAs for toolchains

This PR forbids unprefixed SHAs for toolchain arguments, to avoid crater hanging when they appear.

I'm not sure this is fully valid though: I don't know if SHAs could appear in a `Toolchain`'s name (and `RustwideToolchain::dist()`) without being an error 😓. This commonly happens with `rustup-toolchain-install-master` but I don't know if a similar situation could arise within common crater usage.

CI will surely fail: some of the used dependencies are broken on nightly right now, and clippy emits warnings -- both issues are fixed in #722.

<sub>(this is [for](rust-lang/rust#122230 (comment)) `@oli-obk` and [for](rust-lang/rust#122502 (comment)) `@compiler-errors)</sub>`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-borrow-checker Area: The borrow checker A-lifetimes Area: Lifetimes / regions C-discussion Category: Discussion or questions that doesn't represent real issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants