Skip to content

Commit 52a3999

Browse files
authored
Fix missing_inline_in_public_items fail to fulfill expect in --test build (#15320)
Closes #13394 changelog: [`missing_inline_in_public_items`] fix failure to fulfill `expect` in `--test` build
2 parents c95d95b + a86dd63 commit 52a3999

File tree

4 files changed

+40
-13
lines changed

4 files changed

+40
-13
lines changed

clippy_lints/src/missing_inline.rs

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

@@ -81,20 +82,20 @@ fn check_missing_inline_attrs(
8182
}
8283
}
8384

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

9587
impl<'tcx> LateLintPass<'tcx> for MissingInline {
9688
fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
97-
if it.span.in_external_macro(cx.sess().source_map()) || is_executable_or_proc_macro(cx) {
89+
if it.span.in_external_macro(cx.sess().source_map()) {
90+
return;
91+
}
92+
93+
if cx
94+
.tcx
95+
.crate_types()
96+
.iter()
97+
.any(|t: &CrateType| matches!(t, CrateType::ProcMacro))
98+
{
9899
return;
99100
}
100101

@@ -149,7 +150,13 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
149150
}
150151

151152
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {
152-
if impl_item.span.in_external_macro(cx.sess().source_map()) || is_executable_or_proc_macro(cx) {
153+
if impl_item.span.in_external_macro(cx.sess().source_map())
154+
|| cx
155+
.tcx
156+
.crate_types()
157+
.iter()
158+
.any(|t: &CrateType| matches!(t, CrateType::ProcMacro))
159+
{
153160
return;
154161
}
155162

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+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//@compile-flags: --test
2+
//@check-pass
3+
#![warn(clippy::missing_inline_in_public_items)]
4+
5+
#[expect(clippy::missing_inline_in_public_items)]
6+
pub fn foo() -> u32 {
7+
0
8+
}
9+
10+
fn private_function() {}

0 commit comments

Comments
 (0)