diff options
| author | Timo <30553356+y21@users.noreply.github.com> | 2025-08-21 22:39:14 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-21 22:39:14 +0000 |
| commit | 9759df692411c70f31b5282e0421483c51c3a18e (patch) | |
| tree | c8ff47df1bd085c40b66cb11f440017b5a970e13 | |
| parent | cca6576a793307077129b7dc33577befb6660bb1 (diff) | |
| parent | 27b2c5dd65de132354056e5132939333672609df (diff) | |
| download | rust-9759df692411c70f31b5282e0421483c51c3a18e.tar.gz rust-9759df692411c70f31b5282e0421483c51c3a18e.zip | |
`renamed_function_params`: clean-up a bit (#15524)
changelog: none
| -rw-r--r-- | clippy_lints/src/functions/renamed_function_params.rs | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/clippy_lints/src/functions/renamed_function_params.rs b/clippy_lints/src/functions/renamed_function_params.rs index 0d6191f2c97..ba0cefaa33b 100644 --- a/clippy_lints/src/functions/renamed_function_params.rs +++ b/clippy_lints/src/functions/renamed_function_params.rs @@ -2,10 +2,11 @@ use clippy_utils::diagnostics::span_lint_and_then; use rustc_errors::{Applicability, MultiSpan}; use rustc_hir::def_id::{DefId, DefIdSet}; use rustc_hir::hir_id::OwnerId; -use rustc_hir::{Impl, ImplItem, ImplItemKind, ItemKind, Node, TraitRef}; +use rustc_hir::{ImplItem, ImplItemKind, ItemKind, Node, TraitRef}; use rustc_lint::LateContext; use rustc_span::Span; use rustc_span::symbol::{Ident, kw}; +use std::iter; use super::RENAMED_FUNCTION_PARAMS; @@ -14,12 +15,10 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, item: &ImplItem<'_>, ignored && let ImplItemKind::Fn(_, body_id) = item.kind && let parent_node = cx.tcx.parent_hir_node(item.hir_id()) && let Node::Item(parent_item) = parent_node - && let ItemKind::Impl(Impl { - of_trait: Some(trait_ref), - .. - }) = &parent_item.kind + && let ItemKind::Impl(impl_) = &parent_item.kind + && let Some(trait_ref) = impl_.of_trait && let Some(did) = trait_item_def_id_of_impl(cx, item.owner_id) - && !is_from_ignored_trait(trait_ref, ignored_traits) + && !is_from_ignored_trait(&trait_ref, ignored_traits) { let mut param_idents_iter = cx.tcx.hir_body_param_idents(body_id); let mut default_param_idents_iter = cx.tcx.fn_arg_idents(did).iter().copied(); @@ -58,16 +57,11 @@ impl RenamedFnArgs { let mut renamed: Vec<(Span, String)> = vec![]; debug_assert!(default_idents.size_hint() == current_idents.size_hint()); - while let (Some(default_ident), Some(current_ident)) = (default_idents.next(), current_idents.next()) { + for (default_ident, current_ident) in iter::zip(default_idents, current_idents) { let has_name_to_check = |ident: Option<Ident>| { - if let Some(ident) = ident - && ident.name != kw::Underscore - && !ident.name.as_str().starts_with('_') - { - Some(ident) - } else { - None - } + ident + .filter(|ident| ident.name != kw::Underscore) + .filter(|ident| !ident.name.as_str().starts_with('_')) }; if let Some(default_ident) = has_name_to_check(default_ident) @@ -97,8 +91,7 @@ fn trait_item_def_id_of_impl(cx: &LateContext<'_>, target: OwnerId) -> Option<De } fn is_from_ignored_trait(of_trait: &TraitRef<'_>, ignored_traits: &DefIdSet) -> bool { - let Some(trait_did) = of_trait.trait_def_id() else { - return false; - }; - ignored_traits.contains(&trait_did) + of_trait + .trait_def_id() + .is_some_and(|trait_did| ignored_traits.contains(&trait_did)) } |
