Skip to content

Commit

Permalink
Move variables closure to their usage sites
Browse files Browse the repository at this point in the history
  • Loading branch information
fmease committed Jan 9, 2024
1 parent 90f3036 commit f54f885
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,11 @@ pub(crate) fn clean_middle_generic_args<'tcx>(
return Vec::new();
}

let generics = cx.tcx.generics_of(owner);
let mut elision_has_failed_once_before = false;

let offset = if has_self { 1 } else { 0 };
let mut clean_args = Vec::with_capacity(args.len().saturating_sub(offset));

// If the container is a trait object type, the arguments won't contain the self type but the
// generics of the corresponding trait will. In such a case, prepend a dummy self type in order
// to align the arguments and parameters for the iteration below and to enable us to correctly
// instantiate the generic parameter default later.
let generics = cx.tcx.generics_of(owner);
let args = if !has_self && generics.parent.is_none() && generics.has_self {
has_self = true;
[cx.tcx.types.trait_object_dummy_self.into()]
Expand All @@ -109,6 +104,7 @@ pub(crate) fn clean_middle_generic_args<'tcx>(
std::borrow::Cow::from(args)
};

let mut elision_has_failed_once_before = false;
let clean_middle_arg = |(index, arg): (usize, &ty::GenericArg<'tcx>)| {
// Elide the self type.
if has_self && index == 0 {
Expand Down Expand Up @@ -155,6 +151,8 @@ pub(crate) fn clean_middle_generic_args<'tcx>(
}
};

let offset = if has_self { 1 } else { 0 };
let mut clean_args = Vec::with_capacity(args.len().saturating_sub(offset));
clean_args.extend(args.iter().enumerate().rev().filter_map(clean_middle_arg));
clean_args.reverse();
clean_args
Expand Down

0 comments on commit f54f885

Please sign in to comment.