]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/inherent_impl.rs
Auto merge of #6601 - mdm:fix-unit-args-false-positive, r=camsteffen
[rust.git] / clippy_lints / src / inherent_impl.rs
index 7e2975ac2ae907fe0ab7a4c8ac2111a3450edb46..005c461f105e60a7e3f4582788572d84cd81547b 100644 (file)
@@ -2,7 +2,7 @@
 
 use crate::utils::{in_macro, span_lint_and_then};
 use rustc_data_structures::fx::FxHashMap;
-use rustc_hir::{def_id, Crate, Item, ItemKind};
+use rustc_hir::{def_id, Crate, Impl, Item, ItemKind};
 use rustc_lint::{LateContext, LateLintPass};
 use rustc_session::{declare_tool_lint, impl_lint_pass};
 use rustc_span::Span;
@@ -47,32 +47,27 @@ pub struct MultipleInherentImpl {
 
 impl_lint_pass!(MultipleInherentImpl => [MULTIPLE_INHERENT_IMPL]);
 
-impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MultipleInherentImpl {
-    fn check_item(&mut self, _: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) {
-        if let ItemKind::Impl {
+impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
+    fn check_item(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) {
+        if let ItemKind::Impl(Impl {
             ref generics,
             of_trait: None,
             ..
-        } = item.kind
+        }) = item.kind
         {
-            // Remember for each inherent implementation encoutered its span and generics
+            // Remember for each inherent implementation encountered its span and generics
             // but filter out implementations that have generic params (type or lifetime)
             // or are derived from a macro
             if !in_macro(item.span) && generics.params.is_empty() {
-                self.impls.insert(item.hir_id.owner.to_def_id(), item.span);
+                self.impls.insert(item.def_id.to_def_id(), item.span);
             }
         }
     }
 
-    fn check_crate_post(&mut self, cx: &LateContext<'a, 'tcx>, krate: &'tcx Crate<'_>) {
-        if let Some(item) = krate.items.values().next() {
+    fn check_crate_post(&mut self, cx: &LateContext<'tcx>, krate: &'tcx Crate<'_>) {
+        if !krate.items.is_empty() {
             // Retrieve all inherent implementations from the crate, grouped by type
-            for impls in cx
-                .tcx
-                .crate_inherent_impls(item.hir_id.owner.to_def_id().krate)
-                .inherent_impls
-                .values()
-            {
+            for impls in cx.tcx.crate_inherent_impls(def_id::LOCAL_CRATE).inherent_impls.values() {
                 // Filter out implementations that have generic params (type or lifetime)
                 let mut impl_spans = impls.iter().filter_map(|impl_def| self.impls.get(impl_def));
                 if let Some(initial_span) = impl_spans.next() {
@@ -81,9 +76,9 @@ fn check_crate_post(&mut self, cx: &LateContext<'a, 'tcx>, krate: &'tcx Crate<'_
                             cx,
                             MULTIPLE_INHERENT_IMPL,
                             *additional_span,
-                            "Multiple implementations of this structure",
+                            "multiple implementations of this structure",
                             |diag| {
-                                diag.span_note(*initial_span, "First implementation here");
+                                diag.span_note(*initial_span, "first implementation here");
                             },
                         )
                     })