@@ -524,7 +524,10 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
524524 }
525525 }
526526
527- fn peek_comment < ' b > ( & ' b self ) -> Option < & ' b Comment > where ' a : ' b {
527+ fn peek_comment < ' b > ( & ' b self ) -> Option < & ' b Comment >
528+ where
529+ ' a : ' b ,
530+ {
528531 self . comments ( ) . and_then ( |c| c. peek ( ) )
529532 }
530533
@@ -849,18 +852,11 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
849852 }
850853
851854 fn nonterminal_to_string ( & self , nt : & Nonterminal ) -> String {
852- match nt {
853- token:: NtExpr ( e) => self . expr_to_string ( e) ,
854- token:: NtMeta ( e) => self . attr_item_to_string ( e) ,
855- token:: NtTy ( e) => self . ty_to_string ( e) ,
856- token:: NtPath ( e) => self . path_to_string ( e) ,
857- token:: NtItem ( e) => self . item_to_string ( e) ,
858- token:: NtBlock ( e) => self . block_to_string ( e) ,
859- token:: NtStmt ( e) => self . stmt_to_string ( e) ,
860- token:: NtPat ( e) => self . pat_to_string ( e) ,
861- token:: NtLiteral ( e) => self . expr_to_string ( e) ,
862- token:: NtVis ( e) => self . vis_to_string ( e) ,
863- }
855+ // We convert the AST fragment to a token stream and pretty print that,
856+ // rather than using AST pretty printing, because `Nonterminal` is
857+ // slated for removal in #124141. (This method will also then be
858+ // removed.)
859+ self . tts_to_string ( & TokenStream :: from_nonterminal_ast ( nt) )
864860 }
865861
866862 /// Print the token kind precisely, without converting `$crate` into its respective crate name.
@@ -994,6 +990,10 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
994990 Self :: to_string ( |s| s. print_attr_item ( ai, ai. path . span ) )
995991 }
996992
993+ fn tts_to_string ( & self , tokens : & TokenStream ) -> String {
994+ Self :: to_string ( |s| s. print_tts ( tokens, false ) )
995+ }
996+
997997 fn to_string ( f : impl FnOnce ( & mut State < ' _ > ) ) -> String {
998998 let mut printer = State :: new ( ) ;
999999 f ( & mut printer) ;
@@ -2039,10 +2039,6 @@ impl<'a> State<'a> {
20392039 } )
20402040 }
20412041
2042- pub ( crate ) fn tts_to_string ( & self , tokens : & TokenStream ) -> String {
2043- Self :: to_string ( |s| s. print_tts ( tokens, false ) )
2044- }
2045-
20462042 pub ( crate ) fn path_segment_to_string ( & self , p : & ast:: PathSegment ) -> String {
20472043 Self :: to_string ( |s| s. print_path_segment ( p, false ) )
20482044 }
0 commit comments