From 5488672d1f1ae02cc9910ecd67485affce996bc8 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sun, 1 Dec 2019 19:26:33 +0700 Subject: [PATCH] account for external macro in MISSING_INLINE_IN_PUBLIC_ITEMS lint --- clippy_lints/src/missing_inline.rs | 6 +++--- tests/ui/missing_inline.rs | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index d9cd78dcd41..927ead77a24 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -1,6 +1,6 @@ use crate::utils::span_lint; use rustc::hir; -use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; +use rustc::lint::{self, LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::{declare_lint_pass, declare_tool_lint}; use syntax::ast; use syntax::source_map::Span; @@ -81,7 +81,7 @@ declare_lint_pass!(MissingInline => [MISSING_INLINE_IN_PUBLIC_ITEMS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) { - if is_executable(cx) { + if lint::in_external_macro(cx.sess(), it.span) || is_executable(cx) { return; } @@ -131,7 +131,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline { fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx hir::ImplItem) { use rustc::ty::{ImplContainer, TraitContainer}; - if is_executable(cx) { + if lint::in_external_macro(cx.sess(), impl_item.span) || is_executable(cx) { return; } diff --git a/tests/ui/missing_inline.rs b/tests/ui/missing_inline.rs index 2b2ea6c94c2..b73b24b8e0a 100644 --- a/tests/ui/missing_inline.rs +++ b/tests/ui/missing_inline.rs @@ -60,3 +60,7 @@ impl Foo { impl PubFoo { pub fn PubFooImpl() {} // missing #[inline] } + +// do not lint this since users cannot control the external code +#[derive(Debug)] +pub struct S {}