1
Fork 0

Rollup merge of #115999 - matthewjasper:closure-capture-let-guards, r=b-naber

Capture scrutinee of if let guards correctly

Previously we were always capturing by value.

cc #51114
This commit is contained in:
Matthias Krüger 2023-09-22 23:12:35 +02:00 committed by GitHub
commit e6f4b35d9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 164 additions and 4 deletions

View file

@ -664,10 +664,12 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
);
self.walk_pat(discr_place, arm.pat, arm.guard.is_some());
if let Some(hir::Guard::If(e)) = arm.guard {
self.consume_expr(e)
} else if let Some(hir::Guard::IfLet(ref l)) = arm.guard {
self.consume_expr(l.init)
match arm.guard {
Some(hir::Guard::If(ref e)) => self.consume_expr(e),
Some(hir::Guard::IfLet(ref l)) => {
self.walk_local(l.init, l.pat, None, |t| t.borrow_expr(l.init, ty::ImmBorrow))
}
None => {}
}
self.consume_expr(arm.body);