Skip to content

Fix double_parens false positive #3207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from Sep 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion clippy_lints/src/double_parens.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::syntax::ast::*;
use crate::rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
use crate::rustc::{declare_tool_lint, lint_array};
use crate::utils::span_lint;
use crate::utils::{in_macro, span_lint};


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

impl EarlyLintPass for DoubleParens {
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
if in_macro(expr.span) {
return;
}

match expr.node {
ExprKind::Paren(ref in_paren) => match in_paren.node {
ExprKind::Paren(_) | ExprKind::Tup(_) => {
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/double_parens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,10 @@ fn method_unit_ok(x: DummyStruct) {
x.dummy_method(());
}

// Issue #3206
fn inside_macro() {
assert_eq!((1, 2), (1, 2), "Error");
assert_eq!(((1, 2)), (1, 2), "Error");
}

fn main() {}
8 changes: 7 additions & 1 deletion tests/ui/double_parens.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,11 @@ error: Consider removing unnecessary double parentheses
32 | (())
| ^^^^

error: aborting due to 5 previous errors
error: Consider removing unnecessary double parentheses
--> $DIR/double_parens.rs:54:16
|
54 | assert_eq!(((1, 2)), (1, 2), "Error");
| ^^^^^^^^

error: aborting due to 6 previous errors