@@ -101,6 +101,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
101
101
param_def_id_to_index,
102
102
has_self : generics. has_self ,
103
103
has_late_bound_regions : generics. has_late_bound_regions ,
104
+ host_effect_index : None ,
104
105
} ;
105
106
} else {
106
107
// HACK(eddyb) this provides the correct generics when
@@ -226,10 +227,12 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
226
227
let has_self = opt_self. is_some ( ) ;
227
228
let mut parent_has_self = false ;
228
229
let mut own_start = has_self as u32 ;
230
+ let mut host_effect_index = None ;
229
231
let parent_count = parent_def_id. map_or ( 0 , |def_id| {
230
232
let generics = tcx. generics_of ( def_id) ;
231
233
assert ! ( !has_self) ;
232
234
parent_has_self = generics. has_self ;
235
+ host_effect_index = generics. host_effect_index ;
233
236
own_start = generics. count ( ) as u32 ;
234
237
generics. parent_count + generics. params . len ( )
235
238
} ) ;
@@ -251,11 +254,11 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
251
254
252
255
// Now create the real type and const parameters.
253
256
let type_start = own_start - has_self as u32 + params. len ( ) as u32 ;
254
- let mut i = 0 ;
257
+ let mut i: u32 = 0 ;
255
258
let mut next_index = || {
256
259
let prev = i;
257
260
i += 1 ;
258
- prev as u32 + type_start
261
+ prev + type_start
259
262
} ;
260
263
261
264
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 {
295
298
} )
296
299
}
297
300
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
+
299
303
if !matches ! ( allow_defaults, Defaults :: Allowed )
300
304
&& 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
302
307
{
303
308
tcx. sess . span_err (
304
309
param. span ,
@@ -307,8 +312,18 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
307
312
) ;
308
313
}
309
314
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
+
310
325
Some ( ty:: GenericParamDef {
311
- index : next_index ( ) ,
326
+ index,
312
327
name : param. name . ident ( ) . name ,
313
328
def_id : param. def_id . to_def_id ( ) ,
314
329
pure_wrt_drop : param. pure_wrt_drop ,
@@ -360,6 +375,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
360
375
param_def_id_to_index,
361
376
has_self : has_self || parent_has_self,
362
377
has_late_bound_regions : has_late_bound_regions ( tcx, node) ,
378
+ host_effect_index,
363
379
}
364
380
}
365
381
0 commit comments