1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
10 use crate::rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
11 use crate::rustc::{declare_tool_lint, lint_array};
12 use crate::syntax::ast::*;
13 use crate::utils::{in_macro, span_lint};
15 /// **What it does:** Checks for unnecessary double parentheses.
17 /// **Why is this bad?** This makes code harder to read and might indicate a
20 /// **Known problems:** None.
28 declare_clippy_lint! {
31 "Warn on unnecessary double parentheses"
34 #[derive(Copy, Clone)]
35 pub struct DoubleParens;
37 impl LintPass for DoubleParens {
38 fn get_lints(&self) -> LintArray {
39 lint_array!(DOUBLE_PARENS)
43 impl EarlyLintPass for DoubleParens {
44 fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
45 if in_macro(expr.span) {
50 ExprKind::Paren(ref in_paren) => match in_paren.node {
51 ExprKind::Paren(_) | ExprKind::Tup(_) => {
56 "Consider removing unnecessary double parentheses",
61 ExprKind::Call(_, ref params) => {
62 if params.len() == 1 {
63 let param = ¶ms[0];
64 if let ExprKind::Paren(_) = param.node {
69 "Consider removing unnecessary double parentheses",
74 ExprKind::MethodCall(_, ref params) => {
75 if params.len() == 2 {
76 let param = ¶ms[1];
77 if let ExprKind::Paren(_) = param.node {
82 "Consider removing unnecessary double parentheses",