Skip to content

Commit

Permalink
Fix proc_macro::quote! for raw ident
Browse files Browse the repository at this point in the history
  • Loading branch information
SpriteOvO authored and gitbot committed Feb 20, 2025
1 parent 3b536f1 commit 3d9dd4e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions proc_macro/src/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,14 @@ pub fn quote(stream: TokenStream) -> TokenStream {
)), &mut ts);)
}
TokenTree::Ident(tt) => {
minimal_quote!(crate::ToTokens::to_tokens(&crate::TokenTree::Ident(crate::Ident::new(
(@ TokenTree::from(Literal::string(&tt.to_string()))),
let literal = tt.to_string();
let (literal, ctor) = if let Some(stripped) = literal.strip_prefix("r#") {
(stripped, minimal_quote!(crate::Ident::new_raw))
} else {
(literal.as_str(), minimal_quote!(crate::Ident::new))
};
minimal_quote!(crate::ToTokens::to_tokens(&crate::TokenTree::Ident((@ ctor)(
(@ TokenTree::from(Literal::string(literal))),
(@ quote_span(proc_macro_crate.clone(), tt.span())),
)), &mut ts);)
}
Expand Down

0 comments on commit 3d9dd4e

Please sign in to comment.