diff --git a/impl/src/fmt.rs b/impl/src/fmt.rs index 36300e52..6dfdccf2 100644 --- a/impl/src/fmt.rs +++ b/impl/src/fmt.rs @@ -99,10 +99,6 @@ impl Display<'_> { formatvar = IdentUnraw::new(format_ident!("_{}", formatvar.to_string())); } out += &formatvar.to_string(); - if !macro_named_args.insert(member.clone()) { - // Already added to scope by a previous use. - continue; - } let local = formatvar.to_local(); let mut binding_value = ToTokens::into_token_stream(match &member { MemberUnraw::Unnamed(index) => format_ident!("_{}", index), @@ -142,7 +138,11 @@ impl Display<'_> { } ); } - bindings.push((local, binding_value)); + if macro_named_args.insert(member) { + bindings.push((local, binding_value)); + } else { + // Already added to bindings by a previous use. + } } out += read; diff --git a/tests/test_generics.rs b/tests/test_generics.rs index 4d49edf5..36f11811 100644 --- a/tests/test_generics.rs +++ b/tests/test_generics.rs @@ -172,3 +172,15 @@ fn test_no_bound_on_named_fmt() { let error = Error { thing: DebugOnly }; assert_eq!(error.to_string(), "..."); } + +#[test] +fn test_multiple_bound() { + #[derive(Error, Debug)] + #[error("0x{thing:x} 0x{thing:X}")] + pub struct Error { + thing: T, + } + + let error = Error { thing: 0xFFi32 }; + assert_eq!(error.to_string(), "0xff 0xFF"); +}