Skip to content

Commit e2c8047

Browse files
Kill move paths of dead variants
1 parent 99b9619 commit e2c8047

File tree

1 file changed

+35
-2
lines changed
  • src/librustc_mir/dataflow/impls

1 file changed

+35
-2
lines changed

src/librustc_mir/dataflow/impls/mod.rs

+35-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
//! zero-sized structure.
44
55
use rustc::mir::{self, Body, Location};
6-
use rustc::ty::TyCtxt;
6+
use rustc::ty::layout::VariantIdx;
7+
use rustc::ty::{self, TyCtxt};
78
use rustc_index::bit_set::BitSet;
89
use rustc_index::vec::Idx;
910

@@ -12,12 +13,13 @@ use super::MoveDataParamEnv;
1213
use crate::util::elaborate_drops::DropFlagState;
1314

1415
use super::generic::{AnalysisDomain, GenKill, GenKillAnalysis};
15-
use super::move_paths::{HasMoveData, InitIndex, InitKind, MoveData, MovePathIndex};
16+
use super::move_paths::{HasMoveData, InitIndex, InitKind, LookupResult, MoveData, MovePathIndex};
1617
use super::{BottomValue, GenKillSet};
1718

1819
use super::drop_flag_effects_for_function_entry;
1920
use super::drop_flag_effects_for_location;
2021
use super::on_lookup_result_bits;
22+
use crate::dataflow::drop_flag_effects;
2123

2224
mod borrowed_locals;
2325
mod indirect_mutation;
@@ -338,6 +340,37 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
338340
},
339341
);
340342
}
343+
344+
fn discriminant_switch_effect(
345+
&self,
346+
trans: &mut impl GenKill<Self::Idx>,
347+
_block: mir::BasicBlock,
348+
enum_place: &mir::Place<'tcx>,
349+
_adt: &ty::AdtDef,
350+
variant: VariantIdx,
351+
) {
352+
let enum_mpi = match self.move_data().rev_lookup.find(enum_place.as_ref()) {
353+
LookupResult::Exact(mpi) => mpi,
354+
LookupResult::Parent(_) => return,
355+
};
356+
357+
// Kill all move paths that correspond to variants other than this one
358+
let move_paths = &self.move_data().move_paths;
359+
let enum_path = &move_paths[enum_mpi];
360+
for (mpi, variant_path) in enum_path.children(move_paths) {
361+
trans.kill(mpi);
362+
match variant_path.place.projection.last().unwrap() {
363+
mir::ProjectionElem::Downcast(_, idx) if *idx == variant => continue,
364+
_ => drop_flag_effects::on_all_children_bits(
365+
self.tcx,
366+
self.body,
367+
self.move_data(),
368+
mpi,
369+
|mpi| trans.kill(mpi),
370+
),
371+
}
372+
}
373+
}
341374
}
342375

343376
impl<'tcx> AnalysisDomain<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {

0 commit comments

Comments
 (0)