diff options
| author | bors <bors@rust-lang.org> | 2024-06-11 20:11:21 +0000 | 
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-06-11 20:11:21 +0000 | 
| commit | d0227c6a19c2d6e8dceb87c7a2776dc2b10d2a04 (patch) | |
| tree | e8812a3577d52d1a80f238ca0863cbd22c35e8b2 /compiler/rustc_ast_pretty/src | |
| parent | 3ea5e236ecb4c5f22437059f82d3915d311e4ec0 (diff) | |
| parent | f7d49fdf4f16fe691561663468efc4fbcbdb6ba4 (diff) | |
| download | rust-d0227c6a19c2d6e8dceb87c7a2776dc2b10d2a04.tar.gz rust-d0227c6a19c2d6e8dceb87c7a2776dc2b10d2a04.zip | |
Auto merge of #125174 - nnethercote:less-ast-pretty-printing, r=petrochenkov
Print `token::Interpolated` with token stream pretty printing. This is a step towards removing `token::Interpolated` (#124141). It unavoidably changes the output of the `stringify!` macro, generally for the better. r? `@petrochenkov`
Diffstat (limited to 'compiler/rustc_ast_pretty/src')
| -rw-r--r-- | compiler/rustc_ast_pretty/src/pprust/state.rs | 25 | 
1 files changed, 9 insertions, 16 deletions
| diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index f32b63a39f0..4eb2a103fd8 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -877,18 +877,11 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere } fn nonterminal_to_string(&self, nt: &Nonterminal) -> String { - match nt { - token::NtExpr(e) => self.expr_to_string(e), - token::NtMeta(e) => self.attr_item_to_string(e), - token::NtTy(e) => self.ty_to_string(e), - token::NtPath(e) => self.path_to_string(e), - token::NtItem(e) => self.item_to_string(e), - token::NtBlock(e) => self.block_to_string(e), - token::NtStmt(e) => self.stmt_to_string(e), - token::NtPat(e) => self.pat_to_string(e), - token::NtLiteral(e) => self.expr_to_string(e), - token::NtVis(e) => self.vis_to_string(e), - } + // We extract the token stream from the AST fragment and pretty print + // it, rather than using AST pretty printing, because `Nonterminal` is + // slated for removal in #124141. (This method will also then be + // removed.) + self.tts_to_string(&TokenStream::from_nonterminal_ast(nt)) } /// Print the token kind precisely, without converting `$crate` into its respective crate name. @@ -1022,6 +1015,10 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere Self::to_string(|s| s.print_attr_item(ai, ai.path.span)) } + fn tts_to_string(&self, tokens: &TokenStream) -> String { + Self::to_string(|s| s.print_tts(tokens, false)) + } + fn to_string(f: impl FnOnce(&mut State<'_>)) -> String { let mut printer = State::new(); f(&mut printer); @@ -2068,10 +2065,6 @@ impl<'a> State<'a> { }) } - pub(crate) fn tts_to_string(&self, tokens: &TokenStream) -> String { - Self::to_string(|s| s.print_tts(tokens, false)) - } - pub(crate) fn path_segment_to_string(&self, p: &ast::PathSegment) -> String { Self::to_string(|s| s.print_path_segment(p, false)) } | 
