Skip to content

Commit 10c8b56

Browse files
committed
Factor out common code in PrintState.
The AST and HIR versions of `State::print_ident` are textually identical, but the types differ slightly. This commit factors out the common code they both have by replacing `print_ident` with `ann_post`, which is a smaller function that still captures the type difference.
1 parent e16b52d commit 10c8b56

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,14 @@ impl std::ops::DerefMut for State<'_> {
258258

259259
pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::DerefMut {
260260
fn comments(&mut self) -> &mut Option<Comments<'a>>;
261-
fn print_ident(&mut self, ident: Ident);
261+
fn ann_post(&mut self, ident: Ident);
262262
fn print_generic_args(&mut self, args: &ast::GenericArgs, colons_before_params: bool);
263263

264+
fn print_ident(&mut self, ident: Ident) {
265+
self.word(IdentPrinter::for_ast_ident(ident, ident.is_raw_guess()).to_string());
266+
self.ann_post(ident)
267+
}
268+
264269
fn strsep<T, F>(
265270
&mut self,
266271
sep: &'static str,
@@ -837,9 +842,8 @@ impl<'a> PrintState<'a> for State<'a> {
837842
&mut self.comments
838843
}
839844

840-
fn print_ident(&mut self, ident: Ident) {
841-
self.word(IdentPrinter::for_ast_ident(ident, ident.is_raw_guess()).to_string());
842-
self.ann.post(self, AnnNode::Ident(&ident))
845+
fn ann_post(&mut self, ident: Ident) {
846+
self.ann.post(self, AnnNode::Ident(&ident));
843847
}
844848

845849
fn print_generic_args(&mut self, args: &ast::GenericArgs, colons_before_params: bool) {

compiler/rustc_hir_pretty/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_hir::LifetimeParamKind;
1212
use rustc_hir::{BindingAnnotation, ByRef, GenericArg, GenericParam, GenericParamKind, Node, Term};
1313
use rustc_hir::{GenericBound, PatKind, RangeEnd, TraitBoundModifier};
1414
use rustc_span::source_map::SourceMap;
15-
use rustc_span::symbol::{kw, Ident, IdentPrinter, Symbol};
15+
use rustc_span::symbol::{kw, Ident, Symbol};
1616
use rustc_span::{self, FileName};
1717
use rustc_target::spec::abi::Abi;
1818

@@ -136,9 +136,8 @@ impl<'a> PrintState<'a> for State<'a> {
136136
&mut self.comments
137137
}
138138

139-
fn print_ident(&mut self, ident: Ident) {
140-
self.word(IdentPrinter::for_ast_ident(ident, ident.is_raw_guess()).to_string());
141-
self.ann.post(self, AnnNode::Name(&ident.name))
139+
fn ann_post(&mut self, ident: Ident) {
140+
self.ann.post(self, AnnNode::Name(&ident.name));
142141
}
143142

144143
fn print_generic_args(&mut self, _: &ast::GenericArgs, _colons_before_params: bool) {

0 commit comments

Comments
 (0)