]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/missing_inline.rs
Auto merge of #5334 - flip1995:backport_remerge, r=flip1995
[rust.git] / clippy_lints / src / missing_inline.rs
index 3efbfbb700d72942424fdd2445d1e782198a89f4..22b56c28b6bc1aa018c2ae15dccef612f998ba12 100644 (file)
@@ -1,9 +1,9 @@
 use crate::utils::span_lint;
-use rustc::hir;
-use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
-use rustc::{declare_lint_pass, declare_tool_lint};
-use syntax::ast;
-use syntax::source_map::Span;
+use rustc_ast::ast;
+use rustc_hir as hir;
+use rustc_lint::{self, LateContext, LateLintPass, LintContext};
+use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_span::source_map::Span;
 
 declare_clippy_lint! {
     /// **What it does:** it lints if an exported function, method, trait method with default impl,
@@ -33,7 +33,7 @@
     ///
     /// struct Baz;
     /// impl Baz {
-    ///    fn priv() {} // ok
+    ///    fn private() {} // ok
     /// }
     ///
     /// impl Bar for Baz {
@@ -42,8 +42,8 @@
     ///
     /// pub struct PubBaz;
     /// impl PubBaz {
-    ///    fn priv() {} // ok
-    ///    pub not_ptriv() {} // missing #[inline]
+    ///    fn private() {} // ok
+    ///    pub fn not_ptrivate() {} // missing #[inline]
     /// }
     ///
     /// impl Bar for PubBaz {
@@ -53,7 +53,7 @@
     /// ```
     pub MISSING_INLINE_IN_PUBLIC_ITEMS,
     restriction,
-    "detects missing #[inline] attribute for public callables (functions, trait methods, methods...)"
+    "detects missing `#[inline]` attribute for public callables (functions, trait methods, methods...)"
 }
 
 fn check_missing_inline_attrs(cx: &LateContext<'_, '_>, attrs: &[ast::Attribute], sp: Span, desc: &'static str) {
@@ -69,7 +69,7 @@ fn check_missing_inline_attrs(cx: &LateContext<'_, '_>, attrs: &[ast::Attribute]
 }
 
 fn is_executable(cx: &LateContext<'_, '_>) -> bool {
-    use rustc::session::config::CrateType;
+    use rustc_session::config::CrateType;
 
     cx.tcx.sess.crate_types.get().iter().any(|t: &CrateType| match t {
         CrateType::Executable => true,
@@ -80,27 +80,27 @@ fn is_executable(cx: &LateContext<'_, '_>) -> bool {
 declare_lint_pass!(MissingInline => [MISSING_INLINE_IN_PUBLIC_ITEMS]);
 
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
-    fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) {
-        if is_executable(cx) {
+    fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item<'_>) {
+        if rustc::lint::in_external_macro(cx.sess(), it.span) || is_executable(cx) {
             return;
         }
 
         if !cx.access_levels.is_exported(it.hir_id) {
             return;
         }
-        match it.node {
+        match it.kind {
             hir::ItemKind::Fn(..) => {
                 let desc = "a function";
                 check_missing_inline_attrs(cx, &it.attrs, it.span, desc);
             },
-            hir::ItemKind::Trait(ref _is_auto, ref _unsafe, ref _generics, ref _bounds, ref trait_items) => {
+            hir::ItemKind::Trait(ref _is_auto, ref _unsafe, ref _generics, ref _bounds, trait_items) => {
                 // note: we need to check if the trait is exported so we can't use
                 // `LateLintPass::check_trait_item` here.
                 for tit in trait_items {
                     let tit_ = cx.tcx.hir().trait_item(tit.id);
-                    match tit_.node {
+                    match tit_.kind {
                         hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(..) => {},
-                        hir::TraitItemKind::Method(..) => {
+                        hir::TraitItemKind::Fn(..) => {
                             if tit.defaultness.has_value() {
                                 // trait method with default body needs inline in case
                                 // an impl is not provided
@@ -119,19 +119,19 @@ fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) {
             | hir::ItemKind::Struct(..)
             | hir::ItemKind::TraitAlias(..)
             | hir::ItemKind::GlobalAsm(..)
-            | hir::ItemKind::Ty(..)
+            | hir::ItemKind::TyAlias(..)
             | hir::ItemKind::Union(..)
-            | hir::ItemKind::Existential(..)
+            | hir::ItemKind::OpaqueTy(..)
             | hir::ItemKind::ExternCrate(..)
             | hir::ItemKind::ForeignMod(..)
-            | hir::ItemKind::Impl(..)
+            | hir::ItemKind::Impl { .. }
             | hir::ItemKind::Use(..) => {},
         };
     }
 
-    fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx hir::ImplItem) {
+    fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {
         use rustc::ty::{ImplContainer, TraitContainer};
-        if is_executable(cx) {
+        if rustc::lint::in_external_macro(cx.sess(), impl_item.span) || is_executable(cx) {
             return;
         }
 
@@ -140,9 +140,9 @@ fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx hir::
             return;
         }
 
-        let desc = match impl_item.node {
-            hir::ImplItemKind::Method(..) => "a method",
-            hir::ImplItemKind::Const(..) | hir::ImplItemKind::Type(_) | hir::ImplItemKind::Existential(_) => return,
+        let desc = match impl_item.kind {
+            hir::ImplItemKind::Fn(..) => "a method",
+            hir::ImplItemKind::Const(..) | hir::ImplItemKind::TyAlias(_) | hir::ImplItemKind::OpaqueTy(_) => return,
         };
 
         let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);