1
Fork 0

Replace the default branch with an unreachable branch If it is the last variant

This commit is contained in:
DianQK 2024-02-14 12:02:22 +08:00
parent d8b7b5be7d
commit 08ae8380ce
No known key found for this signature in database
GPG key ID: 46BDB1AC96C48912
23 changed files with 997 additions and 11 deletions

View file

@ -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> {