File tree Expand file tree Collapse file tree 3 files changed +22
-21
lines changed Expand file tree Collapse file tree 3 files changed +22
-21
lines changed Original file line number Diff line number Diff line change @@ -302,7 +302,6 @@ impl Attribute {
302
302
if self . tokens . is_empty ( ) {
303
303
return Ok ( Vec :: new ( ) ) ;
304
304
}
305
-
306
305
self . parse ( sess, |p| p. parse_derive_paths ( ) )
307
306
}
308
307
Original file line number Diff line number Diff line change @@ -10,7 +10,6 @@ use crate::attr;
10
10
use crate :: ast;
11
11
use crate :: edition:: Edition ;
12
12
use crate :: mut_visit:: * ;
13
- use crate :: parse:: token;
14
13
use crate :: ptr:: P ;
15
14
use crate :: sess:: ParseSess ;
16
15
use crate :: symbol:: sym;
@@ -112,25 +111,7 @@ impl<'a> StripUnconfigured<'a> {
112
111
return vec ! [ ] ;
113
112
}
114
113
115
- let ( cfg_predicate, expanded_attrs) = match attr. parse ( self . sess , |parser| {
116
- parser. expect ( & token:: OpenDelim ( token:: Paren ) ) ?;
117
-
118
- let cfg_predicate = parser. parse_meta_item ( ) ?;
119
- parser. expect ( & token:: Comma ) ?;
120
-
121
- // Presumably, the majority of the time there will only be one attr.
122
- let mut expanded_attrs = Vec :: with_capacity ( 1 ) ;
123
-
124
- while !parser. check ( & token:: CloseDelim ( token:: Paren ) ) {
125
- let lo = parser. token . span . lo ( ) ;
126
- let item = parser. parse_attr_item ( ) ?;
127
- expanded_attrs. push ( ( item, parser. prev_span . with_lo ( lo) ) ) ;
128
- parser. expect_one_of ( & [ token:: Comma ] , & [ token:: CloseDelim ( token:: Paren ) ] ) ?;
129
- }
130
-
131
- parser. expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
132
- Ok ( ( cfg_predicate, expanded_attrs) )
133
- } ) {
114
+ let ( cfg_predicate, expanded_attrs) = match attr. parse ( self . sess , |p| p. parse_cfg_attr ( ) ) {
134
115
Ok ( result) => result,
135
116
Err ( mut e) => {
136
117
e. emit ( ) ;
Original file line number Diff line number Diff line change @@ -260,6 +260,27 @@ impl<'a> Parser<'a> {
260
260
Ok ( lit)
261
261
}
262
262
263
+ /// Parses `cfg_attr(pred, attr_item_list)` where `attr_item_list` is comma-delimited.
264
+ crate fn parse_cfg_attr ( & mut self ) -> PResult < ' a , ( ast:: MetaItem , Vec < ( ast:: AttrItem , Span ) > ) > {
265
+ self . expect ( & token:: OpenDelim ( token:: Paren ) ) ?;
266
+
267
+ let cfg_predicate = self . parse_meta_item ( ) ?;
268
+ self . expect ( & token:: Comma ) ?;
269
+
270
+ // Presumably, the majority of the time there will only be one attr.
271
+ let mut expanded_attrs = Vec :: with_capacity ( 1 ) ;
272
+
273
+ while !self . check ( & token:: CloseDelim ( token:: Paren ) ) {
274
+ let lo = self . token . span . lo ( ) ;
275
+ let item = self . parse_attr_item ( ) ?;
276
+ expanded_attrs. push ( ( item, self . prev_span . with_lo ( lo) ) ) ;
277
+ self . expect_one_of ( & [ token:: Comma ] , & [ token:: CloseDelim ( token:: Paren ) ] ) ?;
278
+ }
279
+
280
+ self . expect ( & token:: CloseDelim ( token:: Paren ) ) ?;
281
+ Ok ( ( cfg_predicate, expanded_attrs) )
282
+ }
283
+
263
284
/// Matches the following grammar (per RFC 1559).
264
285
///
265
286
/// meta_item : PATH ( '=' UNSUFFIXED_LIT | '(' meta_item_inner? ')' )? ;
You can’t perform that action at this time.
0 commit comments