Switch case condition that is constant () no longer optimizes to false.

This commit is contained in:
Stephen Chung
2022-07-18 23:28:12 +08:00
parent ff6954d9d5
commit 281e94fc62
3 changed files with 105 additions and 106 deletions

View File

@@ -153,6 +153,27 @@ impl<B: Into<StmtBlock>> From<(Expr, B)> for ConditionalStmtBlock {
}
}
impl ConditionalStmtBlock {
/// Is this conditional statements block always `true`?
#[inline(always)]
#[must_use]
pub fn is_always_true(&self) -> bool {
match self.condition {
Expr::BoolConstant(true, ..) => true,
_ => false,
}
}
/// Is this conditional statements block always `false`?
#[inline(always)]
#[must_use]
pub fn is_always_false(&self) -> bool {
match self.condition {
Expr::BoolConstant(false, ..) => true,
_ => false,
}
}
}
/// _(internals)_ A type containing a range case for a `switch` statement.
/// Exported under the `internals` feature only.
#[derive(Clone, Hash)]