Skip to content

Conversation

@ShoyuVanilla
Copy link
Member

@ShoyuVanilla ShoyuVanilla commented Nov 27, 2025

Fixes #115175
Fixes #148854

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 27, 2025
@ShoyuVanilla
Copy link
Member Author

@bors try

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Nov 27, 2025
WF check lifetime bounds for locals with type params
@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Nov 27, 2025

☀️ Try build successful (CI)
Build commit: 5ce1ef4 (5ce1ef4ffbf1e6d8c09f46fa655ea765bacf4427, parent: cf8a95590a1b768b7711f2631d5b5e3ead464de7)

@ShoyuVanilla
Copy link
Member Author

@bors try

rust-bors bot added a commit that referenced this pull request Nov 27, 2025
WF check lifetime bounds for locals with type params
@rust-bors

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Nov 27, 2025

☀️ Try build successful (CI)
Build commit: f70ee28 (f70ee28831acc074c109afab32d287057c3eca46, parent: cf8a95590a1b768b7711f2631d5b5e3ead464de7)

@ShoyuVanilla
Copy link
Member Author

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-149389 created and queued.
🤖 Automatically detected try build f70ee28
🔍 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 28, 2025
@craterbot
Copy link
Collaborator

🚧 Experiment pr-149389 is now running

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

@craterbot
Copy link
Collaborator

🎉 Experiment pr-149389 is completed!
📊 5 regressed and 3 fixed (746168 total)
📊 2051 spurious results on the retry-regessed-list.txt, consider a retry1 if this is a significant amount.
📰 Open the summary report.

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

Footnotes

  1. re-run the experiment with crates=https://crater-reports.s3.amazonaws.com/pr-149389/retry-regressed-list.txt

@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 Dec 7, 2025
@ShoyuVanilla
Copy link
Member Author

@craterbot
Copy link
Collaborator

👌 Experiment pr-149389-1 created and queued.
🤖 Automatically detected try build f70ee28
🔍 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 Dec 8, 2025
@petrochenkov
Copy link
Contributor

@craterbot p=11
All the small runs will complete in a few hours and won't need to wait for a few days until the long beta runs complete.

@craterbot
Copy link
Collaborator

📝 Configuration of the pr-149389-1 experiment changed.

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

@craterbot
Copy link
Collaborator

🚧 Experiment pr-149389-1 is now running

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

@craterbot
Copy link
Collaborator

🎉 Experiment pr-149389-1 is completed!
📊 0 regressed and 0 fixed (1832 total)
📊 118 spurious results on the retry-regessed-list.txt, consider a retry1 if this is a significant amount.
📰 Open the summary report.

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

Footnotes

  1. re-run the experiment with crates=https://crater-reports.s3.amazonaws.com/pr-149389-1/retry-regressed-list.txt

@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 Dec 13, 2025
@ShoyuVanilla
Copy link
Member Author

I expected lots of breakages but seems not
r? lcnr

@ShoyuVanilla ShoyuVanilla marked this pull request as ready for review December 13, 2025 12:27
fn test<T>() {
let _ = None::<Static<T>>;
//~^ ERROR the parameter type `T` may not live long enough
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also add a test for the unsoundness?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test with the code from #148854

Comment on lines 35 to 37
Copy link
Contributor

@lcnr lcnr Dec 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// This has to error due to an unsatisfied outlives bound on
// `Inner<T: 'static>` as its implicit drop relies on that
// bound.

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writing an FCP for this rn

View changes since this review

@lcnr lcnr added T-types Relevant to the types team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 18, 2025
@lcnr
Copy link
Contributor

lcnr commented Dec 18, 2025

@rfcbot fcp merge types

MIR typeck needs to check that all used types are well-formed. While one could imagine checking all locals for well-formedness, we don't. We only check types which flow into the body and assuming that most expressions and subtyping maintain well-formedness.

As part of this FCP proposal I took some time to look through everything chcked for WF in borrowck, it should be the following:

  • function signatures of Call terminators, both before and after normalization
  • the array type of Repeat expressions (I don't know why)
  • FnDef -> FnPtr coercions to reduce impact of Implied bounds on nested references + variance = soundness hole #25860
  • FnDef constants
  • all type information provided by the user, tracked in multiple ways
    • user_type_annotations in the MIR body
    • the user_ty of local_decls
    • the rvalue_user_type for ADT constructors?
    • AscribeUserType statements used for a bunch of stuff otherwise not checked
    • the type of constants used in the body to handle e.g. const N: Inv<'static> and let _: Inv<'a> = N;

Notably, we only check that the type of locals is well-formed if we explicitly track the fact that the user provided type information for them. As a performance optimization, we only track that fact if checking well-formedness may result in lifetime constraints.

This previously didn't add user type annotations for types which involve type params but no regions. This meant the following incorrectly compiles

struct Static<T: 'static>(T);
fn test<T>() {
    let _ = None::<Static<T>>;
}

@theemathas was then able to weaponize this in #148854 by adding a Drop impl which relies on this bound.

This PR changes us to weaken the perf optimization so that we now also check user type annotations if they have type parameters in them. There are no crater regressions from this change.

@rust-rfcbot
Copy link
Collaborator

rust-rfcbot commented Dec 18, 2025

Team member @lcnr has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Dec 18, 2025
@oli-obk
Copy link
Contributor

oli-obk commented Dec 19, 2025

@rust-timer build f70ee28

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f70ee28): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.6% [0.2%, 1.0%] 2
Regressions ❌
(secondary)
0.1% [0.1%, 0.1%] 1
Improvements ✅
(primary)
-0.4% [-0.4%, -0.4%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [-0.4%, 1.0%] 3

Max RSS (memory usage)

Results (primary -5.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-5.4% [-5.4%, -5.4%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -5.4% [-5.4%, -5.4%] 1

Cycles

Results (primary -1.3%, secondary -1.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.2% [2.2%, 2.2%] 1
Regressions ❌
(secondary)
2.3% [2.3%, 2.3%] 1
Improvements ✅
(primary)
-2.5% [-3.0%, -2.2%] 3
Improvements ✅
(secondary)
-3.0% [-3.8%, -2.2%] 2
All ❌✅ (primary) -1.3% [-3.0%, 2.2%] 4

Binary size

Results (primary -0.1%, secondary -0.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.0% [0.0%, 0.0%] 6
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.2% [-1.0%, -0.1%] 5
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.1%] 32
All ❌✅ (primary) -0.1% [-1.0%, 0.0%] 11

Bootstrap: 470.335s -> 475.664s (1.13%)
Artifact size: 386.93 MiB -> 386.89 MiB (-0.01%)

@rustbot rustbot added the perf-regression Performance regression. label Dec 19, 2025
@lqd
Copy link
Member

lqd commented Dec 19, 2025

Is it expected that changing WF has diffs in mir-opts tests?

@oli-obk
Copy link
Contributor

oli-obk commented Dec 19, 2025

It looks like there are query differences in metadata. Maybe the wf checks cause some difference but I wouldn't know how or why. I'd say noise (even if reproducible, any other change could cause it, too)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. perf-regression Performance regression. proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. 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

Successfully merging this pull request may close these issues.

Lifetime bounds of Drop aren't checked properly ignored lifetime constraints in type annotations

10 participants