Skip to content

Commit e528256

Browse files
committed
fix: missing_inline_in_public_items fail to fulfill expect in --test build
1 parent ae8ff77 commit e528256

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

clippy_lints/src/missing_inline.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use clippy_utils::diagnostics::span_lint;
2+
use clippy_utils::lint_is_expected;
23
use rustc_attr_data_structures::{AttributeKind, find_attr};
34
use rustc_hir as hir;
45
use rustc_hir::Attribute;
@@ -88,7 +89,14 @@ declare_lint_pass!(MissingInline => [MISSING_INLINE_IN_PUBLIC_ITEMS]);
8889

8990
impl<'tcx> LateLintPass<'tcx> for MissingInline {
9091
fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
91-
if it.span.in_external_macro(cx.sess().source_map()) || is_executable_or_proc_macro(cx) {
92+
if it.span.in_external_macro(cx.sess().source_map()) {
93+
return;
94+
}
95+
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() && lint_is_expected(cx, it.owner_id, MISSING_INLINE_IN_PUBLIC_ITEMS))
99+
{
92100
return;
93101
}
94102

clippy_utils/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3567,3 +3567,16 @@ pub fn potential_return_of_enclosing_body(cx: &LateContext<'_>, expr: &Expr<'_>)
35673567
// enclosing body.
35683568
false
35693569
}
3570+
3571+
/// Checks if the given lint is `expected`:
3572+
/// ```rust
3573+
/// #[expect(clippy::lint_name)]
3574+
/// fn foo() {}
3575+
/// ```
3576+
pub fn lint_is_expected(cx: &LateContext<'_>, owner_id: OwnerId, lint: &'static Lint) -> bool {
3577+
cx.tcx
3578+
.shallow_lint_levels_on(owner_id)
3579+
.specs
3580+
.iter()
3581+
.any(|(_, lint_map)| lint_map.iter().any(|(lint_id, _)| lint_id.lint.name == lint.name))
3582+
}

tests/ui/missing_inline_test_crate.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@compile-flags: --test
2+
//@check-pass
3+
#![warn(clippy::missing_inline_in_public_items)]
4+
#![crate_type = "dylib"]
5+
// When denying at the crate level, be sure to not get random warnings from the
6+
// injected intrinsics by the compiler.
7+
#![allow(dead_code)]
8+
9+
#[expect(clippy::missing_inline_in_public_items)]
10+
pub fn foo() -> u32 {
11+
0
12+
}

0 commit comments

Comments
 (0)