diff --git a/impl/src/attr.rs b/impl/src/attr.rs index f48d506..c7c3d99 100644 --- a/impl/src/attr.rs +++ b/impl/src/attr.rs @@ -20,7 +20,6 @@ pub struct Display<'a> { pub original: &'a Attribute, pub fmt: LitStr, pub args: TokenStream, - pub was_shorthand: bool, pub has_bonus_display: bool, } @@ -82,7 +81,6 @@ fn parse_error_attribute<'a>(attrs: &mut Attrs<'a>, attr: &'a Attribute) -> Resu original: attr, fmt: input.parse()?, args: parse_token_expr(input, false)?, - was_shorthand: false, has_bonus_display: false, }; if attrs.display.is_some() { @@ -153,20 +151,8 @@ impl ToTokens for Display<'_> { fn to_tokens(&self, tokens: &mut TokenStream) { let fmt = &self.fmt; let args = &self.args; - if self.was_shorthand && fmt.value() == "{}" { - let arg = args.clone().into_iter().nth(1).unwrap(); - tokens.extend(quote! { - std::fmt::Display::fmt(#arg, __formatter) - }); - } else if self.was_shorthand && fmt.value() == "{:?}" { - let arg = args.clone().into_iter().nth(1).unwrap(); - tokens.extend(quote! { - std::fmt::Debug::fmt(#arg, __formatter) - }); - } else { - tokens.extend(quote! { - write!(__formatter, #fmt #args) - }); - } + tokens.extend(quote! { + write!(__formatter, #fmt #args) + }); } } diff --git a/impl/src/fmt.rs b/impl/src/fmt.rs index 71e5929..3927eb5 100644 --- a/impl/src/fmt.rs +++ b/impl/src/fmt.rs @@ -88,7 +88,6 @@ impl Display<'_> { out += read; self.fmt = LitStr::new(&out, self.fmt.span()); self.args = args; - self.was_shorthand = true; self.has_bonus_display = has_bonus_display; } } diff --git a/tests/test_display.rs b/tests/test_display.rs index 1e7b13d..7d9ac59 100644 --- a/tests/test_display.rs +++ b/tests/test_display.rs @@ -165,3 +165,17 @@ fn test_trailing_comma() { assert("error ?", Error('?')); } + +#[test] +fn test_field() { + #[derive(Debug)] + struct Inner { + data: usize, + } + + #[derive(Error, Debug)] + #[error("{}", .0.data)] + struct Error(Inner); + + assert("0", Error(Inner { data: 0 })); +}