]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/missing_inline.rs
Merge branch 'macro-use' into HEAD
[rust.git] / clippy_lints / src / missing_inline.rs
index 7b13aee9a55101c5c2ded647ae0a66c0923ff5c2..cc57e771064b4ba6a7b8b17f1b66953d5f07f936 100644 (file)
@@ -11,6 +11,7 @@
 
 use rustc::hir;
 use rustc::lint::*;
+use rustc::{declare_lint, lint_array};
 use syntax::ast;
 use syntax::codemap::Span;
 
@@ -108,11 +109,11 @@ fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) {
             return;
         }
         match it.node {
-            hir::ItemFn(..) => {
+            hir::ItemKind::Fn(..) => {
                 let desc = "a function";
                 check_missing_inline_attrs(cx, &it.attrs, it.span, desc);
             },
-            hir::ItemTrait(ref _is_auto, ref _unsafe, ref _generics,
+            hir::ItemKind::Trait(ref _is_auto, ref _unsafe, ref _generics,
                            ref _bounds, ref trait_items)  => {
                 // note: we need to check if the trait is exported so we can't use
                 // `LateLintPass::check_trait_item` here.
@@ -134,20 +135,20 @@ fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) {
                     }
                 }
             }
-            hir::ItemConst(..) |
-            hir::ItemEnum(..) |
-            hir::ItemMod(..) |
-            hir::ItemStatic(..) |
-            hir::ItemStruct(..) |
-            hir::ItemTraitAlias(..) |
-            hir::ItemGlobalAsm(..) |
-            hir::ItemTy(..) |
-            hir::ItemUnion(..) |
-            hir::ItemExistential(..) |
-            hir::ItemExternCrate(..) |
-            hir::ItemForeignMod(..) |
-            hir::ItemImpl(..) |
-            hir::ItemUse(..) => {},
+            hir::ItemKind::Const(..) |
+            hir::ItemKind::Enum(..) |
+            hir::ItemKind::Mod(..) |
+            hir::ItemKind::Static(..) |
+            hir::ItemKind::Struct(..) |
+            hir::ItemKind::TraitAlias(..) |
+            hir::ItemKind::GlobalAsm(..) |
+            hir::ItemKind::Ty(..) |
+            hir::ItemKind::Union(..) |
+            hir::ItemKind::Existential(..) |
+            hir::ItemKind::ExternCrate(..) |
+            hir::ItemKind::ForeignMod(..) |
+            hir::ItemKind::Impl(..) |
+            hir::ItemKind::Use(..) => {},
         };
     }
 
@@ -165,32 +166,24 @@ fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx hir::
         let desc = match impl_item.node {
             hir::ImplItemKind::Method(..) => "a method",
             hir::ImplItemKind::Const(..) |
-            hir::ImplItemKind::Type(_) => return,
+            hir::ImplItemKind::Type(_) |
+            hir::ImplItemKind::Existential(_) => return,
         };
 
         let def_id = cx.tcx.hir.local_def_id(impl_item.id);
-        match cx.tcx.associated_item(def_id).container {
-            TraitContainer(cid) => {
-                if let Some(n) = cx.tcx.hir.as_local_node_id(cid) {
-                    if !cx.access_levels.is_exported(n) {
-                        // If a trait is being implemented for an item, and the
-                        // trait is not exported, we don't need #[inline]
-                        return;
-                    }
-                }
-            },
-            ImplContainer(cid) => {
-                if cx.tcx.impl_trait_ref(cid).is_some() {
-                    let trait_ref = cx.tcx.impl_trait_ref(cid).unwrap();
-                    if let Some(n) = cx.tcx.hir.as_local_node_id(trait_ref.def_id) {
-                        if !cx.access_levels.is_exported(n) {
-                            // If a trait is being implemented for an item, and the
-                            // trait is not exported, we don't need #[inline]
-                            return;
-                        }
-                    }
+        let trait_def_id = match cx.tcx.associated_item(def_id).container {
+            TraitContainer(cid) => Some(cid),
+            ImplContainer(cid) => cx.tcx.impl_trait_ref(cid).map(|t| t.def_id),
+        };
+
+        if let Some(trait_def_id) = trait_def_id {
+            if let Some(n) = cx.tcx.hir.as_local_node_id(trait_def_id) {
+                if !cx.access_levels.is_exported(n) {
+                    // If a trait is being implemented for an item, and the
+                    // trait is not exported, we don't need #[inline]
+                    return;
                 }
-            },
+            }
         }
 
         check_missing_inline_attrs(cx, &impl_item.attrs, impl_item.span, desc);