mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
fix: don't remove parentheses for calls of function-like pointers that are members of a struct or union
This commit is contained in:
parent
67f7eb505e
commit
d6d45a23d3
2 changed files with 37 additions and 0 deletions
|
@ -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::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue