diff options
| author | flip1995 <philipp.krones@embecosm.com> | 2022-01-13 13:18:19 +0100 |
|---|---|---|
| committer | flip1995 <philipp.krones@embecosm.com> | 2022-01-13 13:18:19 +0100 |
| commit | fb0142ae41a49a4dda6bc0c7487efa00818c8f49 (patch) | |
| tree | 0b51b29d80477019cca389c9b053d0d04c8d74ee /clippy_lints/src/utils/internal_lints.rs | |
| parent | dda2aef64fb5b4903a28e5d4fb8d63483642cc6f (diff) | |
Merge commit '97a5daa65908e59744e2bc625b14849352231c75' into clippyup
Diffstat (limited to 'clippy_lints/src/utils/internal_lints.rs')
| -rw-r--r-- | clippy_lints/src/utils/internal_lints.rs | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 7d196af7a53..9c3dcc8e96a 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -1,5 +1,6 @@ use clippy_utils::consts::{constant_simple, Constant}; use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then}; +use clippy_utils::macros::root_macro_call_first_node; use clippy_utils::source::snippet; use clippy_utils::ty::match_type; use clippy_utils::{ @@ -34,7 +35,7 @@ use rustc_typeck::hir_ty_to_ty; use std::borrow::{Borrow, Cow}; -#[cfg(feature = "metadata-collector-lint")] +#[cfg(feature = "internal")] pub mod metadata_collector; declare_clippy_lint! { @@ -410,9 +411,13 @@ impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass { } self.declared_lints.insert(item.ident.name, item.span); } - } else if is_expn_of(item.span, "impl_lint_pass").is_some() - || is_expn_of(item.span, "declare_lint_pass").is_some() - { + } else if let Some(macro_call) = root_macro_call_first_node(cx, item) { + if !matches!( + &*cx.tcx.item_name(macro_call.def_id).as_str(), + "impl_lint_pass" | "declare_lint_pass" + ) { + return; + } if let hir::ItemKind::Impl(hir::Impl { of_trait: None, items: impl_item_refs, @@ -924,9 +929,20 @@ pub fn check_path(cx: &LateContext<'_>, path: &[&str]) -> bool { let lang_item_path = cx.get_def_path(*item_def_id); if path_syms.starts_with(&lang_item_path) { if let [item] = &path_syms[lang_item_path.len()..] { - for child in cx.tcx.module_children(*item_def_id) { - if child.ident.name == *item { - return true; + if matches!( + cx.tcx.def_kind(*item_def_id), + DefKind::Mod | DefKind::Enum | DefKind::Trait + ) { + for child in cx.tcx.module_children(*item_def_id) { + if child.ident.name == *item { + return true; + } + } + } else { + for child in cx.tcx.associated_item_def_ids(*item_def_id) { + if cx.tcx.item_name(*child) == *item { + return true; + } } } } |
