use toasty_core::stmt::{self, Expr};
pub(super) fn fold_expr_match(expr: &mut stmt::ExprMatch) -> Option<Expr> {
if let Expr::Value(value) = expr.subject.as_ref() {
for arm in &expr.arms {
if value == &arm.pattern {
return Some(arm.expr.clone());
}
}
return Some(expr.else_expr.as_ref().clone());
}
let first = expr.arms.first()?;
let all_arms_match = expr.arms.iter().all(|arm| arm.expr == first.expr);
let else_matches = expr.else_expr.as_ref() == &first.expr;
match () {
() if all_arms_match && else_matches => Some(first.expr.clone()),
() => None,
}
}