@@ -75,13 +75,13 @@ pub(crate) fn krate(cx: &mut DocContext<'_>) -> Crate {
75
75
Crate { module, external_traits : cx. external_traits . clone ( ) }
76
76
}
77
77
78
- pub ( crate ) fn ty_args_to_args < ' tcx > (
78
+ pub ( crate ) fn clean_middle_generic_args < ' tcx > (
79
79
cx : & mut DocContext < ' tcx > ,
80
- ty_args : ty:: Binder < ' tcx , & ' tcx [ ty:: GenericArg < ' tcx > ] > ,
80
+ args : ty:: Binder < ' tcx , & ' tcx [ ty:: GenericArg < ' tcx > ] > ,
81
81
has_self : bool ,
82
82
owner : DefId ,
83
83
) -> Vec < GenericArg > {
84
- if ty_args . skip_binder ( ) . is_empty ( ) {
84
+ if args . skip_binder ( ) . is_empty ( ) {
85
85
// Fast path which avoids executing the query `generics_of`.
86
86
return Vec :: new ( ) ;
87
87
}
@@ -90,9 +90,9 @@ pub(crate) fn ty_args_to_args<'tcx>(
90
90
let mut elision_has_failed_once_before = false ;
91
91
92
92
let offset = if has_self { 1 } else { 0 } ;
93
- let mut args = Vec :: with_capacity ( ty_args . skip_binder ( ) . len ( ) . saturating_sub ( offset) ) ;
93
+ let mut clean_args = Vec :: with_capacity ( args . skip_binder ( ) . len ( ) . saturating_sub ( offset) ) ;
94
94
95
- let ty_arg_to_arg = |( index, arg) : ( usize , & ty:: GenericArg < ' tcx > ) | match arg. unpack ( ) {
95
+ let clean_arg = |( index, arg) : ( usize , & ty:: GenericArg < ' tcx > ) | match arg. unpack ( ) {
96
96
GenericArgKind :: Lifetime ( lt) => {
97
97
Some ( GenericArg :: Lifetime ( clean_middle_region ( lt) . unwrap_or ( Lifetime :: elided ( ) ) ) )
98
98
}
@@ -101,26 +101,20 @@ pub(crate) fn ty_args_to_args<'tcx>(
101
101
if !elision_has_failed_once_before
102
102
&& let Some ( default) = params[ index] . default_value ( cx. tcx )
103
103
{
104
- let default =
105
- ty_args. map_bound ( |args| default. instantiate ( cx. tcx , args) . expect_ty ( ) ) ;
104
+ let default = args. map_bound ( |args| default. instantiate ( cx. tcx , args) . expect_ty ( ) ) ;
106
105
107
- if can_elide_generic_arg ( ty_args . rebind ( ty) , default) {
106
+ if can_elide_generic_arg ( args . rebind ( ty) , default) {
108
107
return None ;
109
108
}
110
109
111
110
elision_has_failed_once_before = true ;
112
111
}
113
112
114
113
Some ( GenericArg :: Type ( clean_middle_ty (
115
- ty_args . rebind ( ty) ,
114
+ args . rebind ( ty) ,
116
115
cx,
117
116
None ,
118
- Some ( crate :: clean:: ContainerTy :: Regular {
119
- ty : owner,
120
- args : ty_args,
121
- has_self,
122
- arg : index,
123
- } ) ,
117
+ Some ( crate :: clean:: ContainerTy :: Regular { ty : owner, args, has_self, arg : index } ) ,
124
118
) ) )
125
119
}
126
120
GenericArgKind :: Const ( ct) => {
@@ -133,22 +127,22 @@ pub(crate) fn ty_args_to_args<'tcx>(
133
127
&& let Some ( default) = params[ index] . default_value ( cx. tcx )
134
128
{
135
129
let default =
136
- ty_args . map_bound ( |args| default. instantiate ( cx. tcx , args) . expect_const ( ) ) ;
130
+ args . map_bound ( |args| default. instantiate ( cx. tcx , args) . expect_const ( ) ) ;
137
131
138
- if can_elide_generic_arg ( ty_args . rebind ( ct) , default) {
132
+ if can_elide_generic_arg ( args . rebind ( ct) , default) {
139
133
return None ;
140
134
}
141
135
142
136
elision_has_failed_once_before = true ;
143
137
}
144
138
145
- Some ( GenericArg :: Const ( Box :: new ( clean_middle_const ( ty_args . rebind ( ct) , cx) ) ) )
139
+ Some ( GenericArg :: Const ( Box :: new ( clean_middle_const ( args . rebind ( ct) , cx) ) ) )
146
140
}
147
141
} ;
148
142
149
- args . extend ( ty_args . skip_binder ( ) . iter ( ) . enumerate ( ) . rev ( ) . filter_map ( ty_arg_to_arg ) ) ;
150
- args . reverse ( ) ;
151
- args
143
+ clean_args . extend ( args . skip_binder ( ) . iter ( ) . enumerate ( ) . rev ( ) . filter_map ( clean_arg ) ) ;
144
+ clean_args . reverse ( ) ;
145
+ clean_args
152
146
}
153
147
154
148
/// Check if the generic argument `actual` coincides with the `default` and can therefore be elided.
@@ -192,14 +186,14 @@ where
192
186
actual. skip_binder ( ) == default. skip_binder ( )
193
187
}
194
188
195
- fn external_generic_args < ' tcx > (
189
+ fn clean_middle_generic_args_with_bindings < ' tcx > (
196
190
cx : & mut DocContext < ' tcx > ,
197
191
did : DefId ,
198
192
has_self : bool ,
199
193
bindings : ThinVec < TypeBinding > ,
200
194
ty_args : ty:: Binder < ' tcx , GenericArgsRef < ' tcx > > ,
201
195
) -> GenericArgs {
202
- let args = ty_args_to_args ( cx, ty_args. map_bound ( |args| & args[ ..] ) , has_self, did) ;
196
+ let args = clean_middle_generic_args ( cx, ty_args. map_bound ( |args| & args[ ..] ) , has_self, did) ;
203
197
204
198
if cx. tcx . fn_trait_kind_from_def_id ( did) . is_some ( ) {
205
199
let ty = ty_args
@@ -225,7 +219,7 @@ fn external_generic_args<'tcx>(
225
219
}
226
220
}
227
221
228
- pub ( super ) fn external_path < ' tcx > (
222
+ pub ( super ) fn clean_middle_path < ' tcx > (
229
223
cx : & mut DocContext < ' tcx > ,
230
224
did : DefId ,
231
225
has_self : bool ,
@@ -238,7 +232,7 @@ pub(super) fn external_path<'tcx>(
238
232
res : Res :: Def ( def_kind, did) ,
239
233
segments : thin_vec ! [ PathSegment {
240
234
name,
241
- args: external_generic_args ( cx, did, has_self, bindings, args) ,
235
+ args: clean_middle_generic_args_with_bindings ( cx, did, has_self, bindings, args) ,
242
236
} ] ,
243
237
}
244
238
}
0 commit comments