Skip to content

Commit bc6d85c

Browse files
authored
Merge pull request #3207 from mikerite/fix-3206
Fix double_parens false positive
2 parents af2d6a0 + 867ac98 commit bc6d85c

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

clippy_lints/src/double_parens.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::syntax::ast::*;
22
use crate::rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
33
use crate::rustc::{declare_tool_lint, lint_array};
4-
use crate::utils::span_lint;
4+
use crate::utils::{in_macro, span_lint};
5+
56

67
/// **What it does:** Checks for unnecessary double parentheses.
78
///
@@ -33,6 +34,10 @@ impl LintPass for DoubleParens {
3334

3435
impl EarlyLintPass for DoubleParens {
3536
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
37+
if in_macro(expr.span) {
38+
return;
39+
}
40+
3641
match expr.node {
3742
ExprKind::Paren(ref in_paren) => match in_paren.node {
3843
ExprKind::Paren(_) | ExprKind::Tup(_) => {

tests/ui/double_parens.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,10 @@ fn method_unit_ok(x: DummyStruct) {
4848
x.dummy_method(());
4949
}
5050

51+
// Issue #3206
52+
fn inside_macro() {
53+
assert_eq!((1, 2), (1, 2), "Error");
54+
assert_eq!(((1, 2)), (1, 2), "Error");
55+
}
56+
5157
fn main() {}

tests/ui/double_parens.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,11 @@ error: Consider removing unnecessary double parentheses
3030
32 | (())
3131
| ^^^^
3232

33-
error: aborting due to 5 previous errors
33+
error: Consider removing unnecessary double parentheses
34+
--> $DIR/double_parens.rs:54:16
35+
|
36+
54 | assert_eq!(((1, 2)), (1, 2), "Error");
37+
| ^^^^^^^^
38+
39+
error: aborting due to 6 previous errors
3440

0 commit comments

Comments
 (0)