Skip to content

Commit

Permalink
Merge pull request #1691 from dtolnay/postfix
Browse files Browse the repository at this point in the history
Eliminate Postfix precedence level
  • Loading branch information
dtolnay authored Jun 25, 2024
2 parents ecb0429 + c29fb6a commit 2bbf612
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
12 changes: 6 additions & 6 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3180,7 +3180,7 @@ pub(crate) mod printing {
outer_attrs_to_tokens(&e.attrs, tokens);
print_subexpression(
&e.base,
Precedence::of(&e.base) < Precedence::Postfix,
Precedence::of(&e.base) < Precedence::Unambiguous,
tokens,
fixup.leftmost_subexpression_with_dot(),
);
Expand Down Expand Up @@ -3313,7 +3313,7 @@ pub(crate) mod printing {
let precedence = if let Expr::Field(_) = &*e.func {
Precedence::Any
} else {
Precedence::Postfix
Precedence::Unambiguous
};
print_subexpression(
&e.func,
Expand Down Expand Up @@ -3424,7 +3424,7 @@ pub(crate) mod printing {
outer_attrs_to_tokens(&e.attrs, tokens);
print_subexpression(
&e.base,
Precedence::of(&e.base) < Precedence::Postfix,
Precedence::of(&e.base) < Precedence::Unambiguous,
tokens,
#[cfg(feature = "full")]
fixup.leftmost_subexpression_with_dot(),
Expand Down Expand Up @@ -3519,7 +3519,7 @@ pub(crate) mod printing {
outer_attrs_to_tokens(&e.attrs, tokens);
print_subexpression(
&e.expr,
Precedence::of(&e.expr) < Precedence::Postfix,
Precedence::of(&e.expr) < Precedence::Unambiguous,
tokens,
#[cfg(feature = "full")]
fixup.leftmost_subexpression(),
Expand Down Expand Up @@ -3635,7 +3635,7 @@ pub(crate) mod printing {
outer_attrs_to_tokens(&e.attrs, tokens);
print_subexpression(
&e.receiver,
Precedence::of(&e.receiver) < Precedence::Postfix,
Precedence::of(&e.receiver) < Precedence::Unambiguous,
tokens,
#[cfg(feature = "full")]
fixup.leftmost_subexpression_with_dot(),
Expand Down Expand Up @@ -3785,7 +3785,7 @@ pub(crate) mod printing {
outer_attrs_to_tokens(&e.attrs, tokens);
print_subexpression(
&e.expr,
Precedence::of(&e.expr) < Precedence::Postfix,
Precedence::of(&e.expr) < Precedence::Unambiguous,
tokens,
fixup.leftmost_subexpression_with_dot(),
);
Expand Down
18 changes: 7 additions & 11 deletions src/precedence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ pub(crate) enum Precedence {
// unary - * ! & &mut
#[cfg(feature = "printing")]
Prefix,
// function calls, array indexing, field expressions, method calls, ?
#[cfg(feature = "printing")]
Postfix,
// paths, loops
// paths, loops, function calls, array indexing, field expressions, method calls
#[cfg(feature = "printing")]
Unambiguous,
}
Expand Down Expand Up @@ -92,30 +89,29 @@ impl Precedence {
Expr::Cast(_) => Precedence::Cast,
Expr::Let(_) | Expr::Reference(_) | Expr::Unary(_) => Precedence::Prefix,

Expr::Await(_)
| Expr::Call(_)
| Expr::MethodCall(_)
| Expr::Field(_)
| Expr::Index(_)
| Expr::Try(_) => Precedence::Postfix,

Expr::Array(_)
| Expr::Async(_)
| Expr::Await(_)
| Expr::Block(_)
| Expr::Call(_)
| Expr::Const(_)
| Expr::Continue(_)
| Expr::Field(_)
| Expr::ForLoop(_)
| Expr::Group(_)
| Expr::If(_)
| Expr::Index(_)
| Expr::Infer(_)
| Expr::Lit(_)
| Expr::Loop(_)
| Expr::Macro(_)
| Expr::Match(_)
| Expr::MethodCall(_)
| Expr::Paren(_)
| Expr::Path(_)
| Expr::Repeat(_)
| Expr::Struct(_)
| Expr::Try(_)
| Expr::TryBlock(_)
| Expr::Tuple(_)
| Expr::Unsafe(_)
Expand Down

0 comments on commit 2bbf612

Please sign in to comment.