@@ -130,7 +130,7 @@ impl<'tcx> Clean<'tcx, Attributes> for [ast::Attribute] {
130
130
impl < ' tcx > Clean < ' tcx , Option < GenericBound > > for hir:: GenericBound < ' tcx > {
131
131
fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Option < GenericBound > {
132
132
Some ( match * self {
133
- hir:: GenericBound :: Outlives ( lt) => GenericBound :: Outlives ( lt . clean ( cx) ) ,
133
+ hir:: GenericBound :: Outlives ( lt) => GenericBound :: Outlives ( clean_lifetime ( lt , cx) ) ,
134
134
hir:: GenericBound :: LangItemTrait ( lang_item, span, _, generic_args) => {
135
135
let def_id = cx. tcx . require_lang_item ( lang_item, Some ( span) ) ;
136
136
@@ -163,7 +163,7 @@ impl<'tcx> Clean<'tcx, Option<GenericBound>> for hir::GenericBound<'tcx> {
163
163
}
164
164
}
165
165
166
- fn clean_trait_ref_with_bindings < ' tcx > (
166
+ pub ( crate ) fn clean_trait_ref_with_bindings < ' tcx > (
167
167
cx : & mut DocContext < ' tcx > ,
168
168
trait_ref : ty:: TraitRef < ' tcx > ,
169
169
bindings : & [ TypeBinding ] ,
@@ -180,12 +180,6 @@ fn clean_trait_ref_with_bindings<'tcx>(
180
180
path
181
181
}
182
182
183
- impl < ' tcx > Clean < ' tcx , Path > for ty:: TraitRef < ' tcx > {
184
- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Path {
185
- clean_trait_ref_with_bindings ( cx, * self , & [ ] )
186
- }
187
- }
188
-
189
183
fn clean_poly_trait_ref_with_bindings < ' tcx > (
190
184
cx : & mut DocContext < ' tcx > ,
191
185
poly_trait_ref : ty:: PolyTraitRef < ' tcx > ,
@@ -220,21 +214,19 @@ impl<'tcx> Clean<'tcx, GenericBound> for ty::PolyTraitRef<'tcx> {
220
214
}
221
215
}
222
216
223
- impl < ' tcx > Clean < ' tcx , Lifetime > for hir:: Lifetime {
224
- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Lifetime {
225
- let def = cx. tcx . named_region ( self . hir_id ) ;
226
- if let Some (
227
- rl:: Region :: EarlyBound ( _, node_id)
228
- | rl:: Region :: LateBound ( _, _, node_id)
229
- | rl:: Region :: Free ( _, node_id) ,
230
- ) = def
231
- {
232
- if let Some ( lt) = cx. substs . get ( & node_id) . and_then ( |p| p. as_lt ( ) ) . cloned ( ) {
233
- return lt;
234
- }
217
+ fn clean_lifetime < ' tcx > ( lifetime : hir:: Lifetime , cx : & mut DocContext < ' tcx > ) -> Lifetime {
218
+ let def = cx. tcx . named_region ( lifetime. hir_id ) ;
219
+ if let Some (
220
+ rl:: Region :: EarlyBound ( _, node_id)
221
+ | rl:: Region :: LateBound ( _, _, node_id)
222
+ | rl:: Region :: Free ( _, node_id) ,
223
+ ) = def
224
+ {
225
+ if let Some ( lt) = cx. substs . get ( & node_id) . and_then ( |p| p. as_lt ( ) ) . cloned ( ) {
226
+ return lt;
235
227
}
236
- Lifetime ( self . name . ident ( ) . name )
237
228
}
229
+ Lifetime ( lifetime. name . ident ( ) . name )
238
230
}
239
231
240
232
pub ( crate ) fn clean_const < ' tcx > ( constant : & hir:: ConstArg , cx : & mut DocContext < ' tcx > ) -> Constant {
@@ -311,7 +303,7 @@ impl<'tcx> Clean<'tcx, Option<WherePredicate>> for hir::WherePredicate<'tcx> {
311
303
}
312
304
313
305
hir:: WherePredicate :: RegionPredicate ( ref wrp) => WherePredicate :: RegionPredicate {
314
- lifetime : wrp. lifetime . clean ( cx) ,
306
+ lifetime : clean_lifetime ( wrp. lifetime , cx) ,
315
307
bounds : wrp. bounds . iter ( ) . filter_map ( |x| x. clean ( cx) ) . collect ( ) ,
316
308
} ,
317
309
@@ -432,7 +424,7 @@ fn clean_projection<'tcx>(
432
424
def_id : Option < DefId > ,
433
425
) -> Type {
434
426
let lifted = ty. lift_to_tcx ( cx. tcx ) . unwrap ( ) ;
435
- let trait_ = lifted. trait_ref ( cx. tcx ) . clean ( cx ) ;
427
+ let trait_ = clean_trait_ref_with_bindings ( cx , lifted. trait_ref ( cx. tcx ) , & [ ] ) ;
436
428
let self_type = clean_middle_ty ( ty. self_ty ( ) , cx, None ) ;
437
429
let self_def_id = if let Some ( def_id) = def_id {
438
430
cx. tcx . opt_parent ( def_id) . or ( Some ( def_id) )
@@ -524,7 +516,7 @@ fn clean_generic_param<'tcx>(
524
516
. filter ( |bp| !bp. in_where_clause )
525
517
. flat_map ( |bp| bp. bounds )
526
518
. map ( |bound| match bound {
527
- hir:: GenericBound :: Outlives ( lt) => lt . clean ( cx) ,
519
+ hir:: GenericBound :: Outlives ( lt) => clean_lifetime ( * lt , cx) ,
528
520
_ => panic ! ( ) ,
529
521
} )
530
522
. collect ( )
@@ -1431,7 +1423,8 @@ fn maybe_expand_private_type_alias<'tcx>(
1431
1423
} ) ;
1432
1424
if let Some ( lt) = lifetime. cloned ( ) {
1433
1425
let lt_def_id = cx. tcx . hir ( ) . local_def_id ( param. hir_id ) ;
1434
- let cleaned = if !lt. is_elided ( ) { lt. clean ( cx) } else { Lifetime :: elided ( ) } ;
1426
+ let cleaned =
1427
+ if !lt. is_elided ( ) { clean_lifetime ( lt, cx) } else { Lifetime :: elided ( ) } ;
1435
1428
substs. insert ( lt_def_id. to_def_id ( ) , SubstParam :: Lifetime ( cleaned) ) ;
1436
1429
}
1437
1430
indices. lifetimes += 1 ;
@@ -1503,7 +1496,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
1503
1496
// there's no case where it could cause the function to fail to compile.
1504
1497
let elided =
1505
1498
l. is_elided ( ) || matches ! ( l. name, LifetimeName :: Param ( _, ParamName :: Fresh ) ) ;
1506
- let lifetime = if elided { None } else { Some ( l . clean ( cx) ) } ;
1499
+ let lifetime = if elided { None } else { Some ( clean_lifetime ( * l , cx) ) } ;
1507
1500
BorrowedRef { lifetime, mutability : m. mutbl , type_ : Box :: new ( clean_ty ( m. ty , cx) ) }
1508
1501
}
1509
1502
TyKind :: Slice ( ty) => Slice ( Box :: new ( clean_ty ( ty, cx) ) ) ,
@@ -1539,7 +1532,8 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
1539
1532
TyKind :: Path ( _) => clean_qpath ( ty, cx) ,
1540
1533
TyKind :: TraitObject ( bounds, ref lifetime, _) => {
1541
1534
let bounds = bounds. iter ( ) . map ( |bound| bound. clean ( cx) ) . collect ( ) ;
1542
- let lifetime = if !lifetime. is_elided ( ) { Some ( lifetime. clean ( cx) ) } else { None } ;
1535
+ let lifetime =
1536
+ if !lifetime. is_elided ( ) { Some ( clean_lifetime ( * lifetime, cx) ) } else { None } ;
1543
1537
DynTrait ( bounds, lifetime)
1544
1538
}
1545
1539
TyKind :: BareFn ( barefn) => BareFunction ( Box :: new ( barefn. clean ( cx) ) ) ,
@@ -1875,7 +1869,7 @@ impl<'tcx> Clean<'tcx, GenericArgs> for hir::GenericArgs<'tcx> {
1875
1869
. iter ( )
1876
1870
. map ( |arg| match arg {
1877
1871
hir:: GenericArg :: Lifetime ( lt) if !lt. is_elided ( ) => {
1878
- GenericArg :: Lifetime ( lt . clean ( cx) )
1872
+ GenericArg :: Lifetime ( clean_lifetime ( * lt , cx) )
1879
1873
}
1880
1874
hir:: GenericArg :: Lifetime ( _) => GenericArg :: Lifetime ( Lifetime :: elided ( ) ) ,
1881
1875
hir:: GenericArg :: Type ( ty) => GenericArg :: Type ( clean_ty ( ty, cx) ) ,
0 commit comments