Skip to content

Commit

Permalink
Auto merge of rust-lang#120614 - DianQK:simplify-switch-int, r=<try>
Browse files Browse the repository at this point in the history
 Transforms match into an assignment statement

Fixes rust-lang#106459.

We should be able to do some similar transformations, like `enum` to `enum`.

r? mir-opt
  • Loading branch information
bors committed Feb 4, 2024
2 parents b11fbfb + 7a47635 commit eea65f2
Show file tree
Hide file tree
Showing 15 changed files with 1,009 additions and 159 deletions.
6 changes: 6 additions & 0 deletions compiler/rustc_middle/src/mir/terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ impl SwitchTargets {
pub fn target_for_value(&self, value: u128) -> BasicBlock {
self.iter().find_map(|(v, t)| (v == value).then_some(t)).unwrap_or_else(|| self.otherwise())
}

/// Returns true if all targets (including the fallback target) are distinct.
#[inline]
pub fn is_distinct(&self) -> bool {
self.targets.iter().collect::<FxHashSet<_>>().len() == self.targets.len()
}
}

pub struct SwitchTargetsIter<'a> {
Expand Down
Loading

0 comments on commit eea65f2

Please sign in to comment.