Rename LitKind::to_token_lit as LitKind::synthesize_token_lit.

This makes it clearer that it's not a lossless conversion, which I find
helpful.
This commit is contained in:
Nicholas Nethercote 2022-11-29 13:01:04 +11:00
parent c090c6880c
commit e658144586
6 changed files with 8 additions and 8 deletions

View File

@ -328,7 +328,7 @@ pub fn mk_name_value_item_str(ident: Ident, str: Symbol, str_span: Span) -> Meta
}
pub fn mk_name_value_item(ident: Ident, kind: LitKind, lit_span: Span) -> MetaItem {
let lit = MetaItemLit { token_lit: kind.to_token_lit(), kind, span: lit_span };
let lit = MetaItemLit { token_lit: kind.synthesize_token_lit(), kind, span: lit_span };
let span = ident.span.to(lit_span);
MetaItem { path: Path::from_ident(ident), kind: MetaItemKind::NameValue(lit), span }
}
@ -408,7 +408,7 @@ pub fn mk_attr_name_value_str(
val: Symbol,
span: Span,
) -> Attribute {
let lit = LitKind::Str(val, StrStyle::Cooked).to_token_lit();
let lit = LitKind::Str(val, StrStyle::Cooked).synthesize_token_lit();
let expr = P(Expr {
id: DUMMY_NODE_ID,
kind: ExprKind::Lit(lit),

View File

@ -142,10 +142,10 @@ impl LitKind {
})
}
/// Attempts to recover a token from semantic literal.
/// Synthesizes a token from a semantic literal.
/// This function is used when the original token doesn't exist (e.g. the literal is created
/// by an AST-based macro) or unavailable (e.g. from HIR pretty-printing).
pub fn to_token_lit(&self) -> token::Lit {
pub fn synthesize_token_lit(&self) -> token::Lit {
let (kind, symbol, suffix) = match *self {
LitKind::Str(symbol, ast::StrStyle::Cooked) => {
// Don't re-intern unless the escaped string is different.

View File

@ -323,7 +323,7 @@ impl<'a> State<'a> {
self.print_token_literal(*token_lit, expr.span);
}
ast::ExprKind::IncludedBytes(bytes) => {
let lit = ast::LitKind::ByteStr(bytes.clone()).to_token_lit();
let lit = ast::LitKind::ByteStr(bytes.clone()).synthesize_token_lit();
self.print_token_literal(lit, expr.span)
}
ast::ExprKind::Cast(expr, ty) => {

View File

@ -333,7 +333,7 @@ impl<'a> ExtCtxt<'a> {
}
fn expr_lit(&self, span: Span, lit_kind: ast::LitKind) -> P<ast::Expr> {
let token_lit = lit_kind.to_token_lit();
let token_lit = lit_kind.synthesize_token_lit();
self.expr(span, ast::ExprKind::Lit(token_lit))
}

View File

@ -526,7 +526,7 @@ impl server::TokenStream for Rustc<'_, '_> {
Ok(tokenstream::TokenStream::token_alone(token::Literal(*token_lit), expr.span))
}
ast::ExprKind::IncludedBytes(bytes) => {
let lit = ast::LitKind::ByteStr(bytes.clone()).to_token_lit();
let lit = ast::LitKind::ByteStr(bytes.clone()).synthesize_token_lit();
Ok(tokenstream::TokenStream::token_alone(token::TokenKind::Literal(lit), expr.span))
}
ast::ExprKind::Unary(ast::UnOp::Neg, e) => match &e.kind {

View File

@ -1256,7 +1256,7 @@ impl<'a> State<'a> {
fn print_literal(&mut self, lit: &hir::Lit) {
self.maybe_print_comment(lit.span.lo());
self.word(lit.node.to_token_lit().to_string())
self.word(lit.node.synthesize_token_lit().to_string())
}
fn print_inline_asm(&mut self, asm: &hir::InlineAsm<'_>) {