Restrict drop to empty projections.

This commit is contained in:
Camille Gillot
2025-10-17 21:00:12 +00:00
parent 97f88f5603
commit 73264f21e9

View File

@@ -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.