Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/cfg/src/cfg_expr.rs')
| -rw-r--r-- | crates/cfg/src/cfg_expr.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/crates/cfg/src/cfg_expr.rs b/crates/cfg/src/cfg_expr.rs index 76e0aba859..a0e0dc5ff0 100644 --- a/crates/cfg/src/cfg_expr.rs +++ b/crates/cfg/src/cfg_expr.rs @@ -56,6 +56,36 @@ pub enum CfgExpr { Not(Box<CfgExpr>), } +impl fmt::Display for CfgExpr { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + CfgExpr::Atom(atom) => atom.fmt(f), + CfgExpr::All(exprs) => { + write!(f, "all(")?; + for (i, expr) in exprs.iter().enumerate() { + if i > 0 { + write!(f, ", ")?; + } + expr.fmt(f)?; + } + write!(f, ")") + } + CfgExpr::Any(exprs) => { + write!(f, "any(")?; + for (i, expr) in exprs.iter().enumerate() { + if i > 0 { + write!(f, ", ")?; + } + expr.fmt(f)?; + } + write!(f, ")") + } + CfgExpr::Not(expr) => write!(f, "not({})", expr), + CfgExpr::Invalid => write!(f, "invalid"), + } + } +} + impl From<CfgAtom> for CfgExpr { fn from(atom: CfgAtom) -> Self { CfgExpr::Atom(atom) |