Skip to content

Commit 8222d48

Browse files
committed
Auto merge of #6814 - hyd-dev:issue-6486, r=flip1995
Fix false positives on procedural macros of `missing_inline_in_public_items` lint Fixes #6486. changelog: Fix false positives on procedural macros of `missing_inline_in_public_items` lint.
2 parents a1e25a9 + da3a573 commit 8222d48

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

clippy_lints/src/missing_inline.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,21 @@ fn check_missing_inline_attrs(cx: &LateContext<'_>, attrs: &[ast::Attribute], sp
6969
}
7070
}
7171

72-
fn is_executable(cx: &LateContext<'_>) -> bool {
72+
fn is_executable_or_proc_macro(cx: &LateContext<'_>) -> bool {
7373
use rustc_session::config::CrateType;
7474

7575
cx.tcx
7676
.sess
7777
.crate_types()
7878
.iter()
79-
.any(|t: &CrateType| matches!(t, CrateType::Executable))
79+
.any(|t: &CrateType| matches!(t, CrateType::Executable | CrateType::ProcMacro))
8080
}
8181

8282
declare_lint_pass!(MissingInline => [MISSING_INLINE_IN_PUBLIC_ITEMS]);
8383

8484
impl<'tcx> LateLintPass<'tcx> for MissingInline {
8585
fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
86-
if rustc_middle::lint::in_external_macro(cx.sess(), it.span) || is_executable(cx) {
86+
if rustc_middle::lint::in_external_macro(cx.sess(), it.span) || is_executable_or_proc_macro(cx) {
8787
return;
8888
}
8989

@@ -133,7 +133,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
133133

134134
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {
135135
use rustc_middle::ty::{ImplContainer, TraitContainer};
136-
if rustc_middle::lint::in_external_macro(cx.sess(), impl_item.span) || is_executable(cx) {
136+
if rustc_middle::lint::in_external_macro(cx.sess(), impl_item.span) || is_executable_or_proc_macro(cx) {
137137
return;
138138
}
139139

tests/ui/missing_inline_executable.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#![warn(clippy::missing_inline_in_public_items)]
2+
3+
pub fn foo() {}
4+
5+
fn main() {}

tests/ui/missing_inline_proc_macro.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#![warn(clippy::missing_inline_in_public_items)]
2+
#![crate_type = "proc-macro"]
3+
4+
extern crate proc_macro;
5+
6+
use proc_macro::TokenStream;
7+
8+
fn _foo() {}
9+
10+
#[proc_macro]
11+
pub fn function_like(_: TokenStream) -> TokenStream {
12+
TokenStream::new()
13+
}
14+
15+
#[proc_macro_attribute]
16+
pub fn attribute(_: TokenStream, _: TokenStream) -> TokenStream {
17+
TokenStream::new()
18+
}
19+
20+
#[proc_macro_derive(Derive)]
21+
pub fn derive(_: TokenStream) -> TokenStream {
22+
TokenStream::new()
23+
}

0 commit comments

Comments
 (0)