Skip to content

Commit 33a5d5e

Browse files
committed
Make missing_inline_in_public_items warn on executables
1 parent b42f87c commit 33a5d5e

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

clippy_lints/src/missing_inline.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rustc_hir::def_id::DefId;
55
use rustc_hir::{self as hir, Attribute, find_attr};
66
use rustc_lint::{LateContext, LateLintPass, LintContext};
77
use rustc_middle::ty::AssocContainer;
8+
use rustc_session::config::CrateType;
89
use rustc_session::declare_lint_pass;
910
use rustc_span::Span;
1011

@@ -82,15 +83,6 @@ fn check_missing_inline_attrs(
8283
}
8384
}
8485

85-
fn is_executable_or_proc_macro(cx: &LateContext<'_>) -> bool {
86-
use rustc_session::config::CrateType;
87-
88-
cx.tcx
89-
.crate_types()
90-
.iter()
91-
.any(|t: &CrateType| matches!(t, CrateType::Executable | CrateType::ProcMacro))
92-
}
93-
9486
declare_lint_pass!(MissingInline => [MISSING_INLINE_IN_PUBLIC_ITEMS]);
9587

9688
impl<'tcx> LateLintPass<'tcx> for MissingInline {
@@ -99,7 +91,11 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
9991
return;
10092
}
10193

102-
if is_executable_or_proc_macro(cx)
94+
if cx
95+
.tcx
96+
.crate_types()
97+
.iter()
98+
.any(|t: &CrateType| matches!(t, CrateType::ProcMacro))
10399
// Allow the lint if it is expected, when building with `--test`
104100
&& !(cx.sess().is_test_crate() && fulfill_or_allowed(cx, MISSING_INLINE_IN_PUBLIC_ITEMS, [it.hir_id()]))
105101
{
@@ -157,7 +153,13 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
157153
}
158154

159155
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {
160-
if impl_item.span.in_external_macro(cx.sess().source_map()) || is_executable_or_proc_macro(cx) {
156+
if impl_item.span.in_external_macro(cx.sess().source_map())
157+
|| cx
158+
.tcx
159+
.crate_types()
160+
.iter()
161+
.any(|t: &CrateType| matches!(t, CrateType::ProcMacro))
162+
{
161163
return;
162164
}
163165

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+

tests/ui/missing_inline_test_crate.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
pub fn foo() -> u32 {
77
0
88
}
9+
10+
fn private_function() {}

0 commit comments

Comments
 (0)