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 5 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 |
|
All the crater regressions I've looked at look unrelated to this PR |
|
@rustbot labels +I-lang-nominated I'm unsure if this a T-lang FCP, but nominated just in case. In edition 2021+, |
|
This seems to be a correct consistency fix to me. Based on @Nadrieril's report that all the crater regressions he's looked at seem unrelated (thanks for having a look), I propose we do this. @rfcbot fcp merge lang |
|
Team member @traviscross 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! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
|
Since this is changing exactly what closures capture, is there a test to make sure that this doesn't introduce new UB-detection issues that rhyme with |
|
Going to go ahead and check a box on the assumption that #154210 (comment) is already covered; if there's any issue on that front, please do raise a concern. @rfcbot reviewed |
|
cc @rust-lang/opsem |
|
🔔 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. |
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.