diff options
| author | hyd-dev <yd-huang@outlook.com> | 2021-02-28 20:44:07 +0800 |
|---|---|---|
| committer | hyd-dev <yd-huang@outlook.com> | 2021-02-28 21:10:44 +0800 |
| commit | da3a57377ea34c1ddb0c0c41defb456b8dceed53 (patch) | |
| tree | 8d6250638b225fc1ba6727cda06a0996193e3b01 | |
| parent | abd2c7ebfb47b3e2dbbb3ce3a7a54ef3847bb7dc (diff) | |
| download | rust-da3a57377ea34c1ddb0c0c41defb456b8dceed53.tar.gz rust-da3a57377ea34c1ddb0c0c41defb456b8dceed53.zip | |
Fix false positives on procedural macros of `missing_inline_in_public_items` lint
| -rw-r--r-- | clippy_lints/src/missing_inline.rs | 8 | ||||
| -rw-r--r-- | tests/ui/missing_inline_executable.rs | 5 | ||||
| -rw-r--r-- | tests/ui/missing_inline_proc_macro.rs | 23 |
3 files changed, 32 insertions, 4 deletions
diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 47d7c5306c4..2448325e899 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -69,21 +69,21 @@ fn check_missing_inline_attrs(cx: &LateContext<'_>, attrs: &[ast::Attribute], sp } } -fn is_executable(cx: &LateContext<'_>) -> bool { +fn is_executable_or_proc_macro(cx: &LateContext<'_>) -> bool { use rustc_session::config::CrateType; cx.tcx .sess .crate_types() .iter() - .any(|t: &CrateType| matches!(t, CrateType::Executable)) + .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 rustc_middle::lint::in_external_macro(cx.sess(), it.span) || is_executable(cx) { + if rustc_middle::lint::in_external_macro(cx.sess(), it.span) || is_executable_or_proc_macro(cx) { return; } @@ -133,7 +133,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) { use rustc_middle::ty::{ImplContainer, TraitContainer}; - if rustc_middle::lint::in_external_macro(cx.sess(), impl_item.span) || is_executable(cx) { + if rustc_middle::lint::in_external_macro(cx.sess(), impl_item.span) || is_executable_or_proc_macro(cx) { return; } diff --git a/tests/ui/missing_inline_executable.rs b/tests/ui/missing_inline_executable.rs new file mode 100644 index 00000000000..6e0400ac935 --- /dev/null +++ b/tests/ui/missing_inline_executable.rs @@ -0,0 +1,5 @@ +#![warn(clippy::missing_inline_in_public_items)] + +pub fn foo() {} + +fn main() {} diff --git a/tests/ui/missing_inline_proc_macro.rs b/tests/ui/missing_inline_proc_macro.rs new file mode 100644 index 00000000000..3c68fb905f1 --- /dev/null +++ b/tests/ui/missing_inline_proc_macro.rs @@ -0,0 +1,23 @@ +#![warn(clippy::missing_inline_in_public_items)] +#![crate_type = "proc-macro"] + +extern crate proc_macro; + +use proc_macro::TokenStream; + +fn _foo() {} + +#[proc_macro] +pub fn function_like(_: TokenStream) -> TokenStream { + TokenStream::new() +} + +#[proc_macro_attribute] +pub fn attribute(_: TokenStream, _: TokenStream) -> TokenStream { + TokenStream::new() +} + +#[proc_macro_derive(Derive)] +pub fn derive(_: TokenStream) -> TokenStream { + TokenStream::new() +} |
