Squash closures and jumps into a single precedence level

This commit is contained in:
David Tolnay 2024-12-02 17:17:37 -08:00
parent f3ac64ac34
commit 193d82797c
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
4 changed files with 4 additions and 7 deletions

View file

@ -1317,9 +1317,8 @@ impl Expr {
pub fn precedence(&self) -> ExprPrecedence { pub fn precedence(&self) -> ExprPrecedence {
match self.kind { match self.kind {
ExprKind::Closure(..) => ExprPrecedence::Closure,
ExprKind::Break(..) ExprKind::Break(..)
| ExprKind::Closure(..)
| ExprKind::Continue(..) | ExprKind::Continue(..)
| ExprKind::Ret(..) | ExprKind::Ret(..)
| ExprKind::Yield(..) | ExprKind::Yield(..)

View file

@ -231,8 +231,7 @@ impl AssocOp {
#[derive(Clone, Copy, PartialEq, PartialOrd)] #[derive(Clone, Copy, PartialEq, PartialOrd)]
pub enum ExprPrecedence { pub enum ExprPrecedence {
Closure, // return, break, yield, closures
// return, break, yield
Jump, Jump,
// = += -= *= /= %= &= |= ^= <<= >>= // = += -= *= /= %= &= |= ^= <<= >>=
Assign, Assign,

View file

@ -1697,9 +1697,8 @@ pub struct Expr<'hir> {
impl Expr<'_> { impl Expr<'_> {
pub fn precedence(&self) -> ExprPrecedence { pub fn precedence(&self) -> ExprPrecedence {
match self.kind { match self.kind {
ExprKind::Closure { .. } => ExprPrecedence::Closure,
ExprKind::Break(..) ExprKind::Break(..)
| ExprKind::Closure { .. }
| ExprKind::Continue(..) | ExprKind::Continue(..)
| ExprKind::Ret(..) | ExprKind::Ret(..)
| ExprKind::Yield(..) | ExprKind::Yield(..)

View file

@ -72,7 +72,7 @@ static EXPRS: &[&str] = &[
"(return) - 2", "(return) - 2",
// Closures and jumps have equal precedence. // Closures and jumps have equal precedence.
"|| return break 2", "|| return break 2",
"return break (|| 2)", // FIXME: no parenthesis needed. "return break || 2",
// These mean different things. // These mean different things.
"if let _ = true && false {}", "if let _ = true && false {}",
"if let _ = (true && false) {}", "if let _ = (true && false) {}",