Address review comments
This commit is contained in:
parent
af26e7f4f4
commit
e38106599a
|
@ -187,8 +187,9 @@ pub fn literal_to_string(lit: token::Lit) -> String {
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ident_to_string(ident: ast::Ident, is_raw: bool) -> String {
|
/// Print an ident from AST, `$crate` is converted into its respective crate name.
|
||||||
ident_to_string_ext(ident.name, is_raw, Some(ident.span))
|
fn ast_ident_to_string(ident: ast::Ident, is_raw: bool) -> String {
|
||||||
|
ident_to_string(ident.name, is_raw, Some(ident.span))
|
||||||
}
|
}
|
||||||
|
|
||||||
// AST pretty-printer is used as a fallback for turning AST structures into token streams for
|
// 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 {
|
||||||
// but not otherwise. Pretty-printing is the only way for proc macros to discover token contents,
|
// but not otherwise. Pretty-printing is the only way for proc macros to discover token contents,
|
||||||
// so we should not perform this lossy conversion if the top level call to the pretty-printer was
|
// so we should not perform this lossy conversion if the top level call to the pretty-printer was
|
||||||
// done for a token stream or a single token.
|
// done for a token stream or a single token.
|
||||||
fn ident_to_string_ext(
|
fn ident_to_string(name: ast::Name, is_raw: bool, convert_dollar_crate: Option<Span>) -> String {
|
||||||
name: ast::Name, is_raw: bool, convert_dollar_crate: Option<Span>
|
|
||||||
) -> String {
|
|
||||||
if is_raw {
|
if is_raw {
|
||||||
format!("r#{}", name)
|
format!("r#{}", name)
|
||||||
} else {
|
} else {
|
||||||
|
@ -222,6 +221,7 @@ fn ident_to_string_ext(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Print the token kind precisely, without converting `$crate` into its respective crate name.
|
||||||
pub fn token_kind_to_string(tok: &TokenKind) -> String {
|
pub fn token_kind_to_string(tok: &TokenKind) -> String {
|
||||||
token_kind_to_string_ext(tok, None)
|
token_kind_to_string_ext(tok, None)
|
||||||
}
|
}
|
||||||
|
@ -272,7 +272,7 @@ fn token_kind_to_string_ext(tok: &TokenKind, convert_dollar_crate: Option<Span>)
|
||||||
token::Literal(lit) => literal_to_string(lit),
|
token::Literal(lit) => literal_to_string(lit),
|
||||||
|
|
||||||
/* Name components */
|
/* Name components */
|
||||||
token::Ident(s, is_raw) => ident_to_string_ext(s, is_raw, convert_dollar_crate),
|
token::Ident(s, is_raw) => ident_to_string(s, is_raw, convert_dollar_crate),
|
||||||
token::Lifetime(s) => s.to_string(),
|
token::Lifetime(s) => s.to_string(),
|
||||||
|
|
||||||
/* Other */
|
/* Other */
|
||||||
|
@ -286,6 +286,7 @@ fn token_kind_to_string_ext(tok: &TokenKind, convert_dollar_crate: Option<Span>)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Print the token precisely, without converting `$crate` into its respective crate name.
|
||||||
pub fn token_to_string(token: &Token) -> String {
|
pub fn token_to_string(token: &Token) -> String {
|
||||||
token_to_string_ext(token, false)
|
token_to_string_ext(token, false)
|
||||||
}
|
}
|
||||||
|
@ -305,7 +306,7 @@ crate fn nonterminal_to_string(nt: &Nonterminal) -> String {
|
||||||
token::NtBlock(ref e) => block_to_string(e),
|
token::NtBlock(ref e) => block_to_string(e),
|
||||||
token::NtStmt(ref e) => stmt_to_string(e),
|
token::NtStmt(ref e) => stmt_to_string(e),
|
||||||
token::NtPat(ref e) => pat_to_string(e),
|
token::NtPat(ref e) => pat_to_string(e),
|
||||||
token::NtIdent(e, is_raw) => ident_to_string(e, is_raw),
|
token::NtIdent(e, is_raw) => ast_ident_to_string(e, is_raw),
|
||||||
token::NtLifetime(e) => e.to_string(),
|
token::NtLifetime(e) => e.to_string(),
|
||||||
token::NtLiteral(ref e) => expr_to_string(e),
|
token::NtLiteral(ref e) => expr_to_string(e),
|
||||||
token::NtTT(ref tree) => tt_to_string(tree.clone()),
|
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
|
||||||
self.word("::");
|
self.word("::");
|
||||||
}
|
}
|
||||||
if segment.ident.name != kw::PathRoot {
|
if segment.ident.name != kw::PathRoot {
|
||||||
self.word(ident_to_string(segment.ident, segment.ident.is_raw_guess()));
|
self.word(ast_ident_to_string(segment.ident, segment.ident.is_raw_guess()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2205,7 +2206,7 @@ impl<'a> State<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn print_ident(&mut self, ident: ast::Ident) {
|
crate fn print_ident(&mut self, ident: ast::Ident) {
|
||||||
self.s.word(ident_to_string(ident, ident.is_raw_guess()));
|
self.s.word(ast_ident_to_string(ident, ident.is_raw_guess()));
|
||||||
self.ann.post(self, AnnNode::Ident(&ident))
|
self.ann.post(self, AnnNode::Ident(&ident))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue