@@ -11,7 +11,7 @@ use rustc_expand::base::{Annotatable, ExtCtxt};
11
11
use rustc_expand:: config:: StripUnconfigured ;
12
12
use rustc_expand:: configure;
13
13
use rustc_feature:: Features ;
14
- use rustc_parse:: parser:: ForceCollect ;
14
+ use rustc_parse:: parser:: { ForceCollect , Parser } ;
15
15
use rustc_session:: utils:: FlattenNonterminals ;
16
16
use rustc_session:: Session ;
17
17
use rustc_span:: symbol:: sym;
@@ -138,8 +138,34 @@ impl CfgEval<'_, '_> {
138
138
// the location of `#[cfg]` and `#[cfg_attr]` in the token stream. The tokenization
139
139
// process is lossless, so this process is invisible to proc-macros.
140
140
141
- // FIXME - get rid of this clone
142
- let nt = annotatable. clone ( ) . into_nonterminal ( ) ;
141
+ let parse_annotatable_with: fn ( & mut Parser < ' _ > ) -> _ = match annotatable {
142
+ Annotatable :: Item ( _) => {
143
+ |parser| Annotatable :: Item ( parser. parse_item ( ForceCollect :: Yes ) . unwrap ( ) . unwrap ( ) )
144
+ }
145
+ Annotatable :: TraitItem ( _) => |parser| {
146
+ Annotatable :: TraitItem (
147
+ parser. parse_trait_item ( ForceCollect :: Yes ) . unwrap ( ) . unwrap ( ) . unwrap ( ) ,
148
+ )
149
+ } ,
150
+ Annotatable :: ImplItem ( _) => |parser| {
151
+ Annotatable :: ImplItem (
152
+ parser. parse_impl_item ( ForceCollect :: Yes ) . unwrap ( ) . unwrap ( ) . unwrap ( ) ,
153
+ )
154
+ } ,
155
+ Annotatable :: ForeignItem ( _) => |parser| {
156
+ Annotatable :: ForeignItem (
157
+ parser. parse_foreign_item ( ForceCollect :: Yes ) . unwrap ( ) . unwrap ( ) . unwrap ( ) ,
158
+ )
159
+ } ,
160
+ Annotatable :: Stmt ( _) => |parser| {
161
+ Annotatable :: Stmt ( P ( parser. parse_stmt ( ForceCollect :: Yes ) . unwrap ( ) . unwrap ( ) ) )
162
+ } ,
163
+ Annotatable :: Expr ( _) => {
164
+ |parser| Annotatable :: Expr ( parser. parse_expr_force_collect ( ) . unwrap ( ) )
165
+ }
166
+ _ => unreachable ! ( ) ,
167
+ } ;
168
+ let nt = annotatable. into_nonterminal ( ) ;
143
169
144
170
let mut orig_tokens = rustc_parse:: nt_to_tokenstream (
145
171
& nt,
@@ -173,25 +199,7 @@ impl CfgEval<'_, '_> {
173
199
let mut parser =
174
200
rustc_parse:: stream_to_parser ( & self . cfg . sess . parse_sess , orig_tokens, None ) ;
175
201
parser. capture_cfg = true ;
176
- annotatable = match annotatable {
177
- Annotatable :: Item ( _) => {
178
- Annotatable :: Item ( parser. parse_item ( ForceCollect :: Yes ) . unwrap ( ) . unwrap ( ) )
179
- }
180
- Annotatable :: TraitItem ( _) => Annotatable :: TraitItem (
181
- parser. parse_trait_item ( ForceCollect :: Yes ) . unwrap ( ) . unwrap ( ) . unwrap ( ) ,
182
- ) ,
183
- Annotatable :: ImplItem ( _) => Annotatable :: ImplItem (
184
- parser. parse_impl_item ( ForceCollect :: Yes ) . unwrap ( ) . unwrap ( ) . unwrap ( ) ,
185
- ) ,
186
- Annotatable :: ForeignItem ( _) => Annotatable :: ForeignItem (
187
- parser. parse_foreign_item ( ForceCollect :: Yes ) . unwrap ( ) . unwrap ( ) . unwrap ( ) ,
188
- ) ,
189
- Annotatable :: Stmt ( _) => {
190
- Annotatable :: Stmt ( P ( parser. parse_stmt ( ForceCollect :: Yes ) . unwrap ( ) . unwrap ( ) ) )
191
- }
192
- Annotatable :: Expr ( _) => Annotatable :: Expr ( parser. parse_expr_force_collect ( ) . unwrap ( ) ) ,
193
- _ => unreachable ! ( ) ,
194
- } ;
202
+ annotatable = parse_annotatable_with ( & mut parser) ;
195
203
196
204
// Now that we have our re-parsed `AttrAnnotatedTokenStream`, recursively configuring
197
205
// our attribute target will correctly the tokens as well.
0 commit comments