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 7, 2024
2 parents e78913b + 755d9e5 commit ff94dee
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

0 comments on commit ff94dee

Please sign in to comment.