Merge pull request #3207 from mikerite/fix-3206

Fix double_parens false positive
This commit is contained in:
Philipp Krones 2018-09-23 18:24:27 +02:00 committed by GitHub
commit bc6d85ceaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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