Fix missing_inline_in_public_items fail to fulfill expect in --test build (#15320)
Closes rust-lang/rust-clippy#13394 changelog: [`missing_inline_in_public_items`] fix failure to fulfill `expect` in `--test` build
This commit is contained in:
commit
52a39998fa
4 changed files with 40 additions and 13 deletions
|
|
@ -4,6 +4,7 @@ use rustc_hir::def_id::DefId;
|
|||
use rustc_hir::{self as hir, Attribute, find_attr};
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_middle::ty::AssocContainer;
|
||||
use rustc_session::config::CrateType;
|
||||
use rustc_session::declare_lint_pass;
|
||||
use rustc_span::Span;
|
||||
|
||||
|
|
@ -81,20 +82,20 @@ fn check_missing_inline_attrs(
|
|||
}
|
||||
}
|
||||
|
||||
fn is_executable_or_proc_macro(cx: &LateContext<'_>) -> bool {
|
||||
use rustc_session::config::CrateType;
|
||||
|
||||
cx.tcx
|
||||
.crate_types()
|
||||
.iter()
|
||||
.any(|t: &CrateType| matches!(t, CrateType::Executable | CrateType::ProcMacro))
|
||||
}
|
||||
|
||||
declare_lint_pass!(MissingInline => [MISSING_INLINE_IN_PUBLIC_ITEMS]);
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for MissingInline {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
|
||||
if it.span.in_external_macro(cx.sess().source_map()) || is_executable_or_proc_macro(cx) {
|
||||
if it.span.in_external_macro(cx.sess().source_map()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if cx
|
||||
.tcx
|
||||
.crate_types()
|
||||
.iter()
|
||||
.any(|t: &CrateType| matches!(t, CrateType::ProcMacro))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -149,7 +150,13 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
|
|||
}
|
||||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {
|
||||
if impl_item.span.in_external_macro(cx.sess().source_map()) || is_executable_or_proc_macro(cx) {
|
||||
if impl_item.span.in_external_macro(cx.sess().source_map())
|
||||
|| cx
|
||||
.tcx
|
||||
.crate_types()
|
||||
.iter()
|
||||
.any(|t: &CrateType| matches!(t, CrateType::ProcMacro))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
//@ check-pass
|
||||
|
||||
#![warn(clippy::missing_inline_in_public_items)]
|
||||
|
||||
pub fn foo() {}
|
||||
//~^ missing_inline_in_public_items
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
11
tests/ui/missing_inline_executable.stderr
Normal file
11
tests/ui/missing_inline_executable.stderr
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
error: missing `#[inline]` for a function
|
||||
--> tests/ui/missing_inline_executable.rs:3:1
|
||||
|
|
||||
LL | pub fn foo() {}
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::missing-inline-in-public-items` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::missing_inline_in_public_items)]`
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
10
tests/ui/missing_inline_test_crate.rs
Normal file
10
tests/ui/missing_inline_test_crate.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
//@compile-flags: --test
|
||||
//@check-pass
|
||||
#![warn(clippy::missing_inline_in_public_items)]
|
||||
|
||||
#[expect(clippy::missing_inline_in_public_items)]
|
||||
pub fn foo() -> u32 {
|
||||
0
|
||||
}
|
||||
|
||||
fn private_function() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue