Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/syntax/src/ast/prec.rs')
-rw-r--r--crates/syntax/src/ast/prec.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/crates/syntax/src/ast/prec.rs b/crates/syntax/src/ast/prec.rs
index 9131cd2f17..28089ffb37 100644
--- a/crates/syntax/src/ast/prec.rs
+++ b/crates/syntax/src/ast/prec.rs
@@ -27,6 +27,14 @@ impl Expr {
}
fn needs_parens_in_expr(&self, parent: &Expr) -> bool {
+ // Parentheses are necessary when calling a function-like pointer that is a member of a struct or union
+ // (e.g. `(a.f)()`).
+ let is_parent_call_expr = matches!(parent, ast::Expr::CallExpr(_));
+ let is_field_expr = matches!(self, ast::Expr::FieldExpr(_));
+ if is_parent_call_expr && is_field_expr {
+ return true;
+ }
+
// Special-case block weirdness
if parent.child_is_followed_by_a_block() {
use Expr::*;