Fix raw ident handling (a little)

This commit is contained in:
Amos Wenger 2022-07-21 19:13:44 +02:00
parent 941416a1d6
commit 246947b779
2 changed files with 11 additions and 4 deletions

View file

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

View file

@ -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());