Skip to content

Commit 193d827

Browse files
committed
Squash closures and jumps into a single precedence level
1 parent f3ac64a commit 193d827

File tree

4 files changed

+4
-7
lines changed

4 files changed

+4
-7
lines changed

compiler/rustc_ast/src/ast.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1317,9 +1317,8 @@ impl Expr {
13171317

13181318
pub fn precedence(&self) -> ExprPrecedence {
13191319
match self.kind {
1320-
ExprKind::Closure(..) => ExprPrecedence::Closure,
1321-
13221320
ExprKind::Break(..)
1321+
| ExprKind::Closure(..)
13231322
| ExprKind::Continue(..)
13241323
| ExprKind::Ret(..)
13251324
| ExprKind::Yield(..)

compiler/rustc_ast/src/util/parser.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ impl AssocOp {
231231

232232
#[derive(Clone, Copy, PartialEq, PartialOrd)]
233233
pub enum ExprPrecedence {
234-
Closure,
235-
// return, break, yield
234+
// return, break, yield, closures
236235
Jump,
237236
// = += -= *= /= %= &= |= ^= <<= >>=
238237
Assign,

compiler/rustc_hir/src/hir.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1697,9 +1697,8 @@ pub struct Expr<'hir> {
16971697
impl Expr<'_> {
16981698
pub fn precedence(&self) -> ExprPrecedence {
16991699
match self.kind {
1700-
ExprKind::Closure { .. } => ExprPrecedence::Closure,
1701-
17021700
ExprKind::Break(..)
1701+
| ExprKind::Closure { .. }
17031702
| ExprKind::Continue(..)
17041703
| ExprKind::Ret(..)
17051704
| ExprKind::Yield(..)

tests/ui-fulldeps/pprust-parenthesis-insertion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static EXPRS: &[&str] = &[
7272
"(return) - 2",
7373
// Closures and jumps have equal precedence.
7474
"|| return break 2",
75-
"return break (|| 2)", // FIXME: no parenthesis needed.
75+
"return break || 2",
7676
// These mean different things.
7777
"if let _ = true && false {}",
7878
"if let _ = (true && false) {}",

0 commit comments

Comments
 (0)