@@ -101,6 +101,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
101101 param_def_id_to_index,
102102 has_self : generics. has_self ,
103103 has_late_bound_regions : generics. has_late_bound_regions ,
104+ host_effect_index : None ,
104105 } ;
105106 } else {
106107 // HACK(eddyb) this provides the correct generics when
@@ -226,10 +227,12 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
226227 let has_self = opt_self. is_some ( ) ;
227228 let mut parent_has_self = false ;
228229 let mut own_start = has_self as u32 ;
230+ let mut host_effect_index = None ;
229231 let parent_count = parent_def_id. map_or ( 0 , |def_id| {
230232 let generics = tcx. generics_of ( def_id) ;
231233 assert ! ( !has_self) ;
232234 parent_has_self = generics. has_self ;
235+ host_effect_index = generics. host_effect_index ;
233236 own_start = generics. count ( ) as u32 ;
234237 generics. parent_count + generics. params . len ( )
235238 } ) ;
@@ -251,11 +254,11 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
251254
252255 // Now create the real type and const parameters.
253256 let type_start = own_start - has_self as u32 + params. len ( ) as u32 ;
254- let mut i = 0 ;
257+ let mut i: u32 = 0 ;
255258 let mut next_index = || {
256259 let prev = i;
257260 i += 1 ;
258- prev as u32 + type_start
261+ prev + type_start
259262 } ;
260263
261264 const TYPE_DEFAULT_NOT_ALLOWED : & ' static str = "defaults for type parameters are only allowed in \
@@ -295,10 +298,12 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
295298 } )
296299 }
297300 GenericParamKind :: Const { default, .. } => {
298- // `rustc_host` effect params are allowed to have defaults.
301+ let is_host_param = tcx. has_attr ( param. def_id , sym:: rustc_host) ;
302+
299303 if !matches ! ( allow_defaults, Defaults :: Allowed )
300304 && default. is_some ( )
301- && !tcx. has_attr ( param. def_id , sym:: rustc_host)
305+ // `rustc_host` effect params are allowed to have defaults.
306+ && !is_host_param
302307 {
303308 tcx. sess . span_err (
304309 param. span ,
@@ -307,8 +312,18 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
307312 ) ;
308313 }
309314
315+ let index = next_index ( ) ;
316+
317+ if is_host_param {
318+ if let Some ( idx) = host_effect_index {
319+ bug ! ( "parent also has host effect param? index: {idx}, def: {def_id:?}" ) ;
320+ }
321+
322+ host_effect_index = Some ( parent_count + index as usize ) ;
323+ }
324+
310325 Some ( ty:: GenericParamDef {
311- index : next_index ( ) ,
326+ index,
312327 name : param. name . ident ( ) . name ,
313328 def_id : param. def_id . to_def_id ( ) ,
314329 pure_wrt_drop : param. pure_wrt_drop ,
@@ -360,6 +375,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
360375 param_def_id_to_index,
361376 has_self : has_self || parent_has_self,
362377 has_late_bound_regions : has_late_bound_regions ( tcx, node) ,
378+ host_effect_index,
363379 }
364380}
365381
0 commit comments