about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-07-10 14:02:45 +0000
committerbors <bors@rust-lang.org>2022-07-10 14:02:45 +0000
commit29554c0a120f6c1eb0c60f2a88c06faeb3d0f3c9 (patch)
treea1c97773965a554cfc3d5fc958d832f3c67014df /compiler
parent268be96d6db196d79a1b2b8299a0485496e5a7ab (diff)
parentfb5b7b4af2c46a2ac2117a49b3209569e7b6ddad (diff)
downloadrust-29554c0a120f6c1eb0c60f2a88c06faeb3d0f3c9.tar.gz
rust-29554c0a120f6c1eb0c60f2a88c06faeb3d0f3c9.zip
Auto merge of #98463 - mystor:expand_expr_bool, r=eddyb
proc_macro: Fix expand_expr expansion of bool literals

Previously, the expand_expr method would expand bool literals as a
`Literal` token containing a `LitKind::Bool`, rather than as an `Ident`.
This is not a valid token, and the `LitKind::Bool` case needs to be
handled seperately.

Tests were added to more deeply compare the streams in the expand-expr
test suite to catch mistakes like this in the future.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_expand/src/proc_macro_server.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/compiler/rustc_expand/src/proc_macro_server.rs b/compiler/rustc_expand/src/proc_macro_server.rs
index 0e909e2f982..411d6be9c44 100644
--- a/compiler/rustc_expand/src/proc_macro_server.rs
+++ b/compiler/rustc_expand/src/proc_macro_server.rs
@@ -426,6 +426,10 @@ impl server::TokenStream for Rustc<'_, '_> {
         // We don't use `TokenStream::from_ast` as the tokenstream currently cannot
         // be recovered in the general case.
         match &expr.kind {
+            ast::ExprKind::Lit(l) if l.token.kind == token::Bool => {
+                Ok(tokenstream::TokenTree::token(token::Ident(l.token.symbol, false), l.span)
+                    .into())
+            }
             ast::ExprKind::Lit(l) => {
                 Ok(tokenstream::TokenTree::token(token::Literal(l.token), l.span).into())
             }