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 <edwin0cheng@gmail.com>
This commit is contained in:
bors[bot] 2021-05-09 12:01:35 +00:00 committed by GitHub
commit b43921cddd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View file

@ -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""#]],
);
}
}

View file

@ -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)]