Skip to content

Commit 7f314ac

Browse files
committed
Delete special handling of some expr kinds from print_let
In all four of Break, Closure, Ret, Yeet, the needs_par_as_let_scrutinee is guaranteed to return true because the .precedence().order() of those expr kinds is <= AssocOp::LAnd.precedence(). The relevant functions in rustc_ast::util::parser are: fn needs_par_as_let_scrutinee(order: i8) -> bool { order <= prec_let_scrutinee_needs_par() as i8 } fn prec_let_scrutinee_needs_par() -> usize { AssocOp::LAnd.precedence() } The .precedence().order() of Closure is PREC_CLOSURE (-40) and of Break, Ret, Yeet is PREC_JUMP (-30). The value of AssocOp::LAnd.precedence() is 6. So this commit causes no change in behavior, only potentially performance by doing a redundant call to contains_exterior_struct_lit in those four cases. This is fine because Break, Closure, Ret, Yeet should be exceedingly rare in the position of a let scrutinee.
1 parent dc5ec72 commit 7f314ac

File tree

1 file changed

+2
-10
lines changed
  • compiler/rustc_ast_pretty/src/pprust

1 file changed

+2
-10
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,16 +1161,8 @@ impl<'a> State<'a> {
11611161
self.word_space("=");
11621162
self.print_expr_cond_paren(
11631163
expr,
1164-
match expr.kind {
1165-
ast::ExprKind::Break(..)
1166-
| ast::ExprKind::Closure(..)
1167-
| ast::ExprKind::Ret(..)
1168-
| ast::ExprKind::Yeet(..) => true,
1169-
_ => {
1170-
parser::contains_exterior_struct_lit(expr)
1171-
|| parser::needs_par_as_let_scrutinee(expr.precedence().order())
1172-
}
1173-
},
1164+
parser::contains_exterior_struct_lit(expr)
1165+
|| parser::needs_par_as_let_scrutinee(expr.precedence().order()),
11741166
);
11751167
}
11761168

0 commit comments

Comments
 (0)