Replace the default branch with an unreachable branch If it is the last variant
This commit is contained in:
parent
d8b7b5be7d
commit
08ae8380ce
23 changed files with 997 additions and 11 deletions
|
@ -74,6 +74,17 @@ 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())
|
||||
}
|
||||
|
||||
/// Adds a new target to the switch. But You cannot add an already present value.
|
||||
#[inline]
|
||||
pub fn add_target(&mut self, value: u128, bb: BasicBlock) {
|
||||
let value = Pu128(value);
|
||||
if self.values.contains(&value) {
|
||||
bug!("target value {:?} already present", value);
|
||||
}
|
||||
self.values.push(value);
|
||||
self.targets.insert(self.targets.len() - 1, bb);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SwitchTargetsIter<'a> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue