6
6
7
7
use crate :: { Delimiter , Group , Ident , Literal , Punct , Spacing , Span , TokenStream , TokenTree } ;
8
8
9
- macro_rules! quote_tt {
10
- ( ( $( $t: tt) * ) ) => { Group :: new( Delimiter :: Parenthesis , quote !( $( $t) * ) ) } ;
11
- ( [ $( $t: tt) * ] ) => { Group :: new( Delimiter :: Bracket , quote !( $( $t) * ) ) } ;
12
- ( { $( $t: tt) * } ) => { Group :: new( Delimiter :: Brace , quote !( $( $t) * ) ) } ;
9
+ macro_rules! minimal_quote_tt {
10
+ ( ( $( $t: tt) * ) ) => { Group :: new( Delimiter :: Parenthesis , minimal_quote !( $( $t) * ) ) } ;
11
+ ( [ $( $t: tt) * ] ) => { Group :: new( Delimiter :: Bracket , minimal_quote !( $( $t) * ) ) } ;
12
+ ( { $( $t: tt) * } ) => { Group :: new( Delimiter :: Brace , minimal_quote !( $( $t) * ) ) } ;
13
13
( , ) => { Punct :: new( ',' , Spacing :: Alone ) } ;
14
14
( . ) => { Punct :: new( '.' , Spacing :: Alone ) } ;
15
15
( ; ) => { Punct :: new( ';' , Spacing :: Alone ) } ;
@@ -21,7 +21,7 @@ macro_rules! quote_tt {
21
21
( $i: ident) => { Ident :: new( stringify!( $i) , Span :: def_site( ) ) } ;
22
22
}
23
23
24
- macro_rules! quote_ts {
24
+ macro_rules! minimal_quote_ts {
25
25
( ( @ $( $t: tt) * ) ) => { $( $t) * } ;
26
26
( :: ) => {
27
27
[
@@ -35,7 +35,7 @@ macro_rules! quote_ts {
35
35
} )
36
36
. collect:: <TokenStream >( )
37
37
} ;
38
- ( $t: tt) => { TokenTree :: from( quote_tt !( $t) ) } ;
38
+ ( $t: tt) => { TokenTree :: from( minimal_quote_tt !( $t) ) } ;
39
39
}
40
40
41
41
/// Simpler version of the real `quote!` macro, implemented solely
@@ -46,11 +46,11 @@ macro_rules! quote_ts {
46
46
///
47
47
/// Note: supported tokens are a subset of the real `quote!`, but
48
48
/// unquoting is different: instead of `$x`, this uses `(@ expr)`.
49
- macro_rules! quote {
49
+ macro_rules! minimal_quote {
50
50
( ) => { TokenStream :: new( ) } ;
51
51
( $( $t: tt) * ) => {
52
52
[
53
- $( TokenStream :: from( quote_ts !( $t) ) , ) *
53
+ $( TokenStream :: from( minimal_quote_ts !( $t) ) , ) *
54
54
] . iter( ) . cloned( ) . collect:: <TokenStream >( )
55
55
} ;
56
56
}
@@ -62,9 +62,9 @@ macro_rules! quote {
62
62
#[ unstable( feature = "proc_macro_quote" , issue = "54722" ) ]
63
63
pub fn quote ( stream : TokenStream ) -> TokenStream {
64
64
if stream. is_empty ( ) {
65
- return quote ! ( crate :: TokenStream :: new( ) ) ;
65
+ return minimal_quote ! ( crate :: TokenStream :: new( ) ) ;
66
66
}
67
- let proc_macro_crate = quote ! ( crate ) ;
67
+ let proc_macro_crate = minimal_quote ! ( crate ) ;
68
68
let mut after_dollar = false ;
69
69
let tokens = stream
70
70
. into_iter ( )
@@ -73,7 +73,7 @@ pub fn quote(stream: TokenStream) -> TokenStream {
73
73
after_dollar = false ;
74
74
match tree {
75
75
TokenTree :: Ident ( _) => {
76
- return Some ( quote ! ( Into :: <crate :: TokenStream >:: into(
76
+ return Some ( minimal_quote ! ( Into :: <crate :: TokenStream >:: into(
77
77
Clone :: clone( & ( @ tree) ) ) , ) ) ;
78
78
}
79
79
TokenTree :: Punct ( ref tt) if tt. as_char ( ) == '$' => { }
@@ -86,28 +86,28 @@ pub fn quote(stream: TokenStream) -> TokenStream {
86
86
}
87
87
}
88
88
89
- Some ( quote ! ( crate :: TokenStream :: from( ( @ match tree {
90
- TokenTree :: Punct ( tt) => quote !( crate :: TokenTree :: Punct ( crate :: Punct :: new(
89
+ Some ( minimal_quote ! ( crate :: TokenStream :: from( ( @ match tree {
90
+ TokenTree :: Punct ( tt) => minimal_quote !( crate :: TokenTree :: Punct ( crate :: Punct :: new(
91
91
( @ TokenTree :: from( Literal :: character( tt. as_char( ) ) ) ) ,
92
92
( @ match tt. spacing( ) {
93
- Spacing :: Alone => quote !( crate :: Spacing :: Alone ) ,
94
- Spacing :: Joint => quote !( crate :: Spacing :: Joint ) ,
93
+ Spacing :: Alone => minimal_quote !( crate :: Spacing :: Alone ) ,
94
+ Spacing :: Joint => minimal_quote !( crate :: Spacing :: Joint ) ,
95
95
} ) ,
96
96
) ) ) ,
97
- TokenTree :: Group ( tt) => quote !( crate :: TokenTree :: Group ( crate :: Group :: new(
97
+ TokenTree :: Group ( tt) => minimal_quote !( crate :: TokenTree :: Group ( crate :: Group :: new(
98
98
( @ match tt. delimiter( ) {
99
- Delimiter :: Parenthesis => quote !( crate :: Delimiter :: Parenthesis ) ,
100
- Delimiter :: Brace => quote !( crate :: Delimiter :: Brace ) ,
101
- Delimiter :: Bracket => quote !( crate :: Delimiter :: Bracket ) ,
102
- Delimiter :: None => quote !( crate :: Delimiter :: None ) ,
99
+ Delimiter :: Parenthesis => minimal_quote !( crate :: Delimiter :: Parenthesis ) ,
100
+ Delimiter :: Brace => minimal_quote !( crate :: Delimiter :: Brace ) ,
101
+ Delimiter :: Bracket => minimal_quote !( crate :: Delimiter :: Bracket ) ,
102
+ Delimiter :: None => minimal_quote !( crate :: Delimiter :: None ) ,
103
103
} ) ,
104
104
( @ quote( tt. stream( ) ) ) ,
105
105
) ) ) ,
106
- TokenTree :: Ident ( tt) => quote !( crate :: TokenTree :: Ident ( crate :: Ident :: new(
106
+ TokenTree :: Ident ( tt) => minimal_quote !( crate :: TokenTree :: Ident ( crate :: Ident :: new(
107
107
( @ TokenTree :: from( Literal :: string( & tt. to_string( ) ) ) ) ,
108
108
( @ quote_span( proc_macro_crate. clone( ) , tt. span( ) ) ) ,
109
109
) ) ) ,
110
- TokenTree :: Literal ( tt) => quote !( crate :: TokenTree :: Literal ( {
110
+ TokenTree :: Literal ( tt) => minimal_quote !( crate :: TokenTree :: Literal ( {
111
111
let mut iter = ( @ TokenTree :: from( Literal :: string( & tt. to_string( ) ) ) )
112
112
. parse:: <crate :: TokenStream >( )
113
113
. unwrap( )
@@ -129,13 +129,13 @@ pub fn quote(stream: TokenStream) -> TokenStream {
129
129
panic ! ( "unexpected trailing `$` in `quote!`" ) ;
130
130
}
131
131
132
- quote ! ( [ ( @ tokens) ] . iter( ) . cloned( ) . collect:: <crate :: TokenStream >( ) )
132
+ minimal_quote ! ( [ ( @ tokens) ] . iter( ) . cloned( ) . collect:: <crate :: TokenStream >( ) )
133
133
}
134
134
135
135
/// Quote a `Span` into a `TokenStream`.
136
136
/// This is needed to implement a custom quoter.
137
137
#[ unstable( feature = "proc_macro_quote" , issue = "54722" ) ]
138
138
pub fn quote_span ( proc_macro_crate : TokenStream , span : Span ) -> TokenStream {
139
139
let id = span. save_span ( ) ;
140
- quote ! ( ( @ proc_macro_crate ) :: Span :: recover_proc_macro_span( ( @ TokenTree :: from( Literal :: usize_unsuffixed( id) ) ) ) )
140
+ minimal_quote ! ( ( @ proc_macro_crate ) :: Span :: recover_proc_macro_span( ( @ TokenTree :: from( Literal :: usize_unsuffixed( id) ) ) ) )
141
141
}
0 commit comments