Skip to content

Commit

Permalink
Merge pull request #377 from dtolnay/bounds
Browse files Browse the repository at this point in the history
Support generic types that need multiple bounds
  • Loading branch information
dtolnay authored Nov 8, 2024
2 parents f728f12 + 5948ee6 commit 8e5c843
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
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");
}

0 comments on commit 8e5c843

Please sign in to comment.