7803: Fix non-latin characters doc comment in mbe expansion r=edwin0cheng a=edwin0cheng

Fixes #7781

![Peek 2021-02-28 13-47](https://user-images.githubusercontent.com/11014119/109409237-f58e5580-79cb-11eb-92ed-a6700bbe39b5.gif)

Off-topic: This is a [beautiful poem](http://chinesepoetryinenglishverse.blogspot.com/2013/12/blog-post_4784.html) from by Li Shangyin.

bors r+


Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
This commit is contained in:
bors[bot] 2021-02-28 05:55:06 +00:00 committed by GitHub
commit c412d5f8d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View file

@ -213,7 +213,7 @@ fn doc_comment_text(comment: &ast::Comment) -> SmolStr {
// Quote the string
// Note that `tt::Literal` expect an escaped string
let text = format!("{:?}", text.escape_default().to_string());
let text = format!("{:?}", text.escape_debug().to_string());
text.into()
}

View file

@ -969,6 +969,29 @@ fn test_meta_doc_comments() {
);
}
#[test]
fn test_meta_doc_comments_non_latin() {
parse_macro(
r#"
macro_rules! foo {
($(#[$ i:meta])+) => (
$(#[$ i])+
fn bar() {}
)
}
"#,
).
assert_expand_items(
r#"foo! {
/// 錦瑟無端五十弦,一弦一柱思華年。
/**
*/
}"#,
"# [doc = \" 錦瑟無端五十弦,一弦一柱思華年。\"] # [doc = \"\\\\n 莊生曉夢迷蝴蝶,望帝春心託杜鵑。\\\\n \"] fn bar () {}",
);
}
#[test]
fn test_tt_block() {
parse_macro(