Skip to content

Commit ca8f474

Browse files
committed
Eliminate PREC_FORCE_PAREN
1 parent 34a65f2 commit ca8f474

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

compiler/rustc_ast/src/util/parser.rs

-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ pub const PREC_RANGE: i8 = -10;
235235
// The range 2..=14 is reserved for AssocOp binary operator precedences.
236236
pub const PREC_PREFIX: i8 = 50;
237237
pub const PREC_UNAMBIGUOUS: i8 = 60;
238-
pub const PREC_FORCE_PAREN: i8 = 100;
239238

240239
/// In `let p = e`, operators with precedence `<=` this one requires parentheses in `e`.
241240
pub fn prec_let_scrutinee_needs_par() -> usize {

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ impl<'a> State<'a> {
212212
}
213213

214214
fn print_expr_call(&mut self, func: &ast::Expr, args: &[P<ast::Expr>], fixup: FixupContext) {
215-
let prec = match func.kind {
216-
ast::ExprKind::Field(..) => parser::PREC_FORCE_PAREN,
217-
_ => parser::PREC_UNAMBIGUOUS,
215+
let needs_paren = match func.kind {
216+
ast::ExprKind::Field(..) => true,
217+
_ => func.precedence() < parser::PREC_UNAMBIGUOUS,
218218
};
219219

220220
// Independent of parenthesization related to precedence, we must
@@ -233,7 +233,7 @@ impl<'a> State<'a> {
233233
// because the latter is valid syntax but with the incorrect meaning.
234234
// It's a match-expression followed by tuple-expression, not a function
235235
// call.
236-
self.print_expr_cond_paren(func, func.precedence() < prec, fixup.leftmost_subexpression());
236+
self.print_expr_cond_paren(func, needs_paren, fixup.leftmost_subexpression());
237237

238238
self.print_call_post(args)
239239
}

compiler/rustc_hir_pretty/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1132,12 +1132,12 @@ impl<'a> State<'a> {
11321132
}
11331133

11341134
fn print_expr_call(&mut self, func: &hir::Expr<'_>, args: &[hir::Expr<'_>]) {
1135-
let prec = match func.kind {
1136-
hir::ExprKind::Field(..) => parser::PREC_FORCE_PAREN,
1137-
_ => parser::PREC_UNAMBIGUOUS,
1135+
let needs_paren = match func.kind {
1136+
hir::ExprKind::Field(..) => true,
1137+
_ => func.precedence() < parser::PREC_UNAMBIGUOUS,
11381138
};
11391139

1140-
self.print_expr_cond_paren(func, func.precedence() < prec);
1140+
self.print_expr_cond_paren(func, needs_paren);
11411141
self.print_call_post(args)
11421142
}
11431143

0 commit comments

Comments
 (0)