Skip to content

Commit 9c97abd

Browse files
committed
Simplify for_each_mut_borrow.
1 parent c94cb83 commit 9c97abd

File tree

1 file changed

+9
-58
lines changed
  • compiler/rustc_mir_dataflow/src/impls

1 file changed

+9
-58
lines changed

compiler/rustc_mir_dataflow/src/impls/mod.rs

Lines changed: 9 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
55
use rustc_index::bit_set::{BitSet, ChunkedBitSet};
66
use rustc_index::Idx;
7-
use rustc_middle::mir::visit::{MirVisitable, Visitor};
87
use rustc_middle::mir::{self, Body, Location};
98
use rustc_middle::ty::{self, TyCtxt};
109

@@ -316,43 +315,29 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
316315
Self::update_bits(trans, path, s)
317316
});
318317

319-
if !self.tcx.sess.opts.unstable_opts.precise_enum_drop_elaboration {
320-
return;
321-
}
322-
323318
// Mark all places as "maybe init" if they are mutably borrowed. See #90752.
324-
for_each_mut_borrow(statement, location, |place| {
325-
let LookupResult::Exact(mpi) = self.move_data().rev_lookup.find(place.as_ref()) else {
326-
return;
327-
};
319+
if self.tcx.sess.opts.unstable_opts.precise_enum_drop_elaboration
320+
&& let Some((_, rvalue)) = statement.kind.as_assign()
321+
&& let mir::Rvalue::Ref(_, mir::BorrowKind::Mut { .. }, place)
322+
// FIXME: Does `&raw const foo` allow mutation? See #90413.
323+
| mir::Rvalue::AddressOf(_, place) = rvalue
324+
&& let LookupResult::Exact(mpi) = self.move_data().rev_lookup.find(place.as_ref())
325+
{
328326
on_all_children_bits(self.tcx, self.body, self.move_data(), mpi, |child| {
329327
trans.gen(child);
330328
})
331-
})
329+
}
332330
}
333331

334332
fn terminator_effect(
335333
&mut self,
336334
trans: &mut impl GenKill<Self::Idx>,
337-
terminator: &mir::Terminator<'tcx>,
335+
_: &mir::Terminator<'tcx>,
338336
location: Location,
339337
) {
340338
drop_flag_effects_for_location(self.tcx, self.body, self.mdpe, location, |path, s| {
341339
Self::update_bits(trans, path, s)
342340
});
343-
344-
if !self.tcx.sess.opts.unstable_opts.precise_enum_drop_elaboration {
345-
return;
346-
}
347-
348-
for_each_mut_borrow(terminator, location, |place| {
349-
let LookupResult::Exact(mpi) = self.move_data().rev_lookup.find(place.as_ref()) else {
350-
return;
351-
};
352-
on_all_children_bits(self.tcx, self.body, self.move_data(), mpi, |child| {
353-
trans.gen(child);
354-
})
355-
})
356341
}
357342

358343
fn call_return_effect(
@@ -733,37 +718,3 @@ fn switch_on_enum_discriminant<'mir, 'tcx>(
733718
}
734719
None
735720
}
736-
737-
struct OnMutBorrow<F>(F);
738-
739-
impl<'tcx, F> Visitor<'tcx> for OnMutBorrow<F>
740-
where
741-
F: FnMut(&mir::Place<'tcx>),
742-
{
743-
fn visit_rvalue(&mut self, rvalue: &mir::Rvalue<'tcx>, location: Location) {
744-
// FIXME: Does `&raw const foo` allow mutation? See #90413.
745-
match rvalue {
746-
mir::Rvalue::Ref(_, mir::BorrowKind::Mut { .. }, place)
747-
| mir::Rvalue::AddressOf(_, place) => (self.0)(place),
748-
749-
_ => {}
750-
}
751-
752-
self.super_rvalue(rvalue, location)
753-
}
754-
}
755-
756-
/// Calls `f` for each mutable borrow or raw reference in the program.
757-
///
758-
/// This DOES NOT call `f` for a shared borrow of a type with interior mutability. That's okay for
759-
/// initializedness, because we cannot move from an `UnsafeCell` (outside of `core::cell`), but
760-
/// other analyses will likely need to check for `!Freeze`.
761-
fn for_each_mut_borrow<'tcx>(
762-
mir: &impl MirVisitable<'tcx>,
763-
location: Location,
764-
f: impl FnMut(&mir::Place<'tcx>),
765-
) {
766-
let mut vis = OnMutBorrow(f);
767-
768-
mir.apply(location, &mut vis);
769-
}

0 commit comments

Comments
 (0)