Skip to content

Commit 4aa4a8f

Browse files
committed
Minor cleanup in parse_assoc_expr_with.
1 parent b680b66 commit 4aa4a8f

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

src/libsyntax/parse/parser.rs

+14-24
Original file line numberDiff line numberDiff line change
@@ -3573,7 +3573,8 @@ impl<'a> Parser<'a> {
35733573
} else {
35743574
self.restrictions
35753575
};
3576-
if op.precedence() < min_prec {
3576+
let prec = op.precedence();
3577+
if prec < min_prec {
35773578
break;
35783579
}
35793580
// Check for deprecated `...` syntax
@@ -3614,8 +3615,7 @@ impl<'a> Parser<'a> {
36143615
// We have 2 alternatives here: `x..y`/`x..=y` and `x..`/`x..=` The other
36153616
// two variants are handled with `parse_prefix_range_expr` call above.
36163617
let rhs = if self.is_at_start_of_range_notation_rhs() {
3617-
Some(self.parse_assoc_expr_with(op.precedence() + 1,
3618-
LhsExpr::NotYetParsed)?)
3618+
Some(self.parse_assoc_expr_with(prec + 1, LhsExpr::NotYetParsed)?)
36193619
} else {
36203620
None
36213621
};
@@ -3635,28 +3635,18 @@ impl<'a> Parser<'a> {
36353635
break
36363636
}
36373637

3638-
let rhs = match op.fixity() {
3639-
Fixity::Right => self.with_res(
3640-
restrictions - Restrictions::STMT_EXPR,
3641-
|this| {
3642-
this.parse_assoc_expr_with(op.precedence(),
3643-
LhsExpr::NotYetParsed)
3644-
}),
3645-
Fixity::Left => self.with_res(
3646-
restrictions - Restrictions::STMT_EXPR,
3647-
|this| {
3648-
this.parse_assoc_expr_with(op.precedence() + 1,
3649-
LhsExpr::NotYetParsed)
3650-
}),
3638+
let fixity = op.fixity();
3639+
let prec_adjustment = match fixity {
3640+
Fixity::Right => 0,
3641+
Fixity::Left => 1,
36513642
// We currently have no non-associative operators that are not handled above by
36523643
// the special cases. The code is here only for future convenience.
3653-
Fixity::None => self.with_res(
3654-
restrictions - Restrictions::STMT_EXPR,
3655-
|this| {
3656-
this.parse_assoc_expr_with(op.precedence() + 1,
3657-
LhsExpr::NotYetParsed)
3658-
}),
3659-
}?;
3644+
Fixity::None => 1,
3645+
};
3646+
let rhs = self.with_res(
3647+
restrictions - Restrictions::STMT_EXPR,
3648+
|this| this.parse_assoc_expr_with(prec + prec_adjustment, LhsExpr::NotYetParsed)
3649+
)?;
36603650

36613651
// Make sure that the span of the parent node is larger than the span of lhs and rhs,
36623652
// including the attributes.
@@ -3702,7 +3692,7 @@ impl<'a> Parser<'a> {
37023692
}
37033693
};
37043694

3705-
if op.fixity() == Fixity::None { break }
3695+
if let Fixity::None = fixity { break }
37063696
}
37073697
Ok(lhs)
37083698
}

0 commit comments

Comments
 (0)