Skip to content

Commit d7f1e02

Browse files
SpriteOvOgitbot
authored and
gitbot
committed
Fix proc_macro::quote! for raw ident
1 parent 8c71c64 commit d7f1e02

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

proc_macro/src/quote.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,14 @@ pub fn quote(stream: TokenStream) -> TokenStream {
112112
)), &mut ts);)
113113
}
114114
TokenTree::Ident(tt) => {
115-
minimal_quote!(crate::ToTokens::to_tokens(&crate::TokenTree::Ident(crate::Ident::new(
116-
(@ TokenTree::from(Literal::string(&tt.to_string()))),
115+
let literal = tt.to_string();
116+
let (literal, ctor) = if let Some(stripped) = literal.strip_prefix("r#") {
117+
(stripped, minimal_quote!(crate::Ident::new_raw))
118+
} else {
119+
(literal.as_str(), minimal_quote!(crate::Ident::new))
120+
};
121+
minimal_quote!(crate::ToTokens::to_tokens(&crate::TokenTree::Ident((@ ctor)(
122+
(@ TokenTree::from(Literal::string(literal))),
117123
(@ quote_span(proc_macro_crate.clone(), tt.span())),
118124
)), &mut ts);)
119125
}

0 commit comments

Comments
 (0)