]> git.lizzy.rs Git - rust.git/commitdiff
Rename `LitKind::to_token_lit` as `LitKind::synthesize_token_lit`.
authorNicholas Nethercote <n.nethercote@gmail.com>
Tue, 29 Nov 2022 02:01:04 +0000 (13:01 +1100)
committerNicholas Nethercote <n.nethercote@gmail.com>
Thu, 1 Dec 2022 23:23:44 +0000 (10:23 +1100)
This makes it clearer that it's not a lossless conversion, which I find
helpful.

compiler/rustc_ast/src/attr/mod.rs
compiler/rustc_ast/src/util/literal.rs
compiler/rustc_ast_pretty/src/pprust/state/expr.rs
compiler/rustc_expand/src/build.rs
compiler/rustc_expand/src/proc_macro_server.rs
compiler/rustc_hir_pretty/src/lib.rs

index 057cc26b5799e7eff82d0d6b7ad30eade281be53..1ba4691467586bd6edfa817770173761e70aae6c 100644 (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),
index 1d6e7914f3a5c8d0395de312564765bc7dbcb688..5e6c94f1e6fc89bdabe6b70ade65bd368d62e5d9 100644 (file)
@@ -142,10 +142,10 @@ pub fn from_token_lit(lit: token::Lit) -> Result<LitKind, LitError> {
         })
     }
 
-    /// 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.
index 81483ac30d1de21bc5c1355832aa394fb58629bc..828b9d5ad5f68b1fb7a7a7582e3bac97f8d6ab08 100644 (file)
@@ -323,7 +323,7 @@ pub(super) fn print_expr_outer_attr_style(&mut self, expr: &ast::Expr, is_inline
                 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) => {
index c978297295d4003420c0b978c5b4222e3b0097e8..b56e1a24834f0b3536b9819107acf18bedd40411 100644 (file)
@@ -333,7 +333,7 @@ pub fn expr_struct_ident(
     }
 
     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))
     }
 
index 7616579611711984161c740745240ab4a9bac203..57f66758ef0055a83acad15ad25c8db8e6276415 100644 (file)
@@ -526,7 +526,7 @@ fn expand_expr(&mut self, stream: &Self::TokenStream) -> Result<Self::TokenStrea
                 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 {
index 95729822677bd32e85597913535ca7165cdec4a6..10b2265c522a0a2aca551f054d0b90c2ec93c767 100644 (file)
@@ -1256,7 +1256,7 @@ fn print_expr_addr_of(
 
     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<'_>) {