Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions compiler/rustc_mir/src/transform/early_otherwise_branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,14 @@ impl<'a, 'tcx> Helper<'a, 'tcx> {
let discr = self.find_switch_discriminant_info(bb, switch)?;

// go through each target, finding a discriminant read, and a switch
let results = discr.targets_with_values.iter().map(|(value, target)| {
self.find_discriminant_switch_pairing(&discr, target.clone(), value.clone())
});

// if the optimization did not apply for one of the targets, then abort
if results.clone().any(|x| x.is_none()) || results.len() == 0 {
trace!("NO: not all of the targets matched the pattern for optimization");
return None;
let mut results = vec![];

for (value, target) in discr.targets_with_values.iter() {
let info = self.find_discriminant_switch_pairing(&discr, *target, *value)?;
results.push(info);
}

Some(results.flatten().collect())
Some(results)
}

fn find_discriminant_switch_pairing(
Expand Down Expand Up @@ -302,7 +299,6 @@ impl<'a, 'tcx> Helper<'a, 'tcx> {
// the declaration of the discriminant read. Place of this read is being used in the switch
let discr_decl = &self.body.local_decls()[discr_local];
let discr_ty = discr_decl.ty;
// the otherwise target lies as the last element
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you meant to remove this comment.

let otherwise_bb = targets.otherwise();
let targets_with_values = targets.iter().collect();

Expand Down