tamer: xir: Attribute error formatting/typo fixes

There were two problem errors: one showing "element element" and one showing
the value along with the name of the attribute.

The change for `<Attr as Display>::fmt` is debatable.  I'm going to do this
for now (only show `@name`) and adjust later if necessary.

I'll need to go use `crate::fmt` consistently in previously-existing format
strings at some point, too.

DEV-7145
main
Mike Gerwitz 2022-07-27 16:25:46 -04:00
parent 41b41e02c1
commit 4f2b27f944
2 changed files with 11 additions and 2 deletions

View File

@ -177,8 +177,17 @@ impl crate::parse::Object for Attr {}
impl Display for Attr {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// Do not display value since it can contain any information and
// mess up formatted output.
// If we wish to display that information in the future,
// then we ought to escape and elide it,
// but we must furthermore make sure that it makes sense in all
// contexts;
// many diagnostic messages today expect that outputting an
// attribute will output the name of that attribute and
// nothing more.
match self {
Self(key, value, _) => write!(f, "`@{key}=\"{value}\"`"),
Self(key, _value, _) => write!(f, "@{key}"),
}
}
}

View File

@ -110,7 +110,7 @@ impl<S: AttrParseState> Display for AttrParseError<S> {
write!(
f,
"unexpected attribute `{attr}` for \
element element `{ele_name}`"
element `{ele_name}`"
)
}