Skip to content

Commit eea65f2

Browse files
committed
Auto merge of rust-lang#120614 - DianQK:simplify-switch-int, r=<try>
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
2 parents b11fbfb + 7a47635 commit eea65f2

15 files changed

+1009
-159
lines changed

compiler/rustc_middle/src/mir/terminator.rs

+6
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ impl SwitchTargets {
7474
pub fn target_for_value(&self, value: u128) -> BasicBlock {
7575
self.iter().find_map(|(v, t)| (v == value).then_some(t)).unwrap_or_else(|| self.otherwise())
7676
}
77+
78+
/// Returns true if all targets (including the fallback target) are distinct.
79+
#[inline]
80+
pub fn is_distinct(&self) -> bool {
81+
self.targets.iter().collect::<FxHashSet<_>>().len() == self.targets.len()
82+
}
7783
}
7884

7985
pub struct SwitchTargetsIter<'a> {

0 commit comments

Comments
 (0)