@@ -207,8 +207,13 @@ pub(crate) fn clean_trait_ref_with_bindings<'tcx>(
207207 span_bug ! ( cx. tcx. def_span( trait_ref. def_id( ) ) , "`TraitRef` had unexpected kind {kind:?}" ) ;
208208 }
209209 inline:: record_extern_fqn ( cx, trait_ref. def_id ( ) , kind) ;
210- let path =
211- external_path ( cx, trait_ref. def_id ( ) , true , bindings, trait_ref. map_bound ( |tr| tr. args ) ) ;
210+ let path = clean_middle_path (
211+ cx,
212+ trait_ref. def_id ( ) ,
213+ true ,
214+ bindings,
215+ trait_ref. map_bound ( |tr| tr. args ) ,
216+ ) ;
212217
213218 debug ! ( ?trait_ref) ;
214219
@@ -467,7 +472,7 @@ fn projection_to_path_segment<'tcx>(
467472 PathSegment {
468473 name : item. name ,
469474 args : GenericArgs :: AngleBracketed {
470- args : ty_args_to_args (
475+ args : clean_middle_generic_args (
471476 cx,
472477 ty. map_bound ( |ty| & ty. args [ generics. parent_count ..] ) ,
473478 false ,
@@ -1903,7 +1908,7 @@ fn normalize<'tcx>(
19031908
19041909fn clean_trait_object_lifetime_bound < ' tcx > (
19051910 region : ty:: Region < ' tcx > ,
1906- container : Option < ContainerTy < ' tcx > > ,
1911+ container : Option < ContainerTy < ' _ , ' tcx > > ,
19071912 preds : & ' tcx ty:: List < ty:: PolyExistentialPredicate < ' tcx > > ,
19081913 tcx : TyCtxt < ' tcx > ,
19091914) -> Option < Lifetime > {
@@ -1932,7 +1937,7 @@ fn clean_trait_object_lifetime_bound<'tcx>(
19321937
19331938fn can_elide_trait_object_lifetime_bound < ' tcx > (
19341939 region : ty:: Region < ' tcx > ,
1935- container : Option < ContainerTy < ' tcx > > ,
1940+ container : Option < ContainerTy < ' _ , ' tcx > > ,
19361941 preds : & ' tcx ty:: List < ty:: PolyExistentialPredicate < ' tcx > > ,
19371942 tcx : TyCtxt < ' tcx > ,
19381943) -> bool {
@@ -1979,21 +1984,22 @@ fn can_elide_trait_object_lifetime_bound<'tcx>(
19791984}
19801985
19811986#[ derive( Debug ) ]
1982- pub ( crate ) enum ContainerTy < ' tcx > {
1987+ pub ( crate ) enum ContainerTy < ' a , ' tcx > {
19831988 Ref ( ty:: Region < ' tcx > ) ,
19841989 Regular {
19851990 ty : DefId ,
1986- args : ty:: Binder < ' tcx , & ' tcx [ ty:: GenericArg < ' tcx > ] > ,
1987- has_self : bool ,
1991+ /// The arguments *have* to contain an arg for the self type if the corresponding generics
1992+ /// contain a self type.
1993+ args : ty:: Binder < ' tcx , & ' a [ ty:: GenericArg < ' tcx > ] > ,
19881994 arg : usize ,
19891995 } ,
19901996}
19911997
1992- impl < ' tcx > ContainerTy < ' tcx > {
1998+ impl < ' tcx > ContainerTy < ' _ , ' tcx > {
19931999 fn object_lifetime_default ( self , tcx : TyCtxt < ' tcx > ) -> ObjectLifetimeDefault < ' tcx > {
19942000 match self {
19952001 Self :: Ref ( region) => ObjectLifetimeDefault :: Arg ( region) ,
1996- Self :: Regular { ty : container, args, has_self , arg : index } => {
2002+ Self :: Regular { ty : container, args, arg : index } => {
19972003 let ( DefKind :: Struct
19982004 | DefKind :: Union
19992005 | DefKind :: Enum
@@ -2006,14 +2012,7 @@ impl<'tcx> ContainerTy<'tcx> {
20062012 let generics = tcx. generics_of ( container) ;
20072013 debug_assert_eq ! ( generics. parent_count, 0 ) ;
20082014
2009- // If the container is a trait object type, the arguments won't contain the self type but the
2010- // generics of the corresponding trait will. In such a case, offset the index by one.
2011- // For comparison, if the container is a trait inside a bound, the arguments do contain the
2012- // self type.
2013- let offset =
2014- if !has_self && generics. parent . is_none ( ) && generics. has_self { 1 } else { 0 } ;
2015- let param = generics. params [ index + offset] . def_id ;
2016-
2015+ let param = generics. params [ index] . def_id ;
20172016 let default = tcx. object_lifetime_default ( param) ;
20182017 match default {
20192018 rbv:: ObjectLifetimeDefault :: Param ( lifetime) => {
@@ -2045,7 +2044,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
20452044 bound_ty : ty:: Binder < ' tcx , Ty < ' tcx > > ,
20462045 cx : & mut DocContext < ' tcx > ,
20472046 parent_def_id : Option < DefId > ,
2048- container : Option < ContainerTy < ' tcx > > ,
2047+ container : Option < ContainerTy < ' _ , ' tcx > > ,
20492048) -> Type {
20502049 let bound_ty = normalize ( cx, bound_ty) . unwrap_or ( bound_ty) ;
20512050 match * bound_ty. skip_binder ( ) . kind ( ) {
@@ -2096,12 +2095,12 @@ pub(crate) fn clean_middle_ty<'tcx>(
20962095 AdtKind :: Enum => ItemType :: Enum ,
20972096 } ;
20982097 inline:: record_extern_fqn ( cx, did, kind) ;
2099- let path = external_path ( cx, did, false , ThinVec :: new ( ) , bound_ty. rebind ( args) ) ;
2098+ let path = clean_middle_path ( cx, did, false , ThinVec :: new ( ) , bound_ty. rebind ( args) ) ;
21002099 Type :: Path { path }
21012100 }
21022101 ty:: Foreign ( did) => {
21032102 inline:: record_extern_fqn ( cx, did, ItemType :: ForeignType ) ;
2104- let path = external_path (
2103+ let path = clean_middle_path (
21052104 cx,
21062105 did,
21072106 false ,
@@ -2132,7 +2131,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
21322131 let mut bounds = dids
21332132 . map ( |did| {
21342133 let empty = ty:: Binder :: dummy ( ty:: GenericArgs :: empty ( ) ) ;
2135- let path = external_path ( cx, did, false , ThinVec :: new ( ) , empty) ;
2134+ let path = clean_middle_path ( cx, did, false , ThinVec :: new ( ) , empty) ;
21362135 inline:: record_extern_fqn ( cx, did, ItemType :: Trait ) ;
21372136 PolyTrait { trait_ : path, generic_params : Vec :: new ( ) }
21382137 } )
@@ -2171,7 +2170,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
21712170 . collect ( ) ;
21722171 let late_bound_regions = late_bound_regions. into_iter ( ) . collect ( ) ;
21732172
2174- let path = external_path ( cx, did, false , bindings, args) ;
2173+ let path = clean_middle_path ( cx, did, false , bindings, args) ;
21752174 bounds. insert ( 0 , PolyTrait { trait_ : path, generic_params : late_bound_regions } ) ;
21762175
21772176 DynTrait ( bounds, lifetime)
@@ -2193,7 +2192,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
21932192 assoc : PathSegment {
21942193 name : cx. tcx . associated_item ( def_id) . name ,
21952194 args : GenericArgs :: AngleBracketed {
2196- args : ty_args_to_args (
2195+ args : clean_middle_generic_args (
21972196 cx,
21982197 alias_ty. map_bound ( |ty| ty. args . as_slice ( ) ) ,
21992198 true ,
@@ -2213,7 +2212,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
22132212 if cx. tcx . features ( ) . lazy_type_alias {
22142213 // Weak type alias `data` represents the `type X` in `type X = Y`. If we need `Y`,
22152214 // we need to use `type_of`.
2216- let path = external_path (
2215+ let path = clean_middle_path (
22172216 cx,
22182217 data. def_id ,
22192218 false ,
@@ -2243,7 +2242,8 @@ pub(crate) fn clean_middle_ty<'tcx>(
22432242 ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, args, .. } ) => {
22442243 // If it's already in the same alias, don't get an infinite loop.
22452244 if cx. current_type_aliases . contains_key ( & def_id) {
2246- let path = external_path ( cx, def_id, false , ThinVec :: new ( ) , bound_ty. rebind ( args) ) ;
2245+ let path =
2246+ clean_middle_path ( cx, def_id, false , ThinVec :: new ( ) , bound_ty. rebind ( args) ) ;
22472247 Type :: Path { path }
22482248 } else {
22492249 * cx. current_type_aliases . entry ( def_id) . or_insert ( 0 ) += 1 ;
0 commit comments