Skip to content

Commit c59a402

Browse files
committed
Avoid inheriting formatter flags in some Display impls
The previous implementation would produce wrong unintentional output when formatting with alignment or padding, such as {:<15}.
1 parent 7b76ea0 commit c59a402

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

gen/src/error.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,11 @@ pub(crate) fn report(error: impl StdError) -> impl Display {
8787

8888
impl<E: StdError> Display for Report<E> {
8989
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
90-
Display::fmt(&self.0, formatter)?;
90+
write!(formatter, "{}", self.0)?;
9191
let mut error: &dyn StdError = &self.0;
9292

9393
while let Some(cause) = error.source() {
94-
formatter.write_str("\n\nCaused by:\n ")?;
95-
Display::fmt(cause, formatter)?;
94+
write!(formatter, "\n\nCaused by:\n {}", cause)?;
9695
error = cause;
9796
}
9897

macro/src/load.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,8 @@ struct CxxName<'a>(&'a Pair);
308308
impl<'a> Display for CxxName<'a> {
309309
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
310310
for namespace in &self.0.namespace {
311-
Display::fmt(namespace, formatter)?;
312-
formatter.write_str("::")?;
311+
write!(formatter, "{}::", namespace)?;
313312
}
314-
Display::fmt(&self.0.cxx, formatter)
313+
write!(formatter, "{}", self.0.cxx)
315314
}
316315
}

syntax/discriminant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ impl Display for Discriminant {
208208
if self.sign == Sign::Negative {
209209
f.write_str("-")?;
210210
}
211-
Display::fmt(&self.magnitude, f)
211+
write!(f, "{}", self.magnitude)
212212
}
213213
}
214214

0 commit comments

Comments
 (0)