@@ -124,7 +124,7 @@ impl<'tcx> Clean<'tcx, Item> for DocModule<'tcx> {
124
124
impl < ' tcx > Clean < ' tcx , Option < GenericBound > > for hir:: GenericBound < ' tcx > {
125
125
fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Option < GenericBound > {
126
126
Some ( match * self {
127
- hir:: GenericBound :: Outlives ( lt) => GenericBound :: Outlives ( lt . clean ( cx) ) ,
127
+ hir:: GenericBound :: Outlives ( lt) => GenericBound :: Outlives ( clean_lifetime ( lt , cx) ) ,
128
128
hir:: GenericBound :: LangItemTrait ( lang_item, span, _, generic_args) => {
129
129
let def_id = cx. tcx . require_lang_item ( lang_item, Some ( span) ) ;
130
130
@@ -157,7 +157,7 @@ impl<'tcx> Clean<'tcx, Option<GenericBound>> for hir::GenericBound<'tcx> {
157
157
}
158
158
}
159
159
160
- fn clean_trait_ref_with_bindings < ' tcx > (
160
+ pub ( crate ) fn clean_trait_ref_with_bindings < ' tcx > (
161
161
cx : & mut DocContext < ' tcx > ,
162
162
trait_ref : ty:: TraitRef < ' tcx > ,
163
163
bindings : & [ TypeBinding ] ,
@@ -174,12 +174,6 @@ fn clean_trait_ref_with_bindings<'tcx>(
174
174
path
175
175
}
176
176
177
- impl < ' tcx > Clean < ' tcx , Path > for ty:: TraitRef < ' tcx > {
178
- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Path {
179
- clean_trait_ref_with_bindings ( cx, * self , & [ ] )
180
- }
181
- }
182
-
183
177
fn clean_poly_trait_ref_with_bindings < ' tcx > (
184
178
cx : & mut DocContext < ' tcx > ,
185
179
poly_trait_ref : ty:: PolyTraitRef < ' tcx > ,
@@ -214,21 +208,19 @@ impl<'tcx> Clean<'tcx, GenericBound> for ty::PolyTraitRef<'tcx> {
214
208
}
215
209
}
216
210
217
- impl < ' tcx > Clean < ' tcx , Lifetime > for hir:: Lifetime {
218
- fn clean ( & self , cx : & mut DocContext < ' tcx > ) -> Lifetime {
219
- let def = cx. tcx . named_region ( self . hir_id ) ;
220
- if let Some (
221
- rl:: Region :: EarlyBound ( _, node_id)
222
- | rl:: Region :: LateBound ( _, _, node_id)
223
- | rl:: Region :: Free ( _, node_id) ,
224
- ) = def
225
- {
226
- if let Some ( lt) = cx. substs . get ( & node_id) . and_then ( |p| p. as_lt ( ) ) . cloned ( ) {
227
- return lt;
228
- }
211
+ fn clean_lifetime < ' tcx > ( lifetime : hir:: Lifetime , cx : & mut DocContext < ' tcx > ) -> Lifetime {
212
+ let def = cx. tcx . named_region ( lifetime. hir_id ) ;
213
+ if let Some (
214
+ rl:: Region :: EarlyBound ( _, node_id)
215
+ | rl:: Region :: LateBound ( _, _, node_id)
216
+ | rl:: Region :: Free ( _, node_id) ,
217
+ ) = def
218
+ {
219
+ if let Some ( lt) = cx. substs . get ( & node_id) . and_then ( |p| p. as_lt ( ) ) . cloned ( ) {
220
+ return lt;
229
221
}
230
- Lifetime ( self . name . ident ( ) . name )
231
222
}
223
+ Lifetime ( lifetime. name . ident ( ) . name )
232
224
}
233
225
234
226
pub ( crate ) fn clean_const < ' tcx > ( constant : & hir:: ConstArg , cx : & mut DocContext < ' tcx > ) -> Constant {
@@ -305,7 +297,7 @@ impl<'tcx> Clean<'tcx, Option<WherePredicate>> for hir::WherePredicate<'tcx> {
305
297
}
306
298
307
299
hir:: WherePredicate :: RegionPredicate ( ref wrp) => WherePredicate :: RegionPredicate {
308
- lifetime : wrp. lifetime . clean ( cx) ,
300
+ lifetime : clean_lifetime ( wrp. lifetime , cx) ,
309
301
bounds : wrp. bounds . iter ( ) . filter_map ( |x| x. clean ( cx) ) . collect ( ) ,
310
302
} ,
311
303
@@ -426,7 +418,7 @@ fn clean_projection<'tcx>(
426
418
def_id : Option < DefId > ,
427
419
) -> Type {
428
420
let lifted = ty. lift_to_tcx ( cx. tcx ) . unwrap ( ) ;
429
- let trait_ = lifted. trait_ref ( cx. tcx ) . clean ( cx ) ;
421
+ let trait_ = clean_trait_ref_with_bindings ( cx , lifted. trait_ref ( cx. tcx ) , & [ ] ) ;
430
422
let self_type = clean_middle_ty ( ty. self_ty ( ) , cx, None ) ;
431
423
let self_def_id = if let Some ( def_id) = def_id {
432
424
cx. tcx . opt_parent ( def_id) . or ( Some ( def_id) )
@@ -518,7 +510,7 @@ fn clean_generic_param<'tcx>(
518
510
. filter ( |bp| !bp. in_where_clause )
519
511
. flat_map ( |bp| bp. bounds )
520
512
. map ( |bound| match bound {
521
- hir:: GenericBound :: Outlives ( lt) => lt . clean ( cx) ,
513
+ hir:: GenericBound :: Outlives ( lt) => clean_lifetime ( * lt , cx) ,
522
514
_ => panic ! ( ) ,
523
515
} )
524
516
. collect ( )
@@ -1425,7 +1417,8 @@ fn maybe_expand_private_type_alias<'tcx>(
1425
1417
} ) ;
1426
1418
if let Some ( lt) = lifetime. cloned ( ) {
1427
1419
let lt_def_id = cx. tcx . hir ( ) . local_def_id ( param. hir_id ) ;
1428
- let cleaned = if !lt. is_elided ( ) { lt. clean ( cx) } else { Lifetime :: elided ( ) } ;
1420
+ let cleaned =
1421
+ if !lt. is_elided ( ) { clean_lifetime ( lt, cx) } else { Lifetime :: elided ( ) } ;
1429
1422
substs. insert ( lt_def_id. to_def_id ( ) , SubstParam :: Lifetime ( cleaned) ) ;
1430
1423
}
1431
1424
indices. lifetimes += 1 ;
@@ -1497,7 +1490,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
1497
1490
// there's no case where it could cause the function to fail to compile.
1498
1491
let elided =
1499
1492
l. is_elided ( ) || matches ! ( l. name, LifetimeName :: Param ( _, ParamName :: Fresh ) ) ;
1500
- let lifetime = if elided { None } else { Some ( l . clean ( cx) ) } ;
1493
+ let lifetime = if elided { None } else { Some ( clean_lifetime ( * l , cx) ) } ;
1501
1494
BorrowedRef { lifetime, mutability : m. mutbl , type_ : Box :: new ( clean_ty ( m. ty , cx) ) }
1502
1495
}
1503
1496
TyKind :: Slice ( ty) => Slice ( Box :: new ( clean_ty ( ty, cx) ) ) ,
@@ -1533,7 +1526,8 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
1533
1526
TyKind :: Path ( _) => clean_qpath ( ty, cx) ,
1534
1527
TyKind :: TraitObject ( bounds, ref lifetime, _) => {
1535
1528
let bounds = bounds. iter ( ) . map ( |bound| bound. clean ( cx) ) . collect ( ) ;
1536
- let lifetime = if !lifetime. is_elided ( ) { Some ( lifetime. clean ( cx) ) } else { None } ;
1529
+ let lifetime =
1530
+ if !lifetime. is_elided ( ) { Some ( clean_lifetime ( * lifetime, cx) ) } else { None } ;
1537
1531
DynTrait ( bounds, lifetime)
1538
1532
}
1539
1533
TyKind :: BareFn ( barefn) => BareFunction ( Box :: new ( barefn. clean ( cx) ) ) ,
@@ -1869,7 +1863,7 @@ impl<'tcx> Clean<'tcx, GenericArgs> for hir::GenericArgs<'tcx> {
1869
1863
. iter ( )
1870
1864
. map ( |arg| match arg {
1871
1865
hir:: GenericArg :: Lifetime ( lt) if !lt. is_elided ( ) => {
1872
- GenericArg :: Lifetime ( lt . clean ( cx) )
1866
+ GenericArg :: Lifetime ( clean_lifetime ( * lt , cx) )
1873
1867
}
1874
1868
hir:: GenericArg :: Lifetime ( _) => GenericArg :: Lifetime ( Lifetime :: elided ( ) ) ,
1875
1869
hir:: GenericArg :: Type ( ty) => GenericArg :: Type ( clean_ty ( ty, cx) ) ,
0 commit comments