Skip to content

Commit f52859b

Browse files
committed
remove both parens in ((x))
1 parent e7d8989 commit f52859b

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

clippy_lints/src/double_parens.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@ declare_lint_pass!(DoubleParens => [DOUBLE_PARENS]);
4343
impl EarlyLintPass for DoubleParens {
4444
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
4545
let (outer_span, inner_span) = match &expr.kind {
46-
ExprKind::Paren(in_paren) if matches!(in_paren.kind, ExprKind::Paren(_) | ExprKind::Tup(_)) => {
47-
(expr.span, in_paren.span)
46+
ExprKind::Paren(in_paren) => {
47+
let inner_span = match &in_paren.kind {
48+
ExprKind::Paren(inner) => inner.span,
49+
ExprKind::Tup(_) => in_paren.span,
50+
_ => return,
51+
};
52+
(expr.span, inner_span)
4853
},
4954
ExprKind::Call(_, params)
5055
if let [param] = &**params

tests/ui/double_parens.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl DummyStruct {
1212
}
1313

1414
fn simple_double_parens() -> i32 {
15-
(0)
15+
0
1616
//~^ double_parens
1717
}
1818

tests/ui/double_parens.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: unnecessary parentheses
22
--> tests/ui/double_parens.rs:15:5
33
|
44
LL | ((0))
5-
| ^^^^^ help: remove them: `(0)`
5+
| ^^^^^ help: remove them: `0`
66
|
77
= note: `-D clippy::double-parens` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::double_parens)]`

0 commit comments

Comments
 (0)