fix: fix the capture behavior of if let in closures#154210
fix: fix the capture behavior of if let in closures#154210Embers-of-the-Fire wants to merge 6 commits into
if let in closures#154210Conversation
|
r? @mati865 rustbot has assigned @mati865. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Could you add a test case that's a bit more like #153982, so that there's also a field that doesn't get captured in the first place? |
|
cc @Nadrieril |
There was a problem hiding this comment.
So, this is technically a breaking change, much like #138961, right? It'd be nice to have a proof-of-concept test on which the borrow checker will start erroring, at which point we'd probably wanna do a crater run...
|
@bors try |
This comment has been minimized.
This comment has been minimized.
…e, r=<try> fix: fix the capture behavior of `if let` in closures
|
I'm wondering which mode we should run crater in. Would |
AFAIK |
|
Since this PR changes the drop order in some cases, it is technically conceivable that some code would have an observable change in behavior after this PR gets merged. It is also technically possible that a crate's test suite would notice this. I would however be extremely surprised if someone has written such code and made a test suite good enough to be able to detect this – previous experience with crater runs for similar adjustments confirms this. If it was my call to make, I'd run a But my call to make it is not. |
|
It can technically change run time behavior by changing drop order. I think that's kind of unlikely to be relied on though. |
|
Based on the discussion above, I'm going with just @craterbot run mode=check-only |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
If this can change runtime behavior (ergo, a stable breaking change), then IMO this definitely justifies a full build-and-test not just check-only. I imagine lang would likewise want as much of the full picture as possible on ecosystem impact when making the accept/reject call. |
|
@craterbot cancel |
|
🗑️ Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
@craterbot run mode=build-and-test |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
This is more a question of how the generated MIR for these patterns looks like, which we're not the experts on... @Nadrieril are there tests we should have to ensure all the intended UB is captured by the generated MIR? |
I'm not sure I follow, do you mean Miri tests? |
|
Yes. |
|
|
|
Apparently the lowering was not the same before this PR so it may be worth having some sort of smoke test here? Is there some test where Miri's verdict (UB vs non-UB) changes with this PR due to the changed capture behavior? |
|
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
In #138961 there's some miri tests added, should I add some miri tests like that? |
|
Yeah something like that -- especially if one of them changes behavior with this PR. |
|
The Miri subtree was changed cc @rust-lang/miri |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Signed-off-by: Embers-of-the-Fire <stellarishs@163.com>
Add focused Miri coverage for the if-let closure capture change, demonstrating UB at closure construction when partial pattern capture reborrows dangling references. Assisted-by: OpenAI:gpt-5.5 Signed-off-by: Embers-of-the-Fire <stellarishs@163.com>
4da8000 to
12dd438
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
View all comments
Closes #153982.
TL;DR This patch adds the missing capture behavior change for
if letstatements introduced in RFC 2229.This patch converts
into
so that
if letnow behaves likelet.