diff options
Diffstat (limited to 'crates/mbe/src')
-rw-r--r-- | crates/mbe/src/syntax_bridge.rs | 2 | ||||
-rw-r--r-- | crates/mbe/src/tests/expand.rs | 24 |
2 files changed, 23 insertions, 3 deletions
diff --git a/crates/mbe/src/syntax_bridge.rs b/crates/mbe/src/syntax_bridge.rs index 9d433b3b0..cfab99da8 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 { | |||
213 | 213 | ||
214 | // Quote the string | 214 | // Quote the string |
215 | // Note that `tt::Literal` expect an escaped string | 215 | // Note that `tt::Literal` expect an escaped string |
216 | let text = format!("{:?}", text.escape_debug().to_string()); | 216 | let text = format!("\"{}\"", text.escape_debug()); |
217 | text.into() | 217 | text.into() |
218 | } | 218 | } |
219 | 219 | ||
diff --git a/crates/mbe/src/tests/expand.rs b/crates/mbe/src/tests/expand.rs index 8951f3813..84f19d3e2 100644 --- a/crates/mbe/src/tests/expand.rs +++ b/crates/mbe/src/tests/expand.rs | |||
@@ -921,7 +921,7 @@ fn test_meta_doc_comments() { | |||
921 | MultiLines Doc | 921 | MultiLines Doc |
922 | */ | 922 | */ |
923 | }"#, | 923 | }"#, |
924 | "# [doc = \" Single Line Doc 1\"] # [doc = \"\\\\n MultiLines Doc\\\\n \"] fn bar () {}", | 924 | "# [doc = \" Single Line Doc 1\"] # [doc = \"\\n MultiLines Doc\\n \"] fn bar () {}", |
925 | ); | 925 | ); |
926 | } | 926 | } |
927 | 927 | ||
@@ -944,7 +944,27 @@ fn test_meta_doc_comments_non_latin() { | |||
944 | 莊生曉夢迷蝴蝶,望帝春心託杜鵑。 | 944 | 莊生曉夢迷蝴蝶,望帝春心託杜鵑。 |
945 | */ | 945 | */ |
946 | }"#, | 946 | }"#, |
947 | "# [doc = \" 錦瑟無端五十弦,一弦一柱思華年。\"] # [doc = \"\\\\n 莊生曉夢迷蝴蝶,望帝春心託杜鵑。\\\\n \"] fn bar () {}", | 947 | "# [doc = \" 錦瑟無端五十弦,一弦一柱思華年。\"] # [doc = \"\\n 莊生曉夢迷蝴蝶,望帝春心託杜鵑。\\n \"] fn bar () {}", |
948 | ); | ||
949 | } | ||
950 | |||
951 | #[test] | ||
952 | fn test_meta_doc_comments_escaped_characters() { | ||
953 | parse_macro( | ||
954 | r#" | ||
955 | macro_rules! foo { | ||
956 | ($(#[$ i:meta])+) => ( | ||
957 | $(#[$ i])+ | ||
958 | fn bar() {} | ||
959 | ) | ||
960 | } | ||
961 | "#, | ||
962 | ) | ||
963 | .assert_expand_items( | ||
964 | r#"foo! { | ||
965 | /// \ " ' | ||
966 | }"#, | ||
967 | r#"# [doc = " \\ \" \'"] fn bar () {}"#, | ||
948 | ); | 968 | ); |
949 | } | 969 | } |
950 | 970 | ||