]> git.proxmox.com Git - rustc.git/blob - compiler/rustc_ast_pretty/src/pprust/mod.rs
New upstream version 1.53.0+dfsg1
[rustc.git] / compiler / rustc_ast_pretty / src / pprust / mod.rs
1 #[cfg(test)]
2 mod tests;
3
4 pub mod state;
5 pub use state::{print_crate, AnnNode, Comments, PpAnn, PrintState, State};
6
7 use rustc_ast as ast;
8 use rustc_ast::token::{Nonterminal, Token, TokenKind};
9 use rustc_ast::tokenstream::{TokenStream, TokenTree};
10
11 pub fn nonterminal_to_string(nt: &Nonterminal) -> String {
12 State::new().nonterminal_to_string(nt)
13 }
14
15 /// Print the token kind precisely, without converting `$crate` into its respective crate name.
16 pub fn token_kind_to_string(tok: &TokenKind) -> String {
17 State::new().token_kind_to_string(tok)
18 }
19
20 /// Print the token precisely, without converting `$crate` into its respective crate name.
21 pub fn token_to_string(token: &Token) -> String {
22 State::new().token_to_string(token)
23 }
24
25 pub fn ty_to_string(ty: &ast::Ty) -> String {
26 State::new().ty_to_string(ty)
27 }
28
29 pub fn bounds_to_string(bounds: &[ast::GenericBound]) -> String {
30 State::new().bounds_to_string(bounds)
31 }
32
33 pub fn pat_to_string(pat: &ast::Pat) -> String {
34 State::new().pat_to_string(pat)
35 }
36
37 pub fn expr_to_string(e: &ast::Expr) -> String {
38 State::new().expr_to_string(e)
39 }
40
41 pub fn tt_to_string(tt: &TokenTree) -> String {
42 State::new().tt_to_string(tt)
43 }
44
45 pub fn tts_to_string(tokens: &TokenStream) -> String {
46 State::new().tts_to_string(tokens)
47 }
48
49 pub fn item_to_string(i: &ast::Item) -> String {
50 State::new().item_to_string(i)
51 }
52
53 pub fn path_to_string(p: &ast::Path) -> String {
54 State::new().path_to_string(p)
55 }
56
57 pub fn path_segment_to_string(p: &ast::PathSegment) -> String {
58 State::new().path_segment_to_string(p)
59 }
60
61 pub fn vis_to_string(v: &ast::Visibility) -> String {
62 State::new().vis_to_string(v)
63 }
64
65 pub fn meta_list_item_to_string(li: &ast::NestedMetaItem) -> String {
66 State::new().meta_list_item_to_string(li)
67 }
68
69 pub fn attribute_to_string(attr: &ast::Attribute) -> String {
70 State::new().attribute_to_string(attr)
71 }
72
73 pub fn to_string(f: impl FnOnce(&mut State<'_>)) -> String {
74 State::new().to_string(f)
75 }