do not apply lint to executable crate type

This commit is contained in:
gnzlbg 2018-07-04 16:39:52 +02:00
parent 999a00bf5e
commit 14cbdf2607
2 changed files with 20 additions and 10 deletions

View file

@ -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) {

View 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]