about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-01-25 11:04:23 +0000
committerGitHub <noreply@github.com>2021-01-25 11:04:23 +0000
commit6362b399ad321d8bece357b703e5455de3850e76 (patch)
treec0bc02a09c350985e1b4c81d7357623bcd1f3fd2
parent1cd5a6cd411a5a71db46a7904aa152123b58f30f (diff)
parentee8c67887067657371b8d0b4b971bfe6d9db9313 (diff)
downloadrust-6362b399ad321d8bece357b703e5455de3850e76.tar.gz
rust-6362b399ad321d8bece357b703e5455de3850e76.zip
Merge #7419
7419: Unquote strings when expanding concat! r=matklad a=lnicola

Fixes #7417.

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
-rw-r--r--crates/hir_expand/src/builtin_macro.rs24
1 files changed, 8 insertions, 16 deletions
diff --git a/crates/hir_expand/src/builtin_macro.rs b/crates/hir_expand/src/builtin_macro.rs
index 80b60d59fed..2806842cddf 100644
--- a/crates/hir_expand/src/builtin_macro.rs
+++ b/crates/hir_expand/src/builtin_macro.rs
@@ -327,17 +327,12 @@ fn concat_expand(
                 // concat works with string and char literals, so remove any quotes.
                 // It also works with integer, float and boolean literals, so just use the rest
                 // as-is.
-
-                text += it
-                    .text
-                    .trim_start_matches(|c| match c {
-                        'r' | '#' | '\'' | '"' => true,
-                        _ => false,
-                    })
-                    .trim_end_matches(|c| match c {
-                        '#' | '\'' | '"' => true,
-                        _ => false,
-                    });
+                let component = unquote_str(&it).unwrap_or_else(|| it.text.to_string());
+                text.push_str(&component);
+            }
+            // handle boolean literals
+            tt::TokenTree::Leaf(tt::Leaf::Ident(id)) if i % 2 == 0 => {
+                text.push_str(id.text.as_str());
             }
             tt::TokenTree::Leaf(tt::Leaf::Punct(punct)) if i % 2 == 1 && punct.char == ',' => (),
             _ => {
@@ -345,7 +340,6 @@ fn concat_expand(
             }
         }
     }
-
     ExpandResult { value: Some((quote!(#text), FragmentKind::Expr)), err }
 }
 
@@ -745,12 +739,10 @@ mod tests {
             r##"
             #[rustc_builtin_macro]
             macro_rules! concat {}
-            concat!("foo", 0, r#"bar"#);
+            concat!("foo", r, 0, r#"bar"#, false);
             "##,
         );
 
-        assert_eq!(expanded, r#""foo0bar""#);
-
-        // FIXME: `true`/`false` literals don't work.
+        assert_eq!(expanded, r#""foor0barfalse""#);
     }
 }