about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAmos Wenger <amoswenger@gmail.com>2022-07-21 19:13:44 +0200
committerAmos Wenger <amoswenger@gmail.com>2022-07-21 19:13:44 +0200
commit246947b7791fd470e8e49c08d30c4c740eb62bc5 (patch)
treecb1f90386ca1c60f8d929f703684d40c6f80cab5
parent941416a1d6a07141dd25eaf608d8fa47ad8a4dec (diff)
downloadrust-246947b7791fd470e8e49c08d30c4c740eb62bc5.tar.gz
rust-246947b7791fd470e8e49c08d30c4c740eb62bc5.zip
Fix raw ident handling (a little)
-rw-r--r--crates/proc-macro-srv/src/tests/mod.rs6
-rw-r--r--crates/proc-macro-test/imp/src/lib.rs9
2 files changed, 11 insertions, 4 deletions
diff --git a/crates/proc-macro-srv/src/tests/mod.rs b/crates/proc-macro-srv/src/tests/mod.rs
index 1277106d71d..07222907f08 100644
--- a/crates/proc-macro-srv/src/tests/mod.rs
+++ b/crates/proc-macro-srv/src/tests/mod.rs
@@ -60,10 +60,10 @@ fn test_fn_like_macro_clone_ident_subtree() {
 fn test_fn_like_macro_clone_raw_ident() {
     assert_expand(
         "fn_like_clone_tokens",
-        "r#\"ident\"#",
-        expect![[r##"
+        "r#async",
+        expect![[r#"
             SUBTREE $
-              LITERAL r#"ident"# 4294967295"##]],
+              IDENT   async 4294967295"#]],
     );
 }
 
diff --git a/crates/proc-macro-test/imp/src/lib.rs b/crates/proc-macro-test/imp/src/lib.rs
index 7760774a3fc..feeacdb6407 100644
--- a/crates/proc-macro-test/imp/src/lib.rs
+++ b/crates/proc-macro-test/imp/src/lib.rs
@@ -90,7 +90,14 @@ fn clone_tree(t: TokenTree) -> TokenTree {
             new.set_span(orig.span());
             TokenTree::Group(new)
         }
-        TokenTree::Ident(orig) => TokenTree::Ident(Ident::new(&orig.to_string(), orig.span())),
+        TokenTree::Ident(orig) => {
+            let s = orig.to_string();
+            if let Some(rest) = s.strip_prefix("r#") {
+                TokenTree::Ident(Ident::new_raw(rest, orig.span()))
+            } else {
+                TokenTree::Ident(Ident::new(&s, orig.span()))
+            }
+        }
         TokenTree::Punct(orig) => {
             let mut new = Punct::new(orig.as_char(), orig.spacing());
             new.set_span(orig.span());