]> git.lizzy.rs Git - rust.git/commitdiff
Ignore spans when comparing expressions
authorOliver Schneider <github35764891676564198441@oli-obk.de>
Sat, 14 Jul 2018 22:00:27 +0000 (00:00 +0200)
committerOliver Schneider <github35764891676564198441@oli-obk.de>
Sat, 14 Jul 2018 22:00:27 +0000 (00:00 +0200)
13 files changed:
clippy_lints/src/enum_glob_use.rs
clippy_lints/src/enum_variants.rs
clippy_lints/src/if_let_redundant_pattern_matching.rs
clippy_lints/src/loops.rs
clippy_lints/src/map_clone.rs
clippy_lints/src/matches.rs
clippy_lints/src/methods.rs
clippy_lints/src/misc.rs
clippy_lints/src/misc_early.rs
clippy_lints/src/overflow_check_conditional.rs
clippy_lints/src/ranges.rs
clippy_lints/src/utils/hir_utils.rs
clippy_lints/src/utils/internal_lints.rs

index 9a0263f2f68c2a2e6cf0b958e44989954cb9fac4..e90dc6f693a33a2b0a83fe856c67d8032ed44d8b 100644 (file)
@@ -44,7 +44,7 @@ fn check_mod(&mut self, cx: &LateContext<'a, 'tcx>, m: &'tcx Mod, _: Span, _: No
 
 impl EnumGlobUse {
     fn lint_item(&self, cx: &LateContext, item: &Item) {
-        if item.vis.node == VisibilityKind::Public {
+        if item.vis.node.is_pub() {
             return; // re-exports are fine
         }
         if let ItemUse(ref path, UseKind::Glob) = item.node {
index a200383b41d166debeb2e8170668e3c4e12b0562..d272cab0a0df941174593b27472ce6e3b939c8a5 100644 (file)
@@ -262,7 +262,7 @@ fn check_item(&mut self, cx: &EarlyContext, item: &Item) {
                             );
                         }
                     }
-                    if item.vis.node == VisibilityKind::Public {
+                    if item.vis.node.is_pub() {
                         let matching = partial_match(mod_camel, &item_camel);
                         let rmatching = partial_rmatch(mod_camel, &item_camel);
                         let nchars = mod_camel.chars().count();
index 92b2bab3ba832c99ae7bb4323fcfe1c2981f94f1..78b21478d8868d9c07c375de68665bdd4f11a9af 100644 (file)
@@ -48,13 +48,17 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
         if let ExprMatch(ref op, ref arms, MatchSource::IfLetDesugar { .. }) = expr.node {
             if arms[0].pats.len() == 1 {
                 let good_method = match arms[0].pats[0].node {
-                    PatKind::TupleStruct(ref path, ref pats, _) if pats.len() == 1 && pats[0].node == PatKind::Wild => {
-                        if match_qpath(path, &paths::RESULT_OK) {
-                            "is_ok()"
-                        } else if match_qpath(path, &paths::RESULT_ERR) {
-                            "is_err()"
-                        } else if match_qpath(path, &paths::OPTION_SOME) {
-                            "is_some()"
+                    PatKind::TupleStruct(ref path, ref pats, _) if pats.len() == 1 => {
+                        if let PatKind::Wild = pats[0].node {
+                            if match_qpath(path, &paths::RESULT_OK) {
+                                "is_ok()"
+                            } else if match_qpath(path, &paths::RESULT_ERR) {
+                                "is_err()"
+                            } else if match_qpath(path, &paths::OPTION_SOME) {
+                                "is_some()"
+                            } else {
+                                return;
+                            }
                         } else {
                             return;
                         }
index 8b7032893d88a332f278e5ff05970784df4c1c8a..963a8da49cb8a519550980d5ad10dfd8b9271eff 100644 (file)
@@ -23,7 +23,7 @@
 
 use crate::utils::{get_enclosing_block, get_parent_expr, higher, in_external_macro, is_integer_literal, is_refutable,
             last_path_segment, match_trait_method, match_type, match_var, multispan_sugg, snippet, snippet_opt,
-            span_help_and_lint, span_lint, span_lint_and_sugg, span_lint_and_then};
+            span_help_and_lint, span_lint, span_lint_and_sugg, span_lint_and_then, SpanlessEq};
 use crate::utils::paths;
 
 /// **What it does:** Checks for for-loops that manually copy items between
@@ -1955,7 +1955,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr) {
         if self.state == VarState::DontWarn {
             return;
         }
-        if expr == self.end_expr {
+        if SpanlessEq::new(self.cx).eq_expr(&expr, self.end_expr) {
             self.past_loop = true;
             return;
         }
index 5ea873e31e1313dbbfb430fd5fa2b8fd9794662e..0d58732f24d1e8d981c47e770838b665ab739494 100644 (file)
@@ -3,7 +3,7 @@
 use rustc::ty;
 use syntax::ast;
 use crate::utils::{get_arg_ident, is_adjusted, iter_input_pats, match_qpath, match_trait_method, match_type,
-            paths, remove_blocks, snippet, span_help_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth};
+            paths, remove_blocks, snippet, span_help_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth, SpanlessEq};
 
 /// **What it does:** Checks for mapping `clone()` over an iterator.
 ///
@@ -66,7 +66,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
                                     if clone_call.ident.name == "clone" &&
                                         clone_args.len() == 1 &&
                                         match_trait_method(cx, closure_expr, &paths::CLONE_TRAIT) &&
-                                        expr_eq_name(&clone_args[0], arg_ident)
+                                        expr_eq_name(cx, &clone_args[0], arg_ident)
                                     {
                                         span_help_and_lint(cx, MAP_CLONE, expr.span, &format!(
                                             "you seem to be using .map() to clone the contents of an {}, consider \
@@ -98,7 +98,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
     }
 }
 
-fn expr_eq_name(expr: &Expr, id: ast::Ident) -> bool {
+fn expr_eq_name(cx: &LateContext, expr: &Expr, id: ast::Ident) -> bool {
     match expr.node {
         ExprPath(QPath::Resolved(None, ref path)) => {
             let arg_segment = [
@@ -108,7 +108,7 @@ fn expr_eq_name(expr: &Expr, id: ast::Ident) -> bool {
                     infer_types: true,
                 },
             ];
-            !path.is_global() && path.segments[..] == arg_segment
+            !path.is_global() && SpanlessEq::new(cx).eq_path_segments(&path.segments[..], &arg_segment)
         },
         _ => false,
     }
@@ -127,7 +127,7 @@ fn get_type_name(cx: &LateContext, expr: &Expr, arg: &Expr) -> Option<&'static s
 fn only_derefs(cx: &LateContext, expr: &Expr, id: ast::Ident) -> bool {
     match expr.node {
         ExprUnary(UnDeref, ref subexpr) if !is_adjusted(cx, subexpr) => only_derefs(cx, subexpr, id),
-        _ => expr_eq_name(expr, id),
+        _ => expr_eq_name(cx, expr, id),
     }
 }
 
index 207343c92c678125cd3208dcfa3f5606e6c9a465..a14c6a0d8b9049e98f446223ac84efbbd95e5663 100644 (file)
@@ -221,7 +221,7 @@ fn check_single_match(cx: &LateContext, ex: &Expr, arms: &[Arm], expr: &Expr) {
 }
 
 fn check_single_match_single_pattern(cx: &LateContext, ex: &Expr, arms: &[Arm], expr: &Expr, els: Option<&Expr>) {
-    if arms[1].pats[0].node == PatKind::Wild {
+    if is_wild(&arms[1].pats[0]) {
         report_single_match_single_pattern(cx, ex, arms, expr, els);
     }
 }
@@ -265,7 +265,7 @@ fn check_single_match_opt_like(cx: &LateContext, ex: &Expr, arms: &[Arm], expr:
     let path = match arms[1].pats[0].node {
         PatKind::TupleStruct(ref path, ref inner, _) => {
             // contains any non wildcard patterns? e.g. Err(err)
-            if inner.iter().any(|pat| pat.node != PatKind::Wild) {
+            if !inner.iter().all(is_wild) {
                 return;
             }
             print::to_string(print::NO_ANN, |s| s.print_qpath(path, false))
@@ -356,6 +356,13 @@ fn check_overlapping_arms<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ex: &'tcx Expr,
     }
 }
 
+fn is_wild(pat: &impl std::ops::Deref<Target = Pat>) -> bool {
+    match pat.node {
+        PatKind::Wild => true,
+        _ => false,
+    }
+}
+
 fn check_wild_err_arm(cx: &LateContext, ex: &Expr, arms: &[Arm]) {
     let ex_ty = walk_ptrs_ty(cx.tables.expr_ty(ex));
     if match_type(cx, ex_ty, &paths::RESULT) {
@@ -364,7 +371,7 @@ fn check_wild_err_arm(cx: &LateContext, ex: &Expr, arms: &[Arm]) {
                 let path_str = print::to_string(print::NO_ANN, |s| s.print_qpath(path, false));
                 if_chain! {
                     if path_str == "Err";
-                    if inner.iter().any(|pat| pat.node == PatKind::Wild);
+                    if inner.iter().any(is_wild);
                     if let ExprBlock(ref block, _) = arm.body.node;
                     if is_panic_block(block);
                     then {
index 1d1d0ef8faa1d879be5356b5b622fe16946e5502..ca739558e6271b6d2f33cc0ed2a9ae97a5d8fb25 100644 (file)
@@ -10,7 +10,7 @@
 use crate::utils::{get_arg_name, get_trait_def_id, implements_trait, in_external_macro, in_macro, is_copy, is_expn_of, is_self,
             is_self_ty, iter_input_pats, last_path_segment, match_def_path, match_path, match_qpath, match_trait_method,
             match_type, method_chain_args, match_var, return_ty, remove_blocks, same_tys, single_segment_path, snippet,
-            span_lint, span_lint_and_sugg, span_lint_and_then, span_note_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth};
+            span_lint, span_lint_and_sugg, span_lint_and_then, span_note_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth, SpanlessEq};
 use crate::utils::paths;
 use crate::utils::sugg;
 use crate::consts::{constant, Constant};
@@ -820,8 +820,8 @@ fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, implitem: &'tcx hir::I
                     for &(method_name, n_args, self_kind, out_type, trait_name) in &TRAIT_METHODS {
                         if name == method_name &&
                         sig.decl.inputs.len() == n_args &&
-                        out_type.matches(&sig.decl.output) &&
-                        self_kind.matches(first_arg_ty, first_arg, self_ty, false, &implitem.generics) {
+                        out_type.matches(cx, &sig.decl.output) &&
+                        self_kind.matches(cx, first_arg_ty, first_arg, self_ty, false, &implitem.generics) {
                             span_lint(cx, SHOULD_IMPLEMENT_TRAIT, implitem.span, &format!(
                                 "defining a method called `{}` on this type; consider implementing \
                                 the `{}` trait or choosing a less ambiguous name", name, trait_name));
@@ -838,9 +838,9 @@ fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, implitem: &'tcx hir::I
                         if conv.check(&name.as_str());
                         if !self_kinds
                             .iter()
-                            .any(|k| k.matches(first_arg_ty, first_arg, self_ty, is_copy, &implitem.generics));
+                            .any(|k| k.matches(cx, first_arg_ty, first_arg, self_ty, is_copy, &implitem.generics));
                         then {
-                            let lint = if item.vis.node == hir::VisibilityKind::Public {
+                            let lint = if item.vis.node.is_pub() {
                                 WRONG_PUB_SELF_CONVENTION
                             } else {
                                 WRONG_SELF_CONVENTION
@@ -2030,6 +2030,7 @@ enum SelfKind {
 impl SelfKind {
     fn matches(
         self,
+        cx: &LateContext,
         ty: &hir::Ty,
         arg: &hir::Arg,
         self_ty: &hir::Ty,
@@ -2047,7 +2048,7 @@ fn matches(
         // `Self`, `&mut Self`,
         // and `Box<Self>`, including the equivalent types with `Foo`.
 
-        let is_actually_self = |ty| is_self_ty(ty) || ty == self_ty;
+        let is_actually_self = |ty| is_self_ty(ty) || SpanlessEq::new(cx).eq_ty(ty, self_ty);
         if is_self(arg) {
             match self {
                 SelfKind::Value => is_actually_self(ty),
@@ -2173,12 +2174,13 @@ enum OutType {
 }
 
 impl OutType {
-    fn matches(self, ty: &hir::FunctionRetTy) -> bool {
+    fn matches(self, cx: &LateContext, ty: &hir::FunctionRetTy) -> bool {
+        let is_unit = |ty: &hir::Ty| SpanlessEq::new(cx).eq_ty_kind(&ty.node, &hir::TyTup(vec![].into()));
         match (self, ty) {
             (OutType::Unit, &hir::DefaultReturn(_)) => true,
-            (OutType::Unit, &hir::Return(ref ty)) if ty.node == hir::TyTup(vec![].into()) => true,
+            (OutType::Unit, &hir::Return(ref ty)) if is_unit(ty) => true,
             (OutType::Bool, &hir::Return(ref ty)) if is_bool(ty) => true,
-            (OutType::Any, &hir::Return(ref ty)) if ty.node != hir::TyTup(vec![].into()) => true,
+            (OutType::Any, &hir::Return(ref ty)) if !is_unit(ty) => true,
             (OutType::Ref, &hir::Return(ref ty)) => matches!(ty.node, hir::TyRptr(_, _)),
             _ => false,
         }
index 697f15bdd1da5dec4189d1585ed24e11651d20a3..4fc65b2f89af73ea9312849e4e3026f4ee7346f7 100644 (file)
@@ -6,7 +6,7 @@
 use syntax::codemap::{ExpnFormat, Span};
 use crate::utils::{get_item_name, get_parent_expr, implements_trait, in_constant, in_macro, is_integer_literal,
             iter_input_pats, last_path_segment, match_qpath, match_trait_method, paths, snippet, span_lint,
-            span_lint_and_then, walk_ptrs_ty};
+            span_lint_and_then, walk_ptrs_ty, SpanlessEq};
 use crate::utils::sugg::Sugg;
 use syntax::ast::{LitKind, CRATE_NODE_ID};
 use crate::consts::{constant, Constant};
@@ -418,7 +418,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
 
     fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
         if let PatKind::Binding(_, _, ident, Some(ref right)) = pat.node {
-            if right.node == PatKind::Wild {
+            if let PatKind::Wild = right.node {
                 span_lint(
                     cx,
                     REDUNDANT_PATTERN,
@@ -542,7 +542,7 @@ fn check_to_owned(cx: &LateContext, expr: &Expr, other: &Expr) {
 fn is_used(cx: &LateContext, expr: &Expr) -> bool {
     if let Some(parent) = get_parent_expr(cx, expr) {
         match parent.node {
-            ExprAssign(_, ref rhs) | ExprAssignOp(_, _, ref rhs) => **rhs == *expr,
+            ExprAssign(_, ref rhs) | ExprAssignOp(_, _, ref rhs) => SpanlessEq::new(cx).eq_expr(rhs, expr),
             _ => is_used(cx, parent),
         }
     } else {
index 87e4d343ab45b87f36618c380df77059c3c4c623..e527a05c85185addd950ab3f23be4cbb5f6656cc 100644 (file)
@@ -213,7 +213,7 @@ fn check_pat(&mut self, cx: &EarlyContext, pat: &Pat) {
                 .name;
 
             for field in pfields {
-                if field.node.pat.node == PatKind::Wild {
+                if let PatKind::Wild = field.node.pat.node {
                     wilds += 1;
                 }
             }
@@ -231,14 +231,15 @@ fn check_pat(&mut self, cx: &EarlyContext, pat: &Pat) {
                 let mut normal = vec![];
 
                 for field in pfields {
-                    if field.node.pat.node != PatKind::Wild {
-                        if let Ok(n) = cx.sess().codemap().span_to_snippet(field.span) {
+                    match field.node.pat.node {
+                        PatKind::Wild => {},
+                        _ => if let Ok(n) = cx.sess().codemap().span_to_snippet(field.span) {
                             normal.push(n);
-                        }
+                        },
                     }
                 }
                 for field in pfields {
-                    if field.node.pat.node == PatKind::Wild {
+                    if let PatKind::Wild = field.node.pat.node {
                         wilds -= 1;
                         if wilds > 0 {
                             span_lint(
index 3a95471d0a288f5610f6ccac212d545c221ee688..c5b0c97795668c8d872fbbfcca7dd86a4d6d9391 100644 (file)
@@ -1,6 +1,6 @@
 use rustc::lint::*;
 use rustc::hir::*;
-use crate::utils::span_lint;
+use crate::utils::{span_lint, SpanlessEq};
 
 /// **What it does:** Detects classic underflow/overflow checks.
 ///
@@ -31,13 +31,14 @@ fn get_lints(&self) -> LintArray {
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OverflowCheckConditional {
     // a + b < a, a > a + b, a < a - b, a - b > a
     fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
+        let eq = |l, r| SpanlessEq::new(cx).eq_path_segment(l, r);
         if_chain! {
             if let Expr_::ExprBinary(ref op, ref first, ref second) = expr.node;
             if let Expr_::ExprBinary(ref op2, ref ident1, ref ident2) = first.node;
             if let Expr_::ExprPath(QPath::Resolved(_, ref path1)) = ident1.node;
             if let Expr_::ExprPath(QPath::Resolved(_, ref path2)) = ident2.node;
             if let Expr_::ExprPath(QPath::Resolved(_, ref path3)) = second.node;
-            if path1.segments[0] == path3.segments[0] || path2.segments[0] == path3.segments[0];
+            if eq(&path1.segments[0], &path3.segments[0]) || eq(&path2.segments[0], &path3.segments[0]);
             if cx.tables.expr_ty(ident1).is_integral();
             if cx.tables.expr_ty(ident2).is_integral();
             then {
@@ -62,7 +63,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
             if let Expr_::ExprPath(QPath::Resolved(_, ref path1)) = ident1.node;
             if let Expr_::ExprPath(QPath::Resolved(_, ref path2)) = ident2.node;
             if let Expr_::ExprPath(QPath::Resolved(_, ref path3)) = first.node;
-            if path1.segments[0] == path3.segments[0] || path2.segments[0] == path3.segments[0];
+            if eq(&path1.segments[0], &path3.segments[0]) || eq(&path2.segments[0], &path3.segments[0]);
             if cx.tables.expr_ty(ident1).is_integral();
             if cx.tables.expr_ty(ident2).is_integral();
             then {
index 6ec624d26e9271a10b4e239274565d971f3d6003..c0fac47b34e82db2209754873e886e50cb7aed82 100644 (file)
@@ -3,7 +3,7 @@
 use syntax::ast::RangeLimits;
 use syntax::codemap::Spanned;
 use crate::utils::{is_integer_literal, paths, snippet, span_lint, span_lint_and_then};
-use crate::utils::{get_trait_def_id, higher, implements_trait};
+use crate::utils::{get_trait_def_id, higher, implements_trait, SpanlessEq};
 use crate::utils::sugg::Sugg;
 
 /// **What it does:** Checks for calling `.step_by(0)` on iterators,
@@ -118,7 +118,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
                     // .iter() and .len() called on same Path
                     if let ExprPath(QPath::Resolved(_, ref iter_path)) = iter_args[0].node;
                     if let ExprPath(QPath::Resolved(_, ref len_path)) = len_args[0].node;
-                    if iter_path.segments == len_path.segments;
+                    if SpanlessEq::new(cx).eq_path_segments(&iter_path.segments, &len_path.segments);
                      then {
                          span_lint(cx,
                                    RANGE_ZIP_WITH_LEN,
index f95fb046b4978b15aae1c1db03713da7db19b663..1f6092789e53161fd07073ad1f32fd58ef591614 100644 (file)
@@ -118,7 +118,7 @@ pub fn eq_expr(&mut self, left: &Expr, right: &Expr) -> bool {
                 })
             },
             (&ExprMethodCall(ref l_path, _, ref l_args), &ExprMethodCall(ref r_path, _, ref r_args)) => {
-                !self.ignore_fn && l_path == r_path && self.eq_exprs(l_args, r_args)
+                !self.ignore_fn && self.eq_path_segment(l_path, r_path) && self.eq_exprs(l_args, r_args)
             },
             (&ExprRepeat(ref le, ref ll_id), &ExprRepeat(ref re, ref rl_id)) => {
                 let mut celcx = constant_context(self.cx, self.cx.tcx.body_tables(ll_id.body));
@@ -225,7 +225,11 @@ fn eq_path_parameters(&mut self, left: &GenericArgs, right: &GenericArgs) -> boo
         }
     }
 
-    fn eq_path_segment(&mut self, left: &PathSegment, right: &PathSegment) -> bool {
+    pub fn eq_path_segments(&mut self, left: &[PathSegment], right: &[PathSegment]) -> bool {
+        left.len() == right.len() && left.iter().zip(right).all(|(l, r)| self.eq_path_segment(l, r))
+    }
+
+    pub fn eq_path_segment(&mut self, left: &PathSegment, right: &PathSegment) -> bool {
         // The == of idents doesn't work with different contexts,
         // we have to be explicit about hygiene
         if left.ident.as_str() != right.ident.as_str() {
@@ -238,8 +242,12 @@ fn eq_path_segment(&mut self, left: &PathSegment, right: &PathSegment) -> bool {
         }
     }
 
-    fn eq_ty(&mut self, left: &Ty, right: &Ty) -> bool {
-        match (&left.node, &right.node) {
+    pub fn eq_ty(&mut self, left: &Ty, right: &Ty) -> bool {
+        self.eq_ty_kind(&left.node, &right.node)
+    }
+
+    pub fn eq_ty_kind(&mut self, left: &Ty_, right: &Ty_) -> bool {
+        match (left, right) {
             (&TySlice(ref l_vec), &TySlice(ref r_vec)) => self.eq_ty(l_vec, r_vec),
             (&TyArray(ref lt, ref ll_id), &TyArray(ref rt, ref rl_id)) => {
                 let full_table = self.tables;
@@ -336,7 +344,12 @@ pub fn hash_block(&mut self, b: &Block) {
             self.hash_expr(e);
         }
 
-        b.rules.hash(&mut self.s);
+        match b.rules {
+            BlockCheckMode::DefaultBlock => 0,
+            BlockCheckMode::UnsafeBlock(_) => 1,
+            BlockCheckMode::PushUnsafeBlock(_) => 2,
+            BlockCheckMode::PopUnsafeBlock(_) => 3,
+        }.hash(&mut self.s);
     }
 
     #[allow(many_single_char_names)]
@@ -419,7 +432,10 @@ pub fn hash_expr(&mut self, e: &Expr) {
             ExprClosure(cap, _, eid, _, _) => {
                 let c: fn(_, _, _, _, _) -> _ = ExprClosure;
                 c.hash(&mut self.s);
-                cap.hash(&mut self.s);
+                match cap {
+                    CaptureClause::CaptureByValue => 0,
+                    CaptureClause::CaptureByRef => 1,
+                }.hash(&mut self.s);
                 self.hash_expr(&self.cx.tcx.hir.body(eid).value);
             },
             ExprField(ref e, ref f) => {
index f0e3961600c108d805ab3145f583b2655fca15d4..ef26b77ea1a4fee5ec68ec01a66718cd5303d2e2 100644 (file)
@@ -120,12 +120,14 @@ fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
         if let ItemStatic(ref ty, MutImmutable, body_id) = item.node {
             if is_lint_ref_type(ty) {
                 self.declared_lints.insert(item.name, item.span);
-            } else if is_lint_array_type(ty) && item.vis.node == VisibilityKind::Inherited && item.name == "ARRAY" {
-                let mut collector = LintCollector {
-                    output: &mut self.registered_lints,
-                    cx,
-                };
-                collector.visit_expr(&cx.tcx.hir.body(body_id).value);
+            } else if is_lint_array_type(ty) && item.name == "ARRAY" {
+                if let VisibilityKind::Inherited = item.vis.node {
+                    let mut collector = LintCollector {
+                        output: &mut self.registered_lints,
+                        cx,
+                    };
+                    collector.visit_expr(&cx.tcx.hir.body(body_id).value);
+                }
             }
         }
     }