Skip to content

Commit 14cbdf2

Browse files
committed
do not apply lint to executable crate type
1 parent 999a00b commit 14cbdf2

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

clippy_lints/src/missing_inline.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ impl MissingInline {
8383
}
8484
}
8585

86+
fn is_executable<'a, 'tcx>(cx: &LateContext<'a, 'tcx>) -> bool {
87+
use rustc::session::config::CrateType;
88+
89+
cx.tcx.sess.crate_types.get().iter().any(|t: &CrateType| {
90+
match t {
91+
CrateType::CrateTypeExecutable => true,
92+
_ => false,
93+
}
94+
})
95+
}
96+
8697
impl LintPass for MissingInline {
8798
fn get_lints(&self) -> LintArray {
8899
lint_array![MISSING_INLINE_IN_PUBLIC_ITEMS]
@@ -91,19 +102,15 @@ impl LintPass for MissingInline {
91102

92103
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
93104
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) {
105+
if is_executable(cx) {
106+
return;
107+
}
108+
94109
if !cx.access_levels.is_exported(it.id) {
95110
return;
96111
}
97112
match it.node {
98113
hir::ItemFn(..) => {
99-
// ignore main()
100-
if it.name == "main" {
101-
let def_id = cx.tcx.hir.local_def_id(it.id);
102-
let def_key = cx.tcx.hir.def_key(def_id);
103-
if def_key.parent == Some(hir::def_id::CRATE_DEF_INDEX) {
104-
return;
105-
}
106-
}
107114
let desc = "a function";
108115
self.check_missing_inline_attrs(cx, &it.attrs, it.span, desc);
109116
},
@@ -148,6 +155,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
148155

149156
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx hir::ImplItem) {
150157
use rustc::ty::{TraitContainer, ImplContainer};
158+
if is_executable(cx) {
159+
return;
160+
}
151161

152162
// If the item being implemented is not exported, then we don't need #[inline]
153163
if !cx.access_levels.is_exported(impl_item.id) {

tests/ui/missing_inline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* except according to those terms.
1212
*/
1313
#![warn(missing_inline_in_public_items)]
14-
14+
#![crate_type = "dylib"]
1515
// When denying at the crate level, be sure to not get random warnings from the
1616
// injected intrinsics by the compiler.
1717
#![allow(dead_code, non_snake_case)]
@@ -34,13 +34,13 @@ pub fn pub_foo() {} // missing #[inline]
3434

3535
#[allow(missing_inline_in_public_items)]
3636
pub fn pub_foo_no_inline() {}
37-
fn main() {}
3837

3938
trait Bar {
4039
fn Bar_a(); // ok
4140
fn Bar_b() {} // ok
4241
}
4342

43+
4444
pub trait PubBar {
4545
fn PubBar_a(); // ok
4646
fn PubBar_b() {} // missing #[inline]

0 commit comments

Comments
 (0)