From 14cbdf2607faafd608ea94234456c509e058e291 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 4 Jul 2018 16:39:52 +0200 Subject: [PATCH] do not apply lint to executable crate type --- clippy_lints/src/missing_inline.rs | 26 ++++++++++++++++++-------- tests/ui/missing_inline.rs | 4 ++-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index ba4c7678d6c..5d17c921cc0 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -83,6 +83,17 @@ impl MissingInline { } } +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 @@ impl LintPass for MissingInline { 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 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline { 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) { diff --git a/tests/ui/missing_inline.rs b/tests/ui/missing_inline.rs index 5dc473ef09d..38f59033071 100644 --- a/tests/ui/missing_inline.rs +++ b/tests/ui/missing_inline.rs @@ -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]