From 01ce37c8052136b3a5ab1f703f774a1b293a25b7 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sun, 9 May 2021 19:57:29 +0800 Subject: Escape characters in builtin macros correctly --- crates/hir_expand/src/builtin_macro.rs | 4 ++-- crates/hir_expand/src/quote.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/hir_expand/src') diff --git a/crates/hir_expand/src/builtin_macro.rs b/crates/hir_expand/src/builtin_macro.rs index 179de61f9..0142a06ed 100644 --- a/crates/hir_expand/src/builtin_macro.rs +++ b/crates/hir_expand/src/builtin_macro.rs @@ -788,9 +788,9 @@ mod tests { r##" #[rustc_builtin_macro] macro_rules! concat {} - concat!("foo", "r", 0, r#"bar"#, false); + concat!("foo", "r", 0, r#"bar"#, "\n", false); "##, - expect![[r#""foor0barfalse""#]], + expect![[r#""foor0bar\nfalse""#]], ); } } diff --git a/crates/hir_expand/src/quote.rs b/crates/hir_expand/src/quote.rs index c82487ef0..230a59964 100644 --- a/crates/hir_expand/src/quote.rs +++ b/crates/hir_expand/src/quote.rs @@ -196,8 +196,8 @@ impl_to_to_tokentrees! { tt::Literal => self { self }; tt::Ident => self { self }; tt::Punct => self { self }; - &str => self { tt::Literal{text: format!("{:?}", self.escape_default().to_string()).into(), id: tt::TokenId::unspecified()}}; - String => self { tt::Literal{text: format!("{:?}", self.escape_default().to_string()).into(), id: tt::TokenId::unspecified()}} + &str => self { tt::Literal{text: format!("\"{}\"", self.escape_debug()).into(), id: tt::TokenId::unspecified()}}; + String => self { tt::Literal{text: format!("\"{}\"", self.escape_debug()).into(), id: tt::TokenId::unspecified()}} } #[cfg(test)] -- cgit v1.2.3