Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions impl/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions tests/test_generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
thing: T,
}

let error = Error { thing: 0xFFi32 };
assert_eq!(error.to_string(), "0xff 0xFF");
}