From 73264f21e9baae4cd9dfe09ccb93b57ebe06e9d3 Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Fri, 17 Oct 2025 21:00:12 +0000 Subject: [PATCH] Restrict drop to empty projections. --- compiler/rustc_mir_transform/src/deduce_param_attrs.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_mir_transform/src/deduce_param_attrs.rs b/compiler/rustc_mir_transform/src/deduce_param_attrs.rs index b5bec55e721c..d9a2dcdd74a3 100644 --- a/compiler/rustc_mir_transform/src/deduce_param_attrs.rs +++ b/compiler/rustc_mir_transform/src/deduce_param_attrs.rs @@ -47,7 +47,10 @@ impl<'tcx> Visitor<'tcx> for DeduceReadOnly { // Dereference is not a mutation. _ if place.is_indirect_first_projection() => {} // This is a `Drop`. It could disappear at monomorphization, so mark it specially. - PlaceContext::MutatingUse(MutatingUseContext::Drop) => { + PlaceContext::MutatingUse(MutatingUseContext::Drop) + // Projection changes the place's type, so `needs_drop(local.ty)` is not + // `needs_drop(place.ty)`. + if place.projection.is_empty() => { self.read_only[param_index] |= DeducedReadOnlyParam::IF_NO_DROP; } // This is a mutation, so mark it as such.