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 {
302302 if self . tokens . is_empty ( ) {
303303 return Ok ( Vec :: new ( ) ) ;
304304 }
305-
306305 self . parse ( sess, |p| p. parse_derive_paths ( ) )
307306 }
308307
Original file line number Diff line number Diff line change @@ -10,7 +10,6 @@ use crate::attr;
1010use crate :: ast;
1111use crate :: edition:: Edition ;
1212use crate :: mut_visit:: * ;
13- use crate :: parse:: token;
1413use crate :: ptr:: P ;
1514use crate :: sess:: ParseSess ;
1615use crate :: symbol:: sym;
@@ -112,25 +111,7 @@ impl<'a> StripUnconfigured<'a> {
112111 return vec ! [ ] ;
113112 }
114113
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 ( ) ) {
134115 Ok ( result) => result,
135116 Err ( mut e) => {
136117 e. emit ( ) ;
Original file line number Diff line number Diff line change @@ -260,6 +260,27 @@ impl<'a> Parser<'a> {
260260 Ok ( lit)
261261 }
262262
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+
263284 /// Matches the following grammar (per RFC 1559).
264285 ///
265286 /// meta_item : PATH ( '=' UNSUFFIXED_LIT | '(' meta_item_inner? ')' )? ;
You can’t perform that action at this time.
0 commit comments