Skip to content

Commit 2d010bc

Browse files
committed
Move variables closer to their usage sites
1 parent aa1a5e3 commit 2d010bc

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/librustdoc/clean/utils.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,11 @@ pub(crate) fn clean_middle_generic_args<'tcx>(
8888
return Vec::new();
8989
}
9090

91-
let generics = cx.tcx.generics_of(owner);
92-
let mut elision_has_failed_once_before = false;
93-
94-
let offset = if has_self { 1 } else { 0 };
95-
let mut clean_args = Vec::with_capacity(args.len().saturating_sub(offset));
96-
9791
// If the container is a trait object type, the arguments won't contain the self type but the
9892
// generics of the corresponding trait will. In such a case, prepend a dummy self type in order
9993
// to align the arguments and parameters for the iteration below and to enable us to correctly
10094
// instantiate the generic parameter default later.
95+
let generics = cx.tcx.generics_of(owner);
10196
let args = if !has_self && generics.parent.is_none() && generics.has_self {
10297
has_self = true;
10398
[cx.tcx.types.trait_object_dummy_self.into()]
@@ -109,6 +104,7 @@ pub(crate) fn clean_middle_generic_args<'tcx>(
109104
std::borrow::Cow::from(args)
110105
};
111106

107+
let mut elision_has_failed_once_before = false;
112108
let clean_arg = |(index, &arg): (usize, &ty::GenericArg<'tcx>)| {
113109
// Elide the self type.
114110
if has_self && index == 0 {
@@ -152,6 +148,8 @@ pub(crate) fn clean_middle_generic_args<'tcx>(
152148
}
153149
};
154150

151+
let offset = if has_self { 1 } else { 0 };
152+
let mut clean_args = Vec::with_capacity(args.len().saturating_sub(offset));
155153
clean_args.extend(args.iter().enumerate().rev().filter_map(clean_arg));
156154
clean_args.reverse();
157155
clean_args

0 commit comments

Comments
 (0)