File tree Expand file tree Collapse file tree 4 files changed +29
-3
lines changed
tests/ui/proc-macro/quote Expand file tree Collapse file tree 4 files changed +29
-3
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ pub fn run_tests(_: TokenStream) -> TokenStream {
3434 test_inner_block_comment ( ) ;
3535 test_outer_attr ( ) ;
3636 test_inner_attr ( ) ;
37- // test_quote_raw_id(); // FIXME: Fix it in a subsequent commit
37+ test_quote_raw_id ( ) ;
3838
3939 TokenStream :: new ( )
4040}
Original file line number Diff line number Diff line change @@ -15,5 +15,6 @@ extern crate proc_macro;
1515fn main ( ) {
1616 proc_macro:: quote! {
1717 let hello = "world" ;
18+ let r#raw_ident = r#"raw"literal"# ;
1819 }
1920}
Original file line number Diff line number Diff line change @@ -40,6 +40,25 @@ fn main() {
4040 }), &mut ts);
4141 crate::ToTokens::to_tokens(&crate::TokenTree::Punct(crate::Punct::new(';',
4242 crate::Spacing::Alone)), &mut ts);
43+ crate::ToTokens::to_tokens(&crate::TokenTree::Ident(crate::Ident::new("let",
44+ crate::Span::recover_proc_macro_span(3))), &mut ts);
45+ crate::ToTokens::to_tokens(&crate::TokenTree::Ident(crate::Ident::new_raw("raw_ident",
46+ crate::Span::recover_proc_macro_span(4))), &mut ts);
47+ crate::ToTokens::to_tokens(&crate::TokenTree::Punct(crate::Punct::new('=',
48+ crate::Spacing::Alone)), &mut ts);
49+ crate::ToTokens::to_tokens(&crate::TokenTree::Literal({
50+ let mut iter =
51+ "r#\"raw\"literal\"#".parse::<crate::TokenStream>().unwrap().into_iter();
52+ if let (Some(crate::TokenTree::Literal(mut lit)), None) =
53+ (iter.next(), iter.next()) {
54+ lit.set_span(crate::Span::recover_proc_macro_span(5));
55+ lit
56+ } else {
57+ ::core::panicking::panic("internal error: entered unreachable code")
58+ }
59+ }), &mut ts);
60+ crate::ToTokens::to_tokens(&crate::TokenTree::Punct(crate::Punct::new(';',
61+ crate::Spacing::Alone)), &mut ts);
4362 ts
4463 }
4564}
You can’t perform that action at this time.
0 commit comments