Skip to content

Commit 819cf8c

Browse files
committed
make on_all_variants argument not Option
1 parent e2213d7 commit 819cf8c

File tree

2 files changed

+57
-23
lines changed

2 files changed

+57
-23
lines changed

compiler/rustc_mir_dataflow/src/drop_flag_effects.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@ where
156156
}
157157

158158
/// Handles each variant that corresponds to one of the child move paths of `enum_place`. If the
159-
/// variant is `active_variant`, `handle_active_variant` will be called (if provided). Otherwise,
159+
/// variant is `active_variant`, `handle_active_variant` will be called. Otherwise,
160160
/// `handle_inactive_variant` will be called.
161161
pub(crate) fn on_all_variants<'tcx>(
162162
move_data: &MoveData<'tcx>,
163163
enum_place: mir::Place<'tcx>,
164164
active_variant: VariantIdx,
165165
mut handle_inactive_variant: impl FnMut(MovePathIndex),
166-
mut handle_active_variant: Option<impl FnMut(MovePathIndex)>,
166+
mut handle_active_variant: impl FnMut(MovePathIndex),
167167
) {
168168
let LookupResult::Exact(enum_mpi) = move_data.rev_lookup.find(enum_place.as_ref()) else {
169169
return;
@@ -183,7 +183,7 @@ pub(crate) fn on_all_variants<'tcx>(
183183

184184
if variant_idx != active_variant {
185185
on_all_children_bits(move_data, variant_mpi, |mpi| handle_inactive_variant(mpi));
186-
} else if let Some(ref mut handle_active_variant) = handle_active_variant {
186+
} else {
187187
on_all_children_bits(move_data, variant_mpi, |mpi| handle_active_variant(mpi));
188188
}
189189
}

compiler/rustc_mir_dataflow/src/impls/initialized.rs

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)