mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
Merge pull request #3207 from mikerite/fix-3206
Fix double_parens false positive
This commit is contained in:
commit
bc6d85ceaf
@ -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(_) => {
|
||||
|
@ -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() {}
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user