From 4e92681aba42aa50a832ec3be547b31a9bbf20e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 25 Jan 2021 13:30:55 +0200 Subject: [PATCH] Disallow non-boolean literals in concat! --- crates/hir_expand/src/builtin_macro.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/hir_expand/src/builtin_macro.rs b/crates/hir_expand/src/builtin_macro.rs index 2806842cdd..57bc6fbd78 100644 --- a/crates/hir_expand/src/builtin_macro.rs +++ b/crates/hir_expand/src/builtin_macro.rs @@ -331,7 +331,9 @@ fn concat_expand( text.push_str(&component); } // handle boolean literals - tt::TokenTree::Leaf(tt::Leaf::Ident(id)) if i % 2 == 0 => { + tt::TokenTree::Leaf(tt::Leaf::Ident(id)) + if i % 2 == 0 && (id.text == "true" || id.text == "false") => + { text.push_str(id.text.as_str()); } tt::TokenTree::Leaf(tt::Leaf::Punct(punct)) if i % 2 == 1 && punct.char == ',' => (), @@ -739,7 +741,7 @@ mod tests { r##" #[rustc_builtin_macro] macro_rules! concat {} - concat!("foo", r, 0, r#"bar"#, false); + concat!("foo", "r", 0, r#"bar"#, false); "##, );