Fix double_parens false positive

Closes #3206
This commit is contained in:
Michael Wright 2018-09-22 17:20:34 +02:00
parent c0c770c60b
commit 867ac98d38
3 changed files with 19 additions and 2 deletions

View File

@ -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.
///
@ -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(_) => {

View File

@ -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() {}

View File

@ -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