]> git.lizzy.rs Git - rust.git/commitdiff
do not apply lint to executable crate type
authorgnzlbg <gonzalobg88@gmail.com>
Wed, 4 Jul 2018 14:39:52 +0000 (16:39 +0200)
committergnzlbg <gonzalobg88@gmail.com>
Wed, 4 Jul 2018 14:39:52 +0000 (16:39 +0200)
clippy_lints/src/missing_inline.rs
tests/ui/missing_inline.rs

index ba4c7678d6c17225ec94553526294519b1879f35..5d17c921cc061c6c5967c0dde655eb240ced6a39 100644 (file)
@@ -83,6 +83,17 @@ fn check_missing_inline_attrs(&self, cx: &LateContext,
     }
 }
 
+fn is_executable<'a, 'tcx>(cx: &LateContext<'a, 'tcx>) -> bool {
+    use rustc::session::config::CrateType;
+
+    cx.tcx.sess.crate_types.get().iter().any(|t: &CrateType| {
+        match t {
+            CrateType::CrateTypeExecutable => true,
+            _ => false,
+        }
+    })
+}
+
 impl LintPass for MissingInline {
     fn get_lints(&self) -> LintArray {
         lint_array![MISSING_INLINE_IN_PUBLIC_ITEMS]
@@ -91,19 +102,15 @@ fn get_lints(&self) -> LintArray {
 
 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) {
+            return;
+        }
+
         if !cx.access_levels.is_exported(it.id) {
             return;
         }
         match it.node {
             hir::ItemFn(..) => {
-                // ignore main()
-                if it.name == "main" {
-                    let def_id = cx.tcx.hir.local_def_id(it.id);
-                    let def_key = cx.tcx.hir.def_key(def_id);
-                    if def_key.parent == Some(hir::def_id::CRATE_DEF_INDEX) {
-                        return;
-                    }
-                }
                 let desc = "a function";
                 self.check_missing_inline_attrs(cx, &it.attrs, it.span, desc);
             },
@@ -148,6 +155,9 @@ fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) {
 
     fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx hir::ImplItem) {
         use rustc::ty::{TraitContainer, ImplContainer};
+        if is_executable(cx) {
+            return;
+        }
 
         // If the item being implemented is not exported, then we don't need #[inline]
         if !cx.access_levels.is_exported(impl_item.id) {
index 5dc473ef09dac1348873f0d5cc81caae22d61366..38f5903307164967f7ef77b5420fc6dd56e472eb 100644 (file)
@@ -11,7 +11,7 @@
  *   except according to those terms.
  */
 #![warn(missing_inline_in_public_items)]
-
+#![crate_type = "dylib"]
 // When denying at the crate level, be sure to not get random warnings from the
 // injected intrinsics by the compiler.
 #![allow(dead_code, non_snake_case)]
@@ -34,13 +34,13 @@ pub fn pub_foo() {} // missing #[inline]
 
 #[allow(missing_inline_in_public_items)]
 pub fn pub_foo_no_inline() {}
-fn main() {}
 
 trait Bar {
     fn Bar_a(); // ok
     fn Bar_b() {} // ok
 }
 
+
 pub trait PubBar {
     fn PubBar_a(); // ok
     fn PubBar_b() {} // missing #[inline]