Skip to content

Commit

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

Fixes #106459.

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

r? mir-opt
  • Loading branch information
bors committed Apr 8, 2024
2 parents 537aab7 + f440737 commit 211518e
Show file tree
Hide file tree
Showing 16 changed files with 1,092 additions and 158 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 @@ -85,6 +85,12 @@ impl SwitchTargets {
self.values.push(value);
self.targets.insert(self.targets.len() - 1, bb);
}

/// 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 211518e

Please sign in to comment.