@@ -148,12 +148,19 @@ pub fn to_string(f: impl FnOnce(&mut State<'_>)) -> String {
148148
149149// This makes comma-separated lists look slightly nicer,
150150// 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 {
152152 match tt {
153153 TokenTree :: Token ( token) => match token. kind {
154154 token:: Comma => false ,
155155 _ => true ,
156156 } ,
157+ TokenTree :: Delimited ( _, DelimToken :: Paren , _) => match prev {
158+ TokenTree :: Token ( token) => match token. kind {
159+ token:: Ident ( _, _) => false ,
160+ _ => true ,
161+ } ,
162+ _ => true ,
163+ } ,
157164 _ => true ,
158165 }
159166}
@@ -650,11 +657,14 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
650657 }
651658
652659 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 {
655666 self . space ( ) ;
656667 }
657- self . print_tt ( tt, convert_dollar_crate) ;
658668 }
659669 }
660670
0 commit comments