Skip to content

Commit

Permalink
Parse trait bound before deciding name for local binding
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Nov 8, 2024
1 parent 24e7f87 commit 8a77dea
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions impl/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,6 @@ impl Display<'_> {
}
_ => continue,
};
let mut formatvar = IdentUnraw::new(match &member {
MemberUnraw::Unnamed(index) => format_ident!("__field{}", index),
MemberUnraw::Named(ident) => format_ident!("__field_{}", ident.to_string()),
});
while user_named_args.contains(&formatvar) {
formatvar = IdentUnraw::new(format_ident!("_{}", formatvar.to_string()));
}
out += &formatvar.to_string();
let local = formatvar.to_local();
let mut binding_value = ToTokens::into_token_stream(match &member {
MemberUnraw::Unnamed(index) => format_ident!("_{}", index),
MemberUnraw::Named(ident) => ident.to_local(),
Expand Down Expand Up @@ -128,6 +119,15 @@ impl Display<'_> {
if let Some(&field) = member_index.get(&member) {
implied_bounds.insert((field, bound));
}
let mut formatvar = IdentUnraw::new(match &member {
MemberUnraw::Unnamed(index) => format_ident!("__field{}", index),
MemberUnraw::Named(ident) => format_ident!("__field_{}", ident.to_string()),
});
while user_named_args.contains(&formatvar) {
formatvar = IdentUnraw::new(format_ident!("_{}", formatvar.to_string()));
}
out += &formatvar.to_string();
let local = formatvar.to_local();
infinite_recursive |= member == *"self" && bound == Trait::Display;
if macro_named_args.insert(member) {
bindings.push((local, binding_value));
Expand Down

0 comments on commit 8a77dea

Please sign in to comment.