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 4 commits intorust-lang:mainfrom
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...
|
|
||
| hir::ExprKind::Let(hir::LetExpr { pat, init, .. }) => { | ||
| self.walk_local(init, pat, None, || self.borrow_expr(init, BorrowKind::Immutable))?; | ||
| self.walk_local(init, pat, None, || Ok(()))?; |
There was a problem hiding this comment.
AFAICS, following this change, the f parameter of walk_local will become entirely unused – could you remove it?
There was a problem hiding this comment.
|
@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 |
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.