@@ -4,7 +4,7 @@ use crate::scan_expr::scan_expr;
4
4
use crate :: unraw:: { IdentUnraw , MemberUnraw } ;
5
5
use proc_macro2:: { Delimiter , TokenStream , TokenTree } ;
6
6
use quote:: { format_ident, quote, quote_spanned} ;
7
- use std:: collections:: { BTreeSet , HashMap , HashSet } ;
7
+ use std:: collections:: { BTreeSet , HashMap } ;
8
8
use std:: iter;
9
9
use syn:: ext:: IdentExt ;
10
10
use syn:: parse:: discouraged:: Speculative ;
@@ -34,7 +34,7 @@ impl Display<'_> {
34
34
let mut infinite_recursive = false ;
35
35
let mut implied_bounds = BTreeSet :: new ( ) ;
36
36
let mut bindings = Vec :: new ( ) ;
37
- let mut macro_named_args = HashSet :: new ( ) ;
37
+ let mut macro_named_args = BTreeSet :: new ( ) ;
38
38
39
39
self . requires_fmt_machinery = self . requires_fmt_machinery || fmt. contains ( '}' ) ;
40
40
@@ -112,15 +112,22 @@ impl Display<'_> {
112
112
out += & member. to_string ( ) ;
113
113
continue ;
114
114
}
115
+ let formatvar_prefix = if bonus_display {
116
+ "__display"
117
+ } else {
118
+ "__field"
119
+ } ;
115
120
let mut formatvar = IdentUnraw :: new ( match & member {
116
- MemberUnraw :: Unnamed ( index) => format_ident ! ( "__field{}" , index) ,
117
- MemberUnraw :: Named ( ident) => format_ident ! ( "__field_{}" , ident. to_string( ) ) ,
121
+ MemberUnraw :: Unnamed ( index) => format_ident ! ( "{}{}" , formatvar_prefix, index) ,
122
+ MemberUnraw :: Named ( ident) => {
123
+ format_ident ! ( "{}_{}" , formatvar_prefix, ident. to_string( ) )
124
+ }
118
125
} ) ;
119
126
while user_named_args. contains ( & formatvar) {
120
127
formatvar = IdentUnraw :: new ( format_ident ! ( "_{}" , formatvar. to_string( ) ) ) ;
121
128
}
122
129
out += & formatvar. to_string ( ) ;
123
- if !macro_named_args. insert ( member . clone ( ) ) {
130
+ if !macro_named_args. insert ( formatvar . clone ( ) ) {
124
131
// Already added to bindings by a previous use.
125
132
continue ;
126
133
}
0 commit comments