fix: fix the capture behavior of if let in closures - #154210
Conversation
|
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 |
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. |
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>
12dd438 to
f491a6c
Compare
|
Nice tests, thanks :) |
|
Apologies, this slipped under my radar! Crater got reviewed, FCP approved, tests added, so everything looks good. @bors r+ |
|
📋 This PR cannot be approved because it currently has the following labels: |
|
@bors r+ |
…full-capture, r=Nadrieril fix: fix the capture behavior of `if let` in closures Closes rust-lang#153982. **TL;DR** This patch adds the missing capture behavior change for `if let` statements introduced in RFC 2229. This patch converts ```rust self.walk_local(init, pat, None, || self.borrow_expr(init, BorrowKind::Immutable))?; ``` into ```rust self.walk_local(init, pat, None, || Ok(()))?; ``` so that `if let` now behaves like `let`.
…uwer Rollup of 8 pull requests Successful merges: - #154210 (fix: fix the capture behavior of `if let` in closures) - #156176 (Initial implementation of `FnPtr` trait) - #160767 (Unify E0117 foreign-trait label for ADT/primitive types with existing Slice/Array/Tuple handling) - #160489 (Adding diagnostic item markers for multiple fs functions and structs) - #161220 (bootstrap: Allow `./x fix --allow-dirty`) - #161291 (Rename `ProjectionPredicate` and `TraitPredicate`) - #161296 (Enable overflow checks in `rustc_thread_pool`) - #161304 (Rename test so it matches the issue)
…full-capture, r=Nadrieril fix: fix the capture behavior of `if let` in closures Closes rust-lang#153982. **TL;DR** This patch adds the missing capture behavior change for `if let` statements introduced in RFC 2229. This patch converts ```rust self.walk_local(init, pat, None, || self.borrow_expr(init, BorrowKind::Immutable))?; ``` into ```rust self.walk_local(init, pat, None, || Ok(()))?; ``` so that `if let` now behaves like `let`.
…full-capture, r=Nadrieril fix: fix the capture behavior of `if let` in closures Closes rust-lang#153982. **TL;DR** This patch adds the missing capture behavior change for `if let` statements introduced in RFC 2229. This patch converts ```rust self.walk_local(init, pat, None, || self.borrow_expr(init, BorrowKind::Immutable))?; ``` into ```rust self.walk_local(init, pat, None, || Ok(()))?; ``` so that `if let` now behaves like `let`.
Rollup of 18 pull requests Successful merges: - #154210 (fix: fix the capture behavior of `if let` in closures) - #156176 (Initial implementation of `FnPtr` trait) - #160767 (Unify E0117 foreign-trait label for ADT/primitive types with existing Slice/Array/Tuple handling) - #161297 (std: use UNIX's `Instant` and `SystemTime` on Hermit) - #160489 (Adding diagnostic item markers for multiple fs functions and structs) - #160643 (Require windowed (and exception) for Xtensa ABI) - #161088 (suppress projection errors already covered by a trait error) - #161114 (Remove fields from TypeKind: Struct, Enum, Union and Tuple) - #161115 (Assorted allocator nitpicks) - #161220 (bootstrap: Allow `./x fix --allow-dirty`) - #161296 (Enable overflow checks in `rustc_thread_pool`) - #161298 (remove rustc_error_messages dependency) - #161304 (Rename test so it matches the issue) - #161309 (`allow(non_camel_case_types)` in `minicore.rs`) - #161315 (Relax codgen test variable regex) - #161318 (Doc: clarify how `Read::bytes` handling Interrupted errors) - #161321 (Update books) - #161335 ([compiletest] Use the correct rustc lib directory for query_rustc_output)
Rollup merge of #154210 - Embers-of-the-Fire:feat/if-let-no-full-capture, r=Nadrieril fix: fix the capture behavior of `if let` in closures Closes #153982. **TL;DR** This patch adds the missing capture behavior change for `if let` statements introduced in RFC 2229. This patch converts ```rust self.walk_local(init, pat, None, || self.borrow_expr(init, BorrowKind::Immutable))?; ``` into ```rust self.walk_local(init, pat, None, || Ok(()))?; ``` so that `if let` now behaves like `let`.
Rollup of 18 pull requests Successful merges: - rust-lang/rust#154210 (fix: fix the capture behavior of `if let` in closures) - rust-lang/rust#156176 (Initial implementation of `FnPtr` trait) - rust-lang/rust#160767 (Unify E0117 foreign-trait label for ADT/primitive types with existing Slice/Array/Tuple handling) - rust-lang/rust#161297 (std: use UNIX's `Instant` and `SystemTime` on Hermit) - rust-lang/rust#160489 (Adding diagnostic item markers for multiple fs functions and structs) - rust-lang/rust#160643 (Require windowed (and exception) for Xtensa ABI) - rust-lang/rust#161088 (suppress projection errors already covered by a trait error) - rust-lang/rust#161114 (Remove fields from TypeKind: Struct, Enum, Union and Tuple) - rust-lang/rust#161115 (Assorted allocator nitpicks) - rust-lang/rust#161220 (bootstrap: Allow `./x fix --allow-dirty`) - rust-lang/rust#161296 (Enable overflow checks in `rustc_thread_pool`) - rust-lang/rust#161298 (remove rustc_error_messages dependency) - rust-lang/rust#161304 (Rename test so it matches the issue) - rust-lang/rust#161309 (`allow(non_camel_case_types)` in `minicore.rs`) - rust-lang/rust#161315 (Relax codgen test variable regex) - rust-lang/rust#161318 (Doc: clarify how `Read::bytes` handling Interrupted errors) - rust-lang/rust#161321 (Update books) - rust-lang/rust#161335 ([compiletest] Use the correct rustc lib directory for query_rustc_output)
Rollup of 18 pull requests Successful merges: - rust-lang/rust#154210 (fix: fix the capture behavior of `if let` in closures) - rust-lang/rust#156176 (Initial implementation of `FnPtr` trait) - rust-lang/rust#160767 (Unify E0117 foreign-trait label for ADT/primitive types with existing Slice/Array/Tuple handling) - rust-lang/rust#161297 (std: use UNIX's `Instant` and `SystemTime` on Hermit) - rust-lang/rust#160489 (Adding diagnostic item markers for multiple fs functions and structs) - rust-lang/rust#160643 (Require windowed (and exception) for Xtensa ABI) - rust-lang/rust#161088 (suppress projection errors already covered by a trait error) - rust-lang/rust#161114 (Remove fields from TypeKind: Struct, Enum, Union and Tuple) - rust-lang/rust#161115 (Assorted allocator nitpicks) - rust-lang/rust#161220 (bootstrap: Allow `./x fix --allow-dirty`) - rust-lang/rust#161296 (Enable overflow checks in `rustc_thread_pool`) - rust-lang/rust#161298 (remove rustc_error_messages dependency) - rust-lang/rust#161304 (Rename test so it matches the issue) - rust-lang/rust#161309 (`allow(non_camel_case_types)` in `minicore.rs`) - rust-lang/rust#161315 (Relax codgen test variable regex) - rust-lang/rust#161318 (Doc: clarify how `Read::bytes` handling Interrupted errors) - rust-lang/rust#161321 (Update books) - rust-lang/rust#161335 ([compiletest] Use the correct rustc lib directory for query_rustc_output)
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.