about summary refs log tree commit diff
path: root/compiler/rustc_lint/src/if_let_rescope.rs
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2025-02-23 01:09:51 +0000
committerMichael Goulet <michael@errs.io>2025-02-24 18:31:50 +0000
commitbad8e98c7d0ed217b58362e61ae4357e5344d995 (patch)
tree1e0c6023ac65a70bbc6442b8fbb654352546bd86 /compiler/rustc_lint/src/if_let_rescope.rs
parent2797936f6dcd29777f236a5d966d487a7f4cbbb3 (diff)
downloadrust-bad8e98c7d0ed217b58362e61ae4357e5344d995.tar.gz
rust-bad8e98c7d0ed217b58362e61ae4357e5344d995.zip
Consider lvalues of field and index as possibly temporary places
Diffstat (limited to 'compiler/rustc_lint/src/if_let_rescope.rs')
-rw-r--r--compiler/rustc_lint/src/if_let_rescope.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/compiler/rustc_lint/src/if_let_rescope.rs b/compiler/rustc_lint/src/if_let_rescope.rs
index 55d900e0319..23f037f3692 100644
--- a/compiler/rustc_lint/src/if_let_rescope.rs
+++ b/compiler/rustc_lint/src/if_let_rescope.rs
@@ -436,6 +436,14 @@ impl<'tcx> Visitor<'tcx> for FindSignificantDropper<'_, 'tcx> {
                 self.check_promoted_temp_with_drop(expr)?;
                 intravisit::walk_expr(self, expr)
             }
+            // `(Drop, ()).1` introduces a temporary and then moves out of
+            // part of it, therefore we should check it for temporaries.
+            // FIXME: This may have false positives if we move the part
+            // that actually has drop, but oh well.
+            hir::ExprKind::Index(expr, _, _) | hir::ExprKind::Field(expr, _) => {
+                self.check_promoted_temp_with_drop(expr)?;
+                intravisit::walk_expr(self, expr)
+            }
             // If always introduces a temporary terminating scope for its cond and arms,
             // so don't visit them.
             hir::ExprKind::If(..) => ControlFlow::Continue(()),