Replace write! with direct calls

This commit is contained in:
Laurențiu Nicola 2022-03-21 10:43:36 +02:00
parent b594f9c441
commit 1a37b17162
13 changed files with 59 additions and 49 deletions

View file

@ -43,7 +43,7 @@ impl CfgAtom {
impl fmt::Display for CfgAtom {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CfgAtom::Flag(name) => write!(f, "{}", name),
CfgAtom::Flag(name) => name.fmt(f),
CfgAtom::KeyValue { key, value } => write!(f, "{} = {:?}", key, value),
}
}

View file

@ -6,7 +6,7 @@
//!
//! This is currently both messy and inefficient. Feel free to improve, there are unit tests.
use std::fmt;
use std::fmt::{self, Write};
use rustc_hash::FxHashSet;
@ -125,17 +125,17 @@ impl DnfExpr {
impl fmt::Display for DnfExpr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.conjunctions.len() != 1 {
write!(f, "any(")?;
f.write_str("any(")?;
}
for (i, conj) in self.conjunctions.iter().enumerate() {
if i != 0 {
f.write_str(", ")?;
}
write!(f, "{}", conj)?;
conj.fmt(f)?;
}
if self.conjunctions.len() != 1 {
write!(f, ")")?;
f.write_char(')')?;
}
Ok(())
@ -165,17 +165,17 @@ impl Conjunction {
impl fmt::Display for Conjunction {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.literals.len() != 1 {
write!(f, "all(")?;
f.write_str("all(")?;
}
for (i, lit) in self.literals.iter().enumerate() {
if i != 0 {
f.write_str(", ")?;
}
write!(f, "{}", lit)?;
lit.fmt(f)?;
}
if self.literals.len() != 1 {
write!(f, ")")?;
f.write_str(")")?;
}
Ok(())
@ -204,12 +204,12 @@ impl fmt::Display for Literal {
}
match &self.var {
Some(var) => write!(f, "{}", var)?,
Some(var) => var.fmt(f)?,
None => f.write_str("<invalid>")?,
}
if self.negate {
write!(f, ")")?;
f.write_char(')')?;
}
Ok(())

View file

@ -128,7 +128,7 @@ impl fmt::Display for CfgDiff {
};
f.write_str(sep)?;
write!(f, "{}", atom)?;
atom.fmt(f)?;
}
if !self.disable.is_empty() {
@ -146,7 +146,7 @@ impl fmt::Display for CfgDiff {
};
f.write_str(sep)?;
write!(f, "{}", atom)?;
atom.fmt(f)?;
}
}
@ -170,7 +170,7 @@ impl fmt::Display for InactiveReason {
};
f.write_str(sep)?;
write!(f, "{}", atom)?;
atom.fmt(f)?;
}
let is_are = if self.enabled.len() == 1 { "is" } else { "are" };
write!(f, " {} enabled", is_are)?;
@ -189,7 +189,7 @@ impl fmt::Display for InactiveReason {
};
f.write_str(sep)?;
write!(f, "{}", atom)?;
atom.fmt(f)?;
}
let is_are = if self.disabled.len() == 1 { "is" } else { "are" };
write!(f, " {} disabled", is_are)?;