@@ -90,21 +90,9 @@ impl<'a> Parser<'a> {
90
90
return Ok ( Some ( self . mk_stmt ( lo. to ( item. span ) , StmtKind :: Item ( item) ) ) ) ;
91
91
}
92
92
93
- let unused_attrs = |attrs : & [ Attribute ] , s : & mut Self | {
94
- if !attrs. is_empty ( ) {
95
- if s. prev_token_kind == PrevTokenKind :: DocComment {
96
- s. span_fatal_err ( s. prev_span , Error :: UselessDocComment ) . emit ( ) ;
97
- } else if attrs. iter ( ) . any ( |a| a. style == AttrStyle :: Outer ) {
98
- s. span_err (
99
- s. token . span , "expected statement after outer attribute"
100
- ) ;
101
- }
102
- }
103
- } ;
104
-
105
93
// Do not attempt to parse an expression if we're done here.
106
94
if self . token == token:: Semi {
107
- unused_attrs ( & attrs, self ) ;
95
+ self . error_outer_attrs ( & attrs) ;
108
96
self . bump ( ) ;
109
97
let mut last_semi = lo;
110
98
while self . token == token:: Semi {
@@ -122,7 +110,7 @@ impl<'a> Parser<'a> {
122
110
}
123
111
124
112
if self . token == token:: CloseDelim ( token:: Brace ) {
125
- unused_attrs ( & attrs, self ) ;
113
+ self . error_outer_attrs ( & attrs) ;
126
114
return Ok ( None ) ;
127
115
}
128
116
@@ -190,6 +178,18 @@ impl<'a> Parser<'a> {
190
178
Ok ( Some ( self . mk_stmt ( lo. to ( hi) , kind) ) )
191
179
}
192
180
181
+ /// Error on outer attributes in this context.
182
+ /// Also error if the previous token was a doc comment.
183
+ fn error_outer_attrs ( & self , attrs : & [ Attribute ] ) {
184
+ if !attrs. is_empty ( ) {
185
+ if self . prev_token_kind == PrevTokenKind :: DocComment {
186
+ self . span_fatal_err ( self . prev_span , Error :: UselessDocComment ) . emit ( ) ;
187
+ } else if attrs. iter ( ) . any ( |a| a. style == AttrStyle :: Outer ) {
188
+ self . span_err ( self . token . span , "expected statement after outer attribute" ) ;
189
+ }
190
+ }
191
+ }
192
+
193
193
/// Parses a local variable declaration.
194
194
fn parse_local ( & mut self , attrs : ThinVec < Attribute > ) -> PResult < ' a , P < Local > > {
195
195
let lo = self . prev_span ;
0 commit comments