@@ -148,12 +148,19 @@ pub fn to_string(f: impl FnOnce(&mut State<'_>)) -> String {
148
148
149
149
// This makes comma-separated lists look slightly nicer,
150
150
// and also addresses a specific regression described in issue #63896.
151
- fn tt_prepend_space ( tt : & TokenTree ) -> bool {
151
+ fn tt_prepend_space ( tt : & TokenTree , prev : & TokenTree ) -> bool {
152
152
match tt {
153
153
TokenTree :: Token ( token) => match token. kind {
154
154
token:: Comma => false ,
155
155
_ => true ,
156
156
} ,
157
+ TokenTree :: Delimited ( _, DelimToken :: Paren , _) => match prev {
158
+ TokenTree :: Token ( token) => match token. kind {
159
+ token:: Ident ( _, _) => false ,
160
+ _ => true ,
161
+ } ,
162
+ _ => true ,
163
+ } ,
157
164
_ => true ,
158
165
}
159
166
}
@@ -650,11 +657,14 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
650
657
}
651
658
652
659
fn print_tts ( & mut self , tts : tokenstream:: TokenStream , convert_dollar_crate : bool ) {
653
- for ( i, tt) in tts. into_trees ( ) . enumerate ( ) {
654
- if i != 0 && tt_prepend_space ( & tt) {
660
+ let mut iter = tts. into_trees ( ) . peekable ( ) ;
661
+ while let Some ( tt) = iter. next ( ) {
662
+ let show_space =
663
+ if let Some ( next) = iter. peek ( ) { tt_prepend_space ( next, & tt) } else { false } ;
664
+ self . print_tt ( tt, convert_dollar_crate) ;
665
+ if show_space {
655
666
self . space ( ) ;
656
667
}
657
- self . print_tt ( tt, convert_dollar_crate) ;
658
668
}
659
669
}
660
670
0 commit comments