Skip to content

Commit 6a142ba

Browse files
committed
Make missing_inline_in_public_items warn on executables
1 parent b77b916 commit 6a142ba

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

clippy_lints/src/missing_inline.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use clippy_utils::diagnostics::span_lint;
2-
use clippy_utils::fulfill_or_allowed;
32
use rustc_hir::attrs::AttributeKind;
43
use rustc_hir::def_id::DefId;
54
use rustc_hir::{self as hir, Attribute, find_attr};
@@ -76,13 +75,13 @@ fn check_missing_inline_attrs(cx: &LateContext<'_>, attrs: &[Attribute], sp: Spa
7675
}
7776
}
7877

79-
fn is_executable_or_proc_macro(cx: &LateContext<'_>) -> bool {
78+
fn is_proc_macro(cx: &LateContext<'_>) -> bool {
8079
use rustc_session::config::CrateType;
8180

8281
cx.tcx
8382
.crate_types()
8483
.iter()
85-
.any(|t: &CrateType| matches!(t, CrateType::Executable | CrateType::ProcMacro))
84+
.any(|t: &CrateType| matches!(t, CrateType::ProcMacro))
8685
}
8786

8887
declare_lint_pass!(MissingInline => [MISSING_INLINE_IN_PUBLIC_ITEMS]);
@@ -93,10 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
9392
return;
9493
}
9594

96-
if is_executable_or_proc_macro(cx)
97-
// Allow the lint if it is expected, when building with `--test`
98-
&& !(cx.sess().is_test_crate() && fulfill_or_allowed(cx, MISSING_INLINE_IN_PUBLIC_ITEMS, [it.hir_id()]))
99-
{
95+
if is_proc_macro(cx) {
10096
return;
10197
}
10298

@@ -159,7 +155,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
159155
}
160156

161157
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {
162-
if impl_item.span.in_external_macro(cx.sess().source_map()) || is_executable_or_proc_macro(cx) {
158+
if impl_item.span.in_external_macro(cx.sess().source_map()) || is_proc_macro(cx) {
163159
return;
164160
}
165161

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
//@ check-pass
2-
31
#![warn(clippy::missing_inline_in_public_items)]
42

53
pub fn foo() {}
4+
//~^ missing_inline_in_public_items
65

76
fn main() {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: missing `#[inline]` for a function
2+
--> tests/ui/missing_inline_executable.rs:3:1
3+
|
4+
LL | pub fn foo() {}
5+
| ^^^^^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::missing-inline-in-public-items` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::missing_inline_in_public_items)]`
9+
10+
error: aborting due to 1 previous error
11+

0 commit comments

Comments
 (0)