|
4 | 4 |
|
5 | 5 | use rustc_index::bit_set::{BitSet, ChunkedBitSet};
|
6 | 6 | use rustc_index::Idx;
|
7 |
| -use rustc_middle::mir::visit::{MirVisitable, Visitor}; |
8 | 7 | use rustc_middle::mir::{self, Body, Location};
|
9 | 8 | use rustc_middle::ty::{self, TyCtxt};
|
10 | 9 |
|
@@ -316,43 +315,29 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
|
316 | 315 | Self::update_bits(trans, path, s)
|
317 | 316 | });
|
318 | 317 |
|
319 |
| - if !self.tcx.sess.opts.unstable_opts.precise_enum_drop_elaboration { |
320 |
| - return; |
321 |
| - } |
322 |
| - |
323 | 318 | // 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 | + { |
328 | 326 | on_all_children_bits(self.tcx, self.body, self.move_data(), mpi, |child| {
|
329 | 327 | trans.gen(child);
|
330 | 328 | })
|
331 |
| - }) |
| 329 | + } |
332 | 330 | }
|
333 | 331 |
|
334 | 332 | fn terminator_effect(
|
335 | 333 | &mut self,
|
336 | 334 | trans: &mut impl GenKill<Self::Idx>,
|
337 |
| - terminator: &mir::Terminator<'tcx>, |
| 335 | + _: &mir::Terminator<'tcx>, |
338 | 336 | location: Location,
|
339 | 337 | ) {
|
340 | 338 | drop_flag_effects_for_location(self.tcx, self.body, self.mdpe, location, |path, s| {
|
341 | 339 | Self::update_bits(trans, path, s)
|
342 | 340 | });
|
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 |
| - }) |
356 | 341 | }
|
357 | 342 |
|
358 | 343 | fn call_return_effect(
|
@@ -733,37 +718,3 @@ fn switch_on_enum_discriminant<'mir, 'tcx>(
|
733 | 718 | }
|
734 | 719 | None
|
735 | 720 | }
|
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