@@ -2131,14 +2131,14 @@ impl<'a> Parser<'a> {
2131
2131
} else {
2132
2132
Ok ( self . mk_expr ( span, ExprKind :: Tup ( es) , attrs) )
2133
2133
}
2134
- } ,
2134
+ }
2135
2135
token:: OpenDelim ( token:: Brace ) => {
2136
2136
return self . parse_block_expr ( lo, BlockCheckMode :: Default , attrs) ;
2137
- } ,
2138
- token:: BinOp ( token:: Or ) | token:: OrOr => {
2137
+ }
2138
+ token:: BinOp ( token:: Or ) | token:: OrOr => {
2139
2139
let lo = self . span ;
2140
2140
return self . parse_lambda_expr ( lo, CaptureBy :: Ref , attrs) ;
2141
- } ,
2141
+ }
2142
2142
token:: OpenDelim ( token:: Bracket ) => {
2143
2143
self . bump ( ) ;
2144
2144
@@ -2387,7 +2387,6 @@ impl<'a> Parser<'a> {
2387
2387
pub fn parse_block_expr ( & mut self , lo : Span , blk_mode : BlockCheckMode ,
2388
2388
outer_attrs : ThinVec < Attribute > )
2389
2389
-> PResult < ' a , P < Expr > > {
2390
-
2391
2390
self . expect ( & token:: OpenDelim ( token:: Brace ) ) ?;
2392
2391
2393
2392
let mut attrs = outer_attrs;
@@ -2421,6 +2420,12 @@ impl<'a> Parser<'a> {
2421
2420
expr. map ( |mut expr| {
2422
2421
attrs. extend :: < Vec < _ > > ( expr. attrs . into ( ) ) ;
2423
2422
expr. attrs = attrs;
2423
+ if if let Some ( ref doc) = expr. attrs . iter ( ) . find ( |x| x. is_sugared_doc ) {
2424
+ self . span_fatal_err ( doc. span , Error :: UselessDocComment ) . emit ( ) ;
2425
+ true
2426
+ } else { false } {
2427
+ return expr;
2428
+ }
2424
2429
match expr. node {
2425
2430
ExprKind :: If ( ..) | ExprKind :: IfLet ( ..) => {
2426
2431
if !expr. attrs . is_empty ( ) {
@@ -3105,6 +3110,9 @@ impl<'a> Parser<'a> {
3105
3110
3106
3111
// `else` token already eaten
3107
3112
pub fn parse_else_expr ( & mut self ) -> PResult < ' a , P < Expr > > {
3113
+ if self . prev_token_kind == PrevTokenKind :: DocComment {
3114
+ return Err ( self . span_fatal_err ( self . span , Error :: UselessDocComment ) ) ;
3115
+ }
3108
3116
if self . eat_keyword ( keywords:: If ) {
3109
3117
return self . parse_if_expr ( ThinVec :: new ( ) ) ;
3110
3118
} else {
@@ -3118,6 +3126,9 @@ impl<'a> Parser<'a> {
3118
3126
span_lo : Span ,
3119
3127
mut attrs : ThinVec < Attribute > ) -> PResult < ' a , P < Expr > > {
3120
3128
// Parse: `for <src_pat> in <src_expr> <src_loop_block>`
3129
+ if let Some ( doc) = attrs. iter ( ) . find ( |x| x. is_sugared_doc ) {
3130
+ self . span_fatal_err ( doc. span , Error :: UselessDocComment ) . emit ( ) ;
3131
+ }
3121
3132
3122
3133
let pat = self . parse_pat ( ) ?;
3123
3134
self . expect_keyword ( keywords:: In ) ?;
@@ -3133,6 +3144,9 @@ impl<'a> Parser<'a> {
3133
3144
pub fn parse_while_expr ( & mut self , opt_ident : Option < ast:: SpannedIdent > ,
3134
3145
span_lo : Span ,
3135
3146
mut attrs : ThinVec < Attribute > ) -> PResult < ' a , P < Expr > > {
3147
+ if let Some ( doc) = attrs. iter ( ) . find ( |x| x. is_sugared_doc ) {
3148
+ self . span_fatal_err ( doc. span , Error :: UselessDocComment ) . emit ( ) ;
3149
+ }
3136
3150
if self . token . is_keyword ( keywords:: Let ) {
3137
3151
return self . parse_while_let_expr ( opt_ident, span_lo, attrs) ;
3138
3152
}
@@ -3161,6 +3175,9 @@ impl<'a> Parser<'a> {
3161
3175
pub fn parse_loop_expr ( & mut self , opt_ident : Option < ast:: SpannedIdent > ,
3162
3176
span_lo : Span ,
3163
3177
mut attrs : ThinVec < Attribute > ) -> PResult < ' a , P < Expr > > {
3178
+ if let Some ( doc) = attrs. iter ( ) . find ( |x| x. is_sugared_doc ) {
3179
+ self . span_fatal_err ( doc. span , Error :: UselessDocComment ) . emit ( ) ;
3180
+ }
3164
3181
let ( iattrs, body) = self . parse_inner_attrs_and_block ( ) ?;
3165
3182
attrs. extend ( iattrs) ;
3166
3183
let span = span_lo. to ( body. span ) ;
@@ -3171,13 +3188,19 @@ impl<'a> Parser<'a> {
3171
3188
pub fn parse_catch_expr ( & mut self , span_lo : Span , mut attrs : ThinVec < Attribute > )
3172
3189
-> PResult < ' a , P < Expr > >
3173
3190
{
3191
+ if let Some ( doc) = attrs. iter ( ) . find ( |x| x. is_sugared_doc ) {
3192
+ self . span_fatal_err ( doc. span , Error :: UselessDocComment ) . emit ( ) ;
3193
+ }
3174
3194
let ( iattrs, body) = self . parse_inner_attrs_and_block ( ) ?;
3175
3195
attrs. extend ( iattrs) ;
3176
3196
Ok ( self . mk_expr ( span_lo. to ( body. span ) , ExprKind :: Catch ( body) , attrs) )
3177
3197
}
3178
3198
3179
3199
// `match` token already eaten
3180
3200
fn parse_match_expr ( & mut self , mut attrs : ThinVec < Attribute > ) -> PResult < ' a , P < Expr > > {
3201
+ if let Some ( doc) = attrs. iter ( ) . find ( |x| x. is_sugared_doc ) {
3202
+ self . span_fatal_err ( doc. span , Error :: UselessDocComment ) . emit ( ) ;
3203
+ }
3181
3204
let match_span = self . prev_span ;
3182
3205
let lo = self . prev_span ;
3183
3206
let discriminant = self . parse_expr_res ( RESTRICTION_NO_STRUCT_LITERAL ,
@@ -3215,6 +3238,9 @@ impl<'a> Parser<'a> {
3215
3238
maybe_whole ! ( self , NtArm , |x| x) ;
3216
3239
3217
3240
let attrs = self . parse_outer_attributes ( ) ?;
3241
+ if let Some ( doc) = attrs. iter ( ) . find ( |x| x. is_sugared_doc ) {
3242
+ self . span_fatal_err ( doc. span , Error :: UselessDocComment ) . emit ( ) ;
3243
+ }
3218
3244
let pats = self . parse_pats ( ) ?;
3219
3245
let guard = if self . eat_keyword ( keywords:: If ) {
3220
3246
Some ( self . parse_expr ( ) ?)
@@ -3669,6 +3695,9 @@ impl<'a> Parser<'a> {
3669
3695
3670
3696
/// Parse a local variable declaration
3671
3697
fn parse_local ( & mut self , attrs : ThinVec < Attribute > ) -> PResult < ' a , P < Local > > {
3698
+ if let Some ( doc) = attrs. iter ( ) . find ( |x| x. is_sugared_doc ) {
3699
+ self . span_fatal_err ( doc. span , Error :: UselessDocComment ) . emit ( ) ;
3700
+ }
3672
3701
let lo = self . span ;
3673
3702
let pat = self . parse_pat ( ) ?;
3674
3703
@@ -4158,6 +4187,8 @@ impl<'a> Parser<'a> {
4158
4187
stmts. push ( stmt) ;
4159
4188
} else if self . token == token:: Eof {
4160
4189
break ;
4190
+ } else if let token:: DocComment ( _) = self . token {
4191
+ return Err ( self . span_fatal_err ( self . span , Error :: UselessDocComment ) ) ;
4161
4192
} else {
4162
4193
// Found only `;` or `}`.
4163
4194
continue ;
0 commit comments