@@ -335,40 +335,6 @@ impl<'a> AstValidator<'a> {
335
335
}
336
336
}
337
337
338
- /// Visits the `expr` and adjusts whether `let $pat = $expr` is allowed in decendants.
339
- /// Returns whether we walked into `expr` or not.
340
- /// If we did, walking should not happen again.
341
- fn visit_expr_with_let_maybe_allowed ( & mut self , expr : & ' a Expr , let_allowed : bool ) -> bool {
342
- match & expr. node {
343
- // Assuming the context permits, `($expr)` does not impose additional constraints.
344
- ExprKind :: Paren ( _) => {
345
- self . with_let_allowed ( let_allowed, |this, _| visit:: walk_expr ( this, expr) ) ;
346
- }
347
- // Assuming the context permits,
348
- // l && r` allows decendants in `l` and `r` to be `let` expressions.
349
- ExprKind :: Binary ( op, ..) if op. node == BinOpKind :: And => {
350
- self . with_let_allowed ( let_allowed, |this, _| visit:: walk_expr ( this, expr) ) ;
351
- }
352
- // However, we do allow it in the condition of the `if` expression.
353
- // We do not allow `let` in `then` and `opt_else` directly.
354
- ExprKind :: If ( cond, then, opt_else) => {
355
- self . visit_block ( then) ;
356
- walk_list ! ( self , visit_expr, opt_else) ;
357
- self . with_let_allowed ( true , |this, _| this. visit_expr ( cond) ) ;
358
- }
359
- // The same logic applies to `While`.
360
- ExprKind :: While ( cond, then, opt_label) => {
361
- walk_list ! ( self , visit_label, opt_label) ;
362
- self . visit_block ( then) ;
363
- self . with_let_allowed ( true , |this, _| this. visit_expr ( cond) ) ;
364
- }
365
- // Don't walk into `expr` and defer further checks to the caller.
366
- _ => return false ,
367
- }
368
-
369
- true
370
- }
371
-
372
338
/// Emits an error banning the `let` expression provided.
373
339
fn ban_let_expr ( & self , expr : & ' a Expr ) {
374
340
self . err_handler ( )
@@ -509,9 +475,31 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
509
475
ExprKind :: Let ( _, _) if !let_allowed => {
510
476
this. ban_let_expr ( expr) ;
511
477
}
512
- _ if this. visit_expr_with_let_maybe_allowed ( & expr, let_allowed) => {
513
- // Prevent `walk_expr` to happen since we've already done that.
514
- return ;
478
+ // Assuming the context permits, `($expr)` does not impose additional constraints.
479
+ ExprKind :: Paren ( _) => {
480
+ this. with_let_allowed ( let_allowed, |this, _| visit:: walk_expr ( this, expr) ) ;
481
+ return ; // We've already walked into `expr`.
482
+ }
483
+ // Assuming the context permits,
484
+ // l && r` allows decendants in `l` and `r` to be `let` expressions.
485
+ ExprKind :: Binary ( op, ..) if op. node == BinOpKind :: And => {
486
+ this. with_let_allowed ( let_allowed, |this, _| visit:: walk_expr ( this, expr) ) ;
487
+ return ; // We've already walked into `expr`.
488
+ }
489
+ // However, we do allow it in the condition of the `if` expression.
490
+ // We do not allow `let` in `then` and `opt_else` directly.
491
+ ExprKind :: If ( cond, then, opt_else) => {
492
+ this. visit_block ( then) ;
493
+ walk_list ! ( this, visit_expr, opt_else) ;
494
+ this. with_let_allowed ( true , |this, _| this. visit_expr ( cond) ) ;
495
+ return ; // We've already walked into `expr`.
496
+ }
497
+ // The same logic applies to `While`.
498
+ ExprKind :: While ( cond, then, opt_label) => {
499
+ walk_list ! ( this, visit_label, opt_label) ;
500
+ this. visit_block ( then) ;
501
+ this. with_let_allowed ( true , |this, _| this. visit_expr ( cond) ) ;
502
+ return ; // We've already walked into `expr`.
515
503
}
516
504
ExprKind :: Closure ( _, _, _, fn_decl, _, _) => {
517
505
this. check_fn_decl ( fn_decl) ;
0 commit comments