mirror of
https://gitee.com/openharmony/third_party_rust_cxx
synced 2024-11-23 15:19:44 +00:00
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}.
This commit is contained in:
parent
7b76ea0881
commit
c59a4022cd
@ -87,12 +87,11 @@ pub(crate) fn report(error: impl StdError) -> impl Display {
|
||||
|
||||
impl<E: StdError> Display for Report<E> {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
Display::fmt(&self.0, formatter)?;
|
||||
write!(formatter, "{}", self.0)?;
|
||||
let mut error: &dyn StdError = &self.0;
|
||||
|
||||
while let Some(cause) = error.source() {
|
||||
formatter.write_str("\n\nCaused by:\n ")?;
|
||||
Display::fmt(cause, formatter)?;
|
||||
write!(formatter, "\n\nCaused by:\n {}", cause)?;
|
||||
error = cause;
|
||||
}
|
||||
|
||||
|
@ -308,9 +308,8 @@ struct CxxName<'a>(&'a Pair);
|
||||
impl<'a> Display for CxxName<'a> {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
for namespace in &self.0.namespace {
|
||||
Display::fmt(namespace, formatter)?;
|
||||
formatter.write_str("::")?;
|
||||
write!(formatter, "{}::", namespace)?;
|
||||
}
|
||||
Display::fmt(&self.0.cxx, formatter)
|
||||
write!(formatter, "{}", self.0.cxx)
|
||||
}
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ impl Display for Discriminant {
|
||||
if self.sign == Sign::Negative {
|
||||
f.write_str("-")?;
|
||||
}
|
||||
Display::fmt(&self.magnitude, f)
|
||||
write!(f, "{}", self.magnitude)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user