Skip to content

Commit b43921c

Browse files
Merge #8777
8777: Escape characters in builtin macros correctly r=edwin0cheng a=edwin0cheng Fixes #8749 It is the same bug in #8560 but in our `quote!` macro. Because the "\" are adding exponentially in #8749 case, so the text is eat up all the memory. bors r+ Co-authored-by: Edwin Cheng <[email protected]>
2 parents 6c0cdc5 + 01ce37c commit b43921c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

crates/hir_expand/src/builtin_macro.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,9 +788,9 @@ mod tests {
788788
r##"
789789
#[rustc_builtin_macro]
790790
macro_rules! concat {}
791-
concat!("foo", "r", 0, r#"bar"#, false);
791+
concat!("foo", "r", 0, r#"bar"#, "\n", false);
792792
"##,
793-
expect![[r#""foor0barfalse""#]],
793+
expect![[r#""foor0bar\nfalse""#]],
794794
);
795795
}
796796
}

crates/hir_expand/src/quote.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ impl_to_to_tokentrees! {
196196
tt::Literal => self { self };
197197
tt::Ident => self { self };
198198
tt::Punct => self { self };
199-
&str => self { tt::Literal{text: format!("{:?}", self.escape_default().to_string()).into(), id: tt::TokenId::unspecified()}};
200-
String => self { tt::Literal{text: format!("{:?}", self.escape_default().to_string()).into(), id: tt::TokenId::unspecified()}}
199+
&str => self { tt::Literal{text: format!("\"{}\"", self.escape_debug()).into(), id: tt::TokenId::unspecified()}};
200+
String => self { tt::Literal{text: format!("\"{}\"", self.escape_debug()).into(), id: tt::TokenId::unspecified()}}
201201
}
202202

203203
#[cfg(test)]

0 commit comments

Comments
 (0)