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

@ -1,6 +1,10 @@
//! Constant evaluation details
use std::{collections::HashMap, convert::TryInto, fmt::Display};
use std::{
collections::HashMap,
convert::TryInto,
fmt::{Display, Write},
};
use chalk_ir::{BoundVar, DebruijnIndex, GenericArgData, IntTy, Scalar};
use hir_def::{
@ -79,28 +83,29 @@ impl Display for ComputedExpr {
if *x >= 16 {
write!(f, "{} ({:#X})", x, x)
} else {
write!(f, "{}", x)
x.fmt(f)
}
}
Literal::Uint(x, _) => {
if *x >= 16 {
write!(f, "{} ({:#X})", x, x)
} else {
write!(f, "{}", x)
x.fmt(f)
}
}
Literal::Float(x, _) => write!(f, "{}", x),
Literal::Bool(x) => write!(f, "{}", x),
Literal::Char(x) => write!(f, "{:?}", x),
Literal::String(x) => write!(f, "{:?}", x),
Literal::ByteString(x) => write!(f, "{:?}", x),
Literal::Float(x, _) => x.fmt(f),
Literal::Bool(x) => x.fmt(f),
Literal::Char(x) => std::fmt::Debug::fmt(x, f),
Literal::String(x) => std::fmt::Debug::fmt(x, f),
Literal::ByteString(x) => std::fmt::Debug::fmt(x, f),
},
ComputedExpr::Tuple(t) => {
write!(f, "(")?;
f.write_char('(')?;
for x in &**t {
write!(f, "{}, ", x)?;
x.fmt(f)?;
f.write_str(", ")?;
}
write!(f, ")")
f.write_char(')')
}
}
}

View file

@ -72,7 +72,7 @@ impl fmt::Display for CaseType {
CaseType::UpperCamelCase => "CamelCase",
};
write!(f, "{}", repr)
repr.fmt(f)
}
}
@ -103,7 +103,7 @@ impl fmt::Display for IdentType {
IdentType::Variant => "Variant",
};
write!(f, "{}", repr)
repr.fmt(f)
}
}

View file

@ -1,5 +1,5 @@
//! Implementation of Chalk debug helper functions using TLS.
use std::fmt;
use std::fmt::{self, Display};
use itertools::Itertools;
@ -24,17 +24,17 @@ impl DebugContext<'_> {
AdtId::UnionId(it) => self.0.union_data(it).name.clone(),
AdtId::EnumId(it) => self.0.enum_data(it).name.clone(),
};
write!(f, "{}", name)
name.fmt(f)
}
pub(crate) fn debug_trait_id(
&self,
id: chalk_db::TraitId,
fmt: &mut fmt::Formatter<'_>,
f: &mut fmt::Formatter<'_>,
) -> Result<(), fmt::Error> {
let trait_: hir_def::TraitId = from_chalk_trait_id(id);
let trait_data = self.0.trait_data(trait_);
write!(fmt, "{}", trait_data.name)
trait_data.name.fmt(f)
}
pub(crate) fn debug_assoc_type_id(