@@ -456,16 +456,33 @@ impl<'tcx> Analysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
456456 value : SwitchTargetValue ,
457457 otherwise_state : Option < & mut Self :: Domain > ,
458458 ) {
459- if let SwitchTargetValue :: Normal ( value) = value {
460- // Kill all move paths that correspond to variants we know to be inactive along this
461- // particular outgoing edge of a `SwitchInt`.
462- drop_flag_effects:: on_all_variants (
463- self . move_data ,
464- data. enum_place ,
465- data. next_discr ( value) ,
466- |mpi| state. kill ( mpi) ,
467- otherwise_state. map ( |state| |mpi| state. kill ( mpi) ) ,
468- ) ;
459+ let SwitchTargetValue :: Normal ( value) = value else {
460+ return ;
461+ } ;
462+
463+ let handle_inactive_variant = |mpi| state. kill ( mpi) ;
464+
465+ // Kill all move paths that correspond to variants we know to be inactive along this
466+ // particular outgoing edge of a `SwitchInt`.
467+ match otherwise_state {
468+ Some ( otherwise_state) => {
469+ drop_flag_effects:: on_all_variants (
470+ self . move_data ,
471+ data. enum_place ,
472+ data. next_discr ( value) ,
473+ handle_inactive_variant,
474+ |mpi| otherwise_state. kill ( mpi) ,
475+ ) ;
476+ }
477+ None => {
478+ drop_flag_effects:: on_all_variants (
479+ self . move_data ,
480+ data. enum_place ,
481+ data. next_discr ( value) ,
482+ handle_inactive_variant,
483+ |_mpi| { } ,
484+ ) ;
485+ }
469486 }
470487 }
471488
@@ -598,16 +615,33 @@ impl<'tcx> Analysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
598615 value : SwitchTargetValue ,
599616 otherwise_state : Option < & mut Self :: Domain > ,
600617 ) {
601- if let SwitchTargetValue :: Normal ( value) = value {
602- // Mark all move paths that correspond to variants other than this one as maybe
603- // uninitialized (in reality, they are *definitely* uninitialized).
604- drop_flag_effects:: on_all_variants (
605- self . move_data ,
606- data. enum_place ,
607- data. next_discr ( value) ,
608- |mpi| state. gen_ ( mpi) ,
609- otherwise_state. map ( |state| |mpi| state. gen_ ( mpi) ) ,
610- ) ;
618+ let SwitchTargetValue :: Normal ( value) = value else {
619+ return ;
620+ } ;
621+
622+ let handle_inactive_variant = |mpi| state. gen_ ( mpi) ;
623+
624+ // Mark all move paths that correspond to variants other than this one as maybe
625+ // uninitialized (in reality, they are *definitely* uninitialized).
626+ match otherwise_state {
627+ Some ( otherwise_state) => {
628+ drop_flag_effects:: on_all_variants (
629+ self . move_data ,
630+ data. enum_place ,
631+ data. next_discr ( value) ,
632+ handle_inactive_variant,
633+ |mpi| otherwise_state. gen_ ( mpi) ,
634+ ) ;
635+ }
636+ None => {
637+ drop_flag_effects:: on_all_variants (
638+ self . move_data ,
639+ data. enum_place ,
640+ data. next_discr ( value) ,
641+ handle_inactive_variant,
642+ |_mpi| { } ,
643+ ) ;
644+ }
611645 }
612646 }
613647
0 commit comments