From bf8bc5c882ac4acb5fef4cd7adf50d4233507e83 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sun, 28 Feb 2021 13:49:08 +0800 Subject: Fix non-latin characters doc comment for mbe --- crates/mbe/src/syntax_bridge.rs | 2 +- crates/mbe/src/tests.rs | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'crates/mbe') diff --git a/crates/mbe/src/syntax_bridge.rs b/crates/mbe/src/syntax_bridge.rs index 5a91781fc..aacae1026 100644 --- a/crates/mbe/src/syntax_bridge.rs +++ b/crates/mbe/src/syntax_bridge.rs @@ -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() } diff --git a/crates/mbe/src/tests.rs b/crates/mbe/src/tests.rs index 1c467facd..f1eadcd1e 100644 --- a/crates/mbe/src/tests.rs +++ b/crates/mbe/src/tests.rs @@ -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( -- cgit v1.2.3