Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f6511b9

Browse files
committedJan 9, 2024
Move variables closer to their usage sites
1 parent 90f3036 commit f6511b9

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_middle_arg = |(index, arg): (usize, &ty::GenericArg<'tcx>)| {
113109
// Elide the self type.
114110
if has_self && index == 0 {
@@ -155,6 +151,8 @@ pub(crate) fn clean_middle_generic_args<'tcx>(
155151
}
156152
};
157153

154+
let offset = if has_self { 1 } else { 0 };
155+
let mut clean_args = Vec::with_capacity(args.len().saturating_sub(offset));
158156
clean_args.extend(args.iter().enumerate().rev().filter_map(clean_middle_arg));
159157
clean_args.reverse();
160158
clean_args

0 commit comments

Comments
 (0)
Please sign in to comment.