Skip to content

Commit 1a8d28a

Browse files
committed
Use otherwise from switchTargets
1 parent bd56b11 commit 1a8d28a

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

compiler/rustc_mir/src/transform/early_otherwise_branch.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
101101
.iter()
102102
.flat_map(|x| x.switch_targets.iter().map(|x| (x.0, x.1)));
103103

104-
let targets = SwitchTargets::new(new_targets, first_switch_info.otherwise_bb);
104+
let targets =
105+
SwitchTargets::new(new_targets, first_switch_info.switch_targets.otherwise());
105106

106107
// new block that jumps to the correct discriminant case. This block is switched to if the discriminants are equal
107108
let new_switch_data = BasicBlockData::new(Some(Terminator {
@@ -118,7 +119,7 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
118119

119120
// switch on the NotEqual. If true, then jump to the `otherwise` case.
120121
// If false, then jump to a basic block that then jumps to the correct disciminant case
121-
let true_case = first_switch_info.otherwise_bb;
122+
let true_case = first_switch_info.switch_targets.otherwise();
122123
let false_case = new_switch_bb;
123124
patch.patch_terminator(
124125
opt_to_apply.basic_block_first_switch,
@@ -171,8 +172,6 @@ struct Helper<'a, 'tcx> {
171172
struct SwitchDiscriminantInfo<'tcx> {
172173
/// Type of the discriminant being switched on
173174
discr_ty: Ty<'tcx>,
174-
/// The basic block that the otherwise branch points to
175-
otherwise_bb: BasicBlock,
176175
/// Targets and values for the switch
177176
switch_targets: SwitchTargets,
178177
discr_source_info: SourceInfo,
@@ -232,7 +231,9 @@ impl<'a, 'tcx> Helper<'a, 'tcx> {
232231
let this_bb_discr_info = self.find_switch_discriminant_info(bb, terminator)?;
233232

234233
// The otherwise branch of the two switches have to point to the same bb
235-
if discr_info.otherwise_bb != this_bb_discr_info.otherwise_bb {
234+
if discr_info.switch_targets.otherwise()
235+
!= this_bb_discr_info.switch_targets.otherwise()
236+
{
236237
trace!("NO: otherwise target is not the same");
237238
return None;
238239
}
@@ -287,7 +288,6 @@ impl<'a, 'tcx> Helper<'a, 'tcx> {
287288
// the declaration of the discriminant read. Place of this read is being used in the switch
288289
let discr_decl = &self.body.local_decls()[discr_local];
289290
let discr_ty = discr_decl.ty;
290-
let otherwise_bb = targets.otherwise();
291291
let targets_with_values = targets.clone();
292292

293293
// find the place of the adt where the discriminant is being read from
@@ -304,7 +304,6 @@ impl<'a, 'tcx> Helper<'a, 'tcx> {
304304
Some(SwitchDiscriminantInfo {
305305
discr_used_in_switch: discr.place()?,
306306
discr_ty,
307-
otherwise_bb,
308307
switch_targets: targets_with_values,
309308
discr_source_info: discr_decl.source_info,
310309
place_of_adt_discr_read,

0 commit comments

Comments
 (0)