Skip to content

Commit

Permalink
Add parenthesis around closure method call
Browse files Browse the repository at this point in the history
  • Loading branch information
Centri3 committed Jul 18, 2023
1 parent e0e633e commit 7f28b56
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,16 @@ impl ChainItemKind {
ChainItemKind::Parent {
expr: expr.clone(),
parens: is_method_call_receiver
&& matches!(
&& (matches!(
&expr.kind,
ast::ExprKind::Lit(lit) if crate::expr::lit_ends_in_dot(lit)
),
) || matches!(
&expr.kind,
ast::ExprKind::Closure(ref cl) if matches!(
cl.body.kind,
ast::ExprKind::Range(None, None, ast::RangeLimits::HalfOpen),
)
)),
},
expr.span,
);
Expand Down
11 changes: 11 additions & 0 deletions tests/source/issue-4808.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
trait Trait {
fn method(&self);
}

impl<F: Fn() -> T, T> Trait for F {
fn method(&self) {}
}

fn main() {
|| .. .method();
}
11 changes: 11 additions & 0 deletions tests/target/issue-4808.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
trait Trait {
fn method(&self);
}

impl<F: Fn() -> T, T> Trait for F {
fn method(&self) {}
}

fn main() {
(|| ..).method();
}

0 comments on commit 7f28b56

Please sign in to comment.