Parse trait bound before deciding name for local binding

This commit is contained in:
David Tolnay 2024-11-08 13:11:46 -05:00
parent 24e7f87d0d
commit 8a77dea3ae
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82

View file

@ -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(),
@ -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));