From 54e4761d0526cd314140f1899c54129270295f5e Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Sun, 29 Sep 2024 18:21:47 -0400 Subject: [PATCH] Address review comment https://github.com/rust-lang/rust-clippy/pull/13286#discussion_r1780038602 --- clippy_lints/src/lifetimes.rs | 38 ++++++++++++----------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 37d244ff53d..034cab72025 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -506,8 +506,17 @@ struct LifetimeChecker<'cx, 'tcx, F> { } impl<'cx, 'tcx, F> LifetimeChecker<'cx, 'tcx, F> { - fn new(cx: &'cx LateContext<'tcx>, def_ids: Vec) -> LifetimeChecker<'cx, 'tcx, F> { - let map = def_ids.into_iter().map(|def_id| (def_id, Vec::new())).collect(); + fn new(cx: &'cx LateContext<'tcx>, generics: &'tcx Generics<'_>) -> LifetimeChecker<'cx, 'tcx, F> { + let map = generics + .params + .iter() + .filter_map(|par| match par.kind { + GenericParamKind::Lifetime { + kind: LifetimeParamKind::Explicit, + } => Some((par.def_id, Vec::new())), + _ => None, + }) + .collect(); Self { cx, map, @@ -556,17 +565,7 @@ fn nested_visit_map(&mut self) -> Self::Map { } fn report_extra_lifetimes<'tcx>(cx: &LateContext<'tcx>, func: &'tcx FnDecl<'_>, generics: &'tcx Generics<'_>) { - let def_ids = generics - .params - .iter() - .filter_map(|par| match par.kind { - GenericParamKind::Lifetime { - kind: LifetimeParamKind::Explicit, - } => Some(par.def_id), - _ => None, - }) - .collect(); - let mut checker = LifetimeChecker::::new(cx, def_ids); + let mut checker = LifetimeChecker::::new(cx, generics); walk_generics(&mut checker, generics); walk_fn_decl(&mut checker, func); @@ -587,18 +586,7 @@ fn report_extra_lifetimes<'tcx>(cx: &LateContext<'tcx>, func: &'tcx FnDecl<'_>, } fn report_extra_impl_lifetimes<'tcx>(cx: &LateContext<'tcx>, impl_: &'tcx Impl<'_>) { - let def_ids = impl_ - .generics - .params - .iter() - .filter_map(|par| match par.kind { - GenericParamKind::Lifetime { - kind: LifetimeParamKind::Explicit, - } => Some(par.def_id), - _ => None, - }) - .collect(); - let mut checker = LifetimeChecker::::new(cx, def_ids); + let mut checker = LifetimeChecker::::new(cx, impl_.generics); walk_generics(&mut checker, impl_.generics); if let Some(ref trait_ref) = impl_.of_trait {