Skip to content

Commit c2f2b2d

Browse files
committed
Streamline token printing functions.
Remove `PrintState::token{,_kind}_to_string`, because they're very thin wrappers for `PrintState::token{,_kind}_to_string_ext` that obscure more than they clarify. And rename the latter two methods.
1 parent 2e4d547 commit c2f2b2d

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

compiler/rustc_ast_pretty/src/pprust/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ pub fn nonterminal_to_string(nt: &Nonterminal) -> String {
1616

1717
/// Print the token kind precisely, without converting `$crate` into its respective crate name.
1818
pub fn token_kind_to_string(tok: &TokenKind) -> Cow<'static, str> {
19-
State::new().token_kind_to_string(tok)
19+
State::new().token_kind_to_string(tok, None)
2020
}
2121

2222
/// Print the token precisely, without converting `$crate` into its respective crate name.
2323
pub fn token_to_string(token: &Token) -> Cow<'static, str> {
24-
State::new().token_to_string(token)
24+
State::new().token_to_string(token, false)
2525
}
2626

2727
pub fn ty_to_string(ty: &ast::Ty) -> String {

compiler/rustc_ast_pretty/src/pprust/state.rs

+6-16
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
666666
fn print_tt(&mut self, tt: &TokenTree, convert_dollar_crate: bool) -> Spacing {
667667
match tt {
668668
TokenTree::Token(token, spacing) => {
669-
let token_str = self.token_to_string_ext(token, convert_dollar_crate);
669+
let token_str = self.token_to_string(token, convert_dollar_crate);
670670
self.word(token_str);
671671
if let token::DocComment(..) = token.kind {
672672
self.hardbreak()
@@ -770,12 +770,12 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
770770
self.bclose(span, empty);
771771
}
772772
delim => {
773-
let token_str = self.token_kind_to_string(&token::OpenDelim(delim));
773+
let token_str = self.token_kind_to_string(&token::OpenDelim(delim), None);
774774
self.word(token_str);
775775
self.ibox(0);
776776
self.print_tts(tts, convert_dollar_crate);
777777
self.end();
778-
let token_str = self.token_kind_to_string(&token::CloseDelim(delim));
778+
let token_str = self.token_kind_to_string(&token::CloseDelim(delim), None);
779779
self.word(token_str);
780780
}
781781
}
@@ -884,12 +884,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
884884
self.tts_to_string(&TokenStream::from_nonterminal_ast(nt))
885885
}
886886

887-
/// Print the token kind precisely, without converting `$crate` into its respective crate name.
888-
fn token_kind_to_string(&self, tok: &TokenKind) -> Cow<'static, str> {
889-
self.token_kind_to_string_ext(tok, None)
890-
}
891-
892-
fn token_kind_to_string_ext(
887+
fn token_kind_to_string(
893888
&self,
894889
tok: &TokenKind,
895890
convert_dollar_crate: Option<Span>,
@@ -959,14 +954,9 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
959954
}
960955
}
961956

962-
/// Print the token precisely, without converting `$crate` into its respective crate name.
963-
fn token_to_string(&self, token: &Token) -> Cow<'static, str> {
964-
self.token_to_string_ext(token, false)
965-
}
966-
967-
fn token_to_string_ext(&self, token: &Token, convert_dollar_crate: bool) -> Cow<'static, str> {
957+
fn token_to_string(&self, token: &Token, convert_dollar_crate: bool) -> Cow<'static, str> {
968958
let convert_dollar_crate = convert_dollar_crate.then_some(token.span);
969-
self.token_kind_to_string_ext(&token.kind, convert_dollar_crate)
959+
self.token_kind_to_string(&token.kind, convert_dollar_crate)
970960
}
971961

972962
fn ty_to_string(&self, ty: &ast::Ty) -> String {

0 commit comments

Comments
 (0)