3
3
//! zero-sized structure.
4
4
5
5
use rustc::mir::{self, Body, Location};
6
- use rustc::ty::TyCtxt;
6
+ use rustc::ty::layout::VariantIdx;
7
+ use rustc::ty::{self, TyCtxt};
7
8
use rustc_index::bit_set::BitSet;
8
9
use rustc_index::vec::Idx;
9
10
@@ -12,12 +13,13 @@ use super::MoveDataParamEnv;
12
13
use crate::util::elaborate_drops::DropFlagState;
13
14
14
15
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};
16
17
use super::{BottomValue, GenKillSet};
17
18
18
19
use super::drop_flag_effects_for_function_entry;
19
20
use super::drop_flag_effects_for_location;
20
21
use super::on_lookup_result_bits;
22
+ use crate::dataflow::drop_flag_effects;
21
23
22
24
mod borrowed_locals;
23
25
mod indirect_mutation;
@@ -338,6 +340,37 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
338
340
},
339
341
);
340
342
}
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
+ }
341
374
}
342
375
343
376
impl<'tcx> AnalysisDomain<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
0 commit comments