File tree 4 files changed +29
-3
lines changed
tests/ui/proc-macro/quote
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 {
112
112
) ) , & mut ts) ; )
113
113
}
114
114
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) ) ) ,
117
123
( @ quote_span( proc_macro_crate. clone( ) , tt. span( ) ) ) ,
118
124
) ) , & mut ts) ; )
119
125
}
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ pub fn run_tests(_: TokenStream) -> TokenStream {
34
34
test_inner_block_comment ( ) ;
35
35
test_outer_attr ( ) ;
36
36
test_inner_attr ( ) ;
37
- // test_quote_raw_id(); // FIXME: Fix it in a subsequent commit
37
+ test_quote_raw_id ( ) ;
38
38
39
39
TokenStream :: new ( )
40
40
}
Original file line number Diff line number Diff line change @@ -15,5 +15,6 @@ extern crate proc_macro;
15
15
fn main ( ) {
16
16
proc_macro:: quote! {
17
17
let hello = "world" ;
18
+ let r#raw_ident = r#"raw"literal"# ;
18
19
}
19
20
}
Original file line number Diff line number Diff line change @@ -40,6 +40,25 @@ fn main() {
40
40
}), &mut ts);
41
41
crate::ToTokens::to_tokens(&crate::TokenTree::Punct(crate::Punct::new(';',
42
42
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);
43
62
ts
44
63
}
45
64
}
You can’t perform that action at this time.
0 commit comments