do not apply lint to executable crate type
This commit is contained in:
parent
999a00bf5e
commit
14cbdf2607
2 changed files with 20 additions and 10 deletions
|
@ -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 {
|
impl LintPass for MissingInline {
|
||||||
fn get_lints(&self) -> LintArray {
|
fn get_lints(&self) -> LintArray {
|
||||||
lint_array![MISSING_INLINE_IN_PUBLIC_ITEMS]
|
lint_array![MISSING_INLINE_IN_PUBLIC_ITEMS]
|
||||||
|
@ -91,19 +102,15 @@ impl LintPass for MissingInline {
|
||||||
|
|
||||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
|
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
|
||||||
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) {
|
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) {
|
if !cx.access_levels.is_exported(it.id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
match it.node {
|
match it.node {
|
||||||
hir::ItemFn(..) => {
|
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";
|
let desc = "a function";
|
||||||
self.check_missing_inline_attrs(cx, &it.attrs, it.span, desc);
|
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) {
|
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx hir::ImplItem) {
|
||||||
use rustc::ty::{TraitContainer, ImplContainer};
|
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 the item being implemented is not exported, then we don't need #[inline]
|
||||||
if !cx.access_levels.is_exported(impl_item.id) {
|
if !cx.access_levels.is_exported(impl_item.id) {
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
* except according to those terms.
|
* except according to those terms.
|
||||||
*/
|
*/
|
||||||
#![warn(missing_inline_in_public_items)]
|
#![warn(missing_inline_in_public_items)]
|
||||||
|
#![crate_type = "dylib"]
|
||||||
// When denying at the crate level, be sure to not get random warnings from the
|
// When denying at the crate level, be sure to not get random warnings from the
|
||||||
// injected intrinsics by the compiler.
|
// injected intrinsics by the compiler.
|
||||||
#![allow(dead_code, non_snake_case)]
|
#![allow(dead_code, non_snake_case)]
|
||||||
|
@ -34,13 +34,13 @@ pub fn pub_foo() {} // missing #[inline]
|
||||||
|
|
||||||
#[allow(missing_inline_in_public_items)]
|
#[allow(missing_inline_in_public_items)]
|
||||||
pub fn pub_foo_no_inline() {}
|
pub fn pub_foo_no_inline() {}
|
||||||
fn main() {}
|
|
||||||
|
|
||||||
trait Bar {
|
trait Bar {
|
||||||
fn Bar_a(); // ok
|
fn Bar_a(); // ok
|
||||||
fn Bar_b() {} // ok
|
fn Bar_b() {} // ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub trait PubBar {
|
pub trait PubBar {
|
||||||
fn PubBar_a(); // ok
|
fn PubBar_a(); // ok
|
||||||
fn PubBar_b() {} // missing #[inline]
|
fn PubBar_b() {} // missing #[inline]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue