Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix false positives on procedural macros of missing_inline_in_public_items lint #6814

Merged
merged 1 commit into from Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions clippy_lints/src/missing_inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions tests/ui/missing_inline_executable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![warn(clippy::missing_inline_in_public_items)]

pub fn foo() {}

fn main() {}
23 changes: 23 additions & 0 deletions tests/ui/missing_inline_proc_macro.rs
Original file line number Diff line number Diff line change
@@ -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()
}