@@ -29,9 +29,9 @@ impl<'a> Parser<'a> {
29
29
let mut attrs: Vec < ast:: Attribute > = Vec :: new ( ) ;
30
30
let mut just_parsed_doc_comment = false ;
31
31
loop {
32
- let ( attr , tokens ) = self . collect_tokens ( |this| {
33
- debug ! ( "parse_outer_attributes: self.token={:?}" , this . token ) ;
34
- if this . check ( & token :: Pound ) {
32
+ debug ! ( "parse_outer_attributes: self.token={:?}" , self . token ) ;
33
+ let ( attr , tokens ) = if self . check ( & token:: Pound ) {
34
+ self . collect_tokens ( |this| {
35
35
let inner_error_reason = if just_parsed_doc_comment {
36
36
"an inner attribute is not permitted following an outer doc comment"
37
37
} else if !attrs. is_empty ( ) {
@@ -47,7 +47,9 @@ impl<'a> Parser<'a> {
47
47
let attr = this. parse_attribute_with_inner_parse_policy ( inner_parse_policy) ?;
48
48
just_parsed_doc_comment = false ;
49
49
Ok ( Some ( attr) )
50
- } else if let token:: DocComment ( comment_kind, attr_style, data) = this. token . kind {
50
+ } ) ?
51
+ } else if let token:: DocComment ( comment_kind, attr_style, data) = self . token . kind {
52
+ self . collect_tokens ( |this| {
51
53
let attr =
52
54
attr:: mk_doc_comment ( comment_kind, attr_style, data, this. token . span ) ;
53
55
if attr. style != ast:: AttrStyle :: Outer {
@@ -67,10 +69,11 @@ impl<'a> Parser<'a> {
67
69
this. bump ( ) ;
68
70
just_parsed_doc_comment = true ;
69
71
Ok ( Some ( attr) )
70
- } else {
71
- Ok ( None )
72
- }
73
- } ) ?;
72
+ } ) ?
73
+ } else {
74
+ ( None , None )
75
+ } ;
76
+
74
77
if let Some ( mut attr) = attr {
75
78
attr. tokens = tokens;
76
79
attrs. push ( attr) ;
@@ -192,26 +195,29 @@ impl<'a> Parser<'a> {
192
195
crate fn parse_inner_attributes ( & mut self ) -> PResult < ' a , Vec < ast:: Attribute > > {
193
196
let mut attrs: Vec < ast:: Attribute > = vec ! [ ] ;
194
197
loop {
195
- let ( attr, tokens) = self . collect_tokens ( |this| {
196
- // Only try to parse if it is an inner attribute (has `!`).
197
- if this. check ( & token:: Pound ) && this. look_ahead ( 1 , |t| t == & token:: Not ) {
198
- let attr = this. parse_attribute ( true ) ?;
199
- assert_eq ! ( attr. style, ast:: AttrStyle :: Inner ) ;
200
- Ok ( Some ( attr) )
201
- } else if let token:: DocComment ( comment_kind, attr_style, data) = this. token . kind {
202
- // We need to get the position of this token before we bump.
203
- let attr =
204
- attr:: mk_doc_comment ( comment_kind, attr_style, data, this. token . span ) ;
205
- if attr. style == ast:: AttrStyle :: Inner {
206
- this. bump ( ) ;
198
+ // Only try to parse if it is an inner attribute (has `!`).
199
+ let ( attr, tokens) =
200
+ if self . check ( & token:: Pound ) && self . look_ahead ( 1 , |t| t == & token:: Not ) {
201
+ self . collect_tokens ( |this| {
202
+ let attr = this. parse_attribute ( true ) ?;
203
+ assert_eq ! ( attr. style, ast:: AttrStyle :: Inner ) ;
207
204
Ok ( Some ( attr) )
208
- } else {
209
- Ok ( None )
210
- }
205
+ } ) ?
206
+ } else if let token:: DocComment ( comment_kind, attr_style, data) = self . token . kind {
207
+ self . collect_tokens ( |this| {
208
+ // We need to get the position of this token before we bump.
209
+ let attr =
210
+ attr:: mk_doc_comment ( comment_kind, attr_style, data, this. token . span ) ;
211
+ if attr. style == ast:: AttrStyle :: Inner {
212
+ this. bump ( ) ;
213
+ Ok ( Some ( attr) )
214
+ } else {
215
+ Ok ( None )
216
+ }
217
+ } ) ?
211
218
} else {
212
- Ok ( None )
213
- }
214
- } ) ?;
219
+ ( None , None )
220
+ } ;
215
221
if let Some ( mut attr) = attr {
216
222
attr. tokens = tokens;
217
223
attrs. push ( attr) ;
0 commit comments