Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 65a714a

Browse files
committed
pprust: Move some methods to the PrintState trait
So that path and macro argument printing code can be shared
1 parent 9bb855c commit 65a714a

File tree

3 files changed

+144
-147
lines changed

3 files changed

+144
-147
lines changed

src/librustc/hir/print.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use syntax::source_map::{SourceMap, Spanned};
44
use syntax::parse::ParseSess;
55
use syntax::print::pp::{self, Breaks};
66
use syntax::print::pp::Breaks::{Consistent, Inconsistent};
7-
use syntax::print::pprust::{Comments, PrintState};
7+
use syntax::print::pprust::{self, Comments, PrintState};
88
use syntax::symbol::kw;
99
use syntax::util::parser::{self, AssocOp, Fixity};
1010
use syntax_pos::{self, BytePos, FileName};
@@ -90,6 +90,15 @@ impl<'a> PrintState<'a> for State<'a> {
9090
fn comments(&mut self) -> &mut Option<Comments<'a>> {
9191
&mut self.comments
9292
}
93+
94+
fn print_ident(&mut self, ident: ast::Ident) {
95+
self.s.word(pprust::ast_ident_to_string(ident, ident.is_raw_guess()));
96+
self.ann.post(self, AnnNode::Name(&ident.name))
97+
}
98+
99+
fn print_generic_args(&mut self, args: &ast::GenericArgs, _colons_before_params: bool) {
100+
span_bug!(args.span(), "AST generic args printed by HIR pretty-printer");
101+
}
93102
}
94103

95104
pub const INDENT_UNIT: usize = 4;
@@ -1442,15 +1451,6 @@ impl<'a> State<'a> {
14421451
self.s.word(i.to_string())
14431452
}
14441453

1445-
pub fn print_ident(&mut self, ident: ast::Ident) {
1446-
if ident.is_raw_guess() {
1447-
self.s.word(format!("r#{}", ident.name));
1448-
} else {
1449-
self.s.word(ident.as_str().to_string());
1450-
}
1451-
self.ann.post(self, AnnNode::Name(&ident.name))
1452-
}
1453-
14541454
pub fn print_name(&mut self, name: ast::Name) {
14551455
self.print_ident(ast::Ident::with_empty_ctxt(name))
14561456
}

0 commit comments

Comments
 (0)