Skip to content

Commit e381065

Browse files
committed
Address review comments
1 parent af26e7f commit e381065

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/libsyntax/print/pprust.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,9 @@ pub fn literal_to_string(lit: token::Lit) -> String {
187187
out
188188
}
189189

190-
fn ident_to_string(ident: ast::Ident, is_raw: bool) -> String {
191-
ident_to_string_ext(ident.name, is_raw, Some(ident.span))
190+
/// Print an ident from AST, `$crate` is converted into its respective crate name.
191+
fn ast_ident_to_string(ident: ast::Ident, is_raw: bool) -> String {
192+
ident_to_string(ident.name, is_raw, Some(ident.span))
192193
}
193194

194195
// AST pretty-printer is used as a fallback for turning AST structures into token streams for
@@ -202,9 +203,7 @@ fn ident_to_string(ident: ast::Ident, is_raw: bool) -> String {
202203
// but not otherwise. Pretty-printing is the only way for proc macros to discover token contents,
203204
// so we should not perform this lossy conversion if the top level call to the pretty-printer was
204205
// done for a token stream or a single token.
205-
fn ident_to_string_ext(
206-
name: ast::Name, is_raw: bool, convert_dollar_crate: Option<Span>
207-
) -> String {
206+
fn ident_to_string(name: ast::Name, is_raw: bool, convert_dollar_crate: Option<Span>) -> String {
208207
if is_raw {
209208
format!("r#{}", name)
210209
} else {
@@ -222,6 +221,7 @@ fn ident_to_string_ext(
222221
}
223222
}
224223

224+
/// Print the token kind precisely, without converting `$crate` into its respective crate name.
225225
pub fn token_kind_to_string(tok: &TokenKind) -> String {
226226
token_kind_to_string_ext(tok, None)
227227
}
@@ -272,7 +272,7 @@ fn token_kind_to_string_ext(tok: &TokenKind, convert_dollar_crate: Option<Span>)
272272
token::Literal(lit) => literal_to_string(lit),
273273

274274
/* Name components */
275-
token::Ident(s, is_raw) => ident_to_string_ext(s, is_raw, convert_dollar_crate),
275+
token::Ident(s, is_raw) => ident_to_string(s, is_raw, convert_dollar_crate),
276276
token::Lifetime(s) => s.to_string(),
277277

278278
/* Other */
@@ -286,6 +286,7 @@ fn token_kind_to_string_ext(tok: &TokenKind, convert_dollar_crate: Option<Span>)
286286
}
287287
}
288288

289+
/// Print the token precisely, without converting `$crate` into its respective crate name.
289290
pub fn token_to_string(token: &Token) -> String {
290291
token_to_string_ext(token, false)
291292
}
@@ -305,7 +306,7 @@ crate fn nonterminal_to_string(nt: &Nonterminal) -> String {
305306
token::NtBlock(ref e) => block_to_string(e),
306307
token::NtStmt(ref e) => stmt_to_string(e),
307308
token::NtPat(ref e) => pat_to_string(e),
308-
token::NtIdent(e, is_raw) => ident_to_string(e, is_raw),
309+
token::NtIdent(e, is_raw) => ast_ident_to_string(e, is_raw),
309310
token::NtLifetime(e) => e.to_string(),
310311
token::NtLiteral(ref e) => expr_to_string(e),
311312
token::NtTT(ref tree) => tt_to_string(tree.clone()),
@@ -601,7 +602,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
601602
self.word("::");
602603
}
603604
if segment.ident.name != kw::PathRoot {
604-
self.word(ident_to_string(segment.ident, segment.ident.is_raw_guess()));
605+
self.word(ast_ident_to_string(segment.ident, segment.ident.is_raw_guess()));
605606
}
606607
}
607608
}
@@ -2205,7 +2206,7 @@ impl<'a> State<'a> {
22052206
}
22062207

22072208
crate fn print_ident(&mut self, ident: ast::Ident) {
2208-
self.s.word(ident_to_string(ident, ident.is_raw_guess()));
2209+
self.s.word(ast_ident_to_string(ident, ident.is_raw_guess()));
22092210
self.ann.post(self, AnnNode::Ident(&ident))
22102211
}
22112212

0 commit comments

Comments
 (0)