33//! zero-sized structure.
44
55use rustc:: mir:: { self , Body , Location } ;
6- use rustc:: ty:: TyCtxt ;
6+ use rustc:: ty:: layout:: VariantIdx ;
7+ use rustc:: ty:: { self , TyCtxt } ;
78use rustc_index:: bit_set:: BitSet ;
89use rustc_index:: vec:: Idx ;
910
@@ -12,12 +13,13 @@ use super::MoveDataParamEnv;
1213use crate :: util:: elaborate_drops:: DropFlagState ;
1314
1415use 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 } ;
1617use super :: { BottomValue , GenKillSet } ;
1718
1819use super :: drop_flag_effects_for_function_entry;
1920use super :: drop_flag_effects_for_location;
2021use super :: on_lookup_result_bits;
22+ use crate :: dataflow:: drop_flag_effects;
2123
2224mod borrowed_locals;
2325mod 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
343376impl < ' tcx > AnalysisDomain < ' tcx > for MaybeUninitializedPlaces < ' _ , ' tcx > {
0 commit comments