@@ -524,7 +524,10 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
524
524
}
525
525
}
526
526
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
+ {
528
531
self . comments ( ) . and_then ( |c| c. peek ( ) )
529
532
}
530
533
@@ -849,18 +852,11 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
849
852
}
850
853
851
854
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) )
864
860
}
865
861
866
862
/// 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
994
990
Self :: to_string ( |s| s. print_attr_item ( ai, ai. path . span ) )
995
991
}
996
992
993
+ fn tts_to_string ( & self , tokens : & TokenStream ) -> String {
994
+ Self :: to_string ( |s| s. print_tts ( tokens, false ) )
995
+ }
996
+
997
997
fn to_string ( f : impl FnOnce ( & mut State < ' _ > ) ) -> String {
998
998
let mut printer = State :: new ( ) ;
999
999
f ( & mut printer) ;
@@ -2039,10 +2039,6 @@ impl<'a> State<'a> {
2039
2039
} )
2040
2040
}
2041
2041
2042
- pub ( crate ) fn tts_to_string ( & self , tokens : & TokenStream ) -> String {
2043
- Self :: to_string ( |s| s. print_tts ( tokens, false ) )
2044
- }
2045
-
2046
2042
pub ( crate ) fn path_segment_to_string ( & self , p : & ast:: PathSegment ) -> String {
2047
2043
Self :: to_string ( |s| s. print_path_segment ( p, false ) )
2048
2044
}
0 commit comments