@@ -1441,17 +1441,10 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
1441
1441
// of a const parameter type, e.g. `struct Foo<const N: usize, const M: [u8; N]>` is not allowed.
1442
1442
None
1443
1443
} else if tcx. lazy_normalization ( ) {
1444
- // Only provide backwards declared generics to cg defaults (#83938)
1445
- if let Node :: GenericParam ( GenericParam {
1446
- hir_id : param_id,
1447
- kind : GenericParamKind :: Const { .. } ,
1448
- ..
1449
- } ) = tcx. hir ( ) . get ( tcx. hir ( ) . get_parent_node ( hir_id) )
1450
- {
1451
- let item_id = tcx. hir ( ) . get_parent_node ( * param_id) ;
1452
- let item_def_id = tcx. hir ( ) . local_def_id ( item_id) ;
1453
- let generics = tcx. generics_of ( item_def_id. to_def_id ( ) ) ;
1454
- let param_def = tcx. hir ( ) . local_def_id ( * param_id) . to_def_id ( ) ;
1444
+ // Only provide backwards declared generics to cg defaults (#86580)
1445
+ if let Some ( param_id) = tcx. hir ( ) . opt_const_param_default_param_hir_id ( hir_id) {
1446
+ let generics = tcx. generics_of ( parent_def_id. to_def_id ( ) ) ;
1447
+ let param_def = tcx. hir ( ) . local_def_id ( param_id) . to_def_id ( ) ;
1455
1448
let param_def_idx = generics. param_def_id_to_index [ & param_def] ;
1456
1449
let params = generics. params [ ..param_def_idx as usize ] . to_owned ( ) ;
1457
1450
let param_def_id_to_index =
@@ -2432,16 +2425,11 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
2432
2425
}
2433
2426
} else {
2434
2427
if matches ! ( def_kind, DefKind :: AnonConst ) && tcx. lazy_normalization ( ) {
2435
- // Provide predicates of parent item of cg defaults manually
2436
- // as generics_of doesn't return a parent for the generics
2428
+ // Provide predicates of parent item of cg defaults manually as `generics_of`
2429
+ // doesn't set the parent item as the parent for the generics (#86580)
2437
2430
let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def_id. expect_local ( ) ) ;
2438
- if let Node :: GenericParam ( hir:: GenericParam {
2439
- hir_id : param_id,
2440
- kind : hir:: GenericParamKind :: Const { .. } ,
2441
- ..
2442
- } ) = tcx. hir ( ) . get ( tcx. hir ( ) . get_parent_node ( hir_id) )
2443
- {
2444
- let item_id = tcx. hir ( ) . get_parent_node ( * param_id) ;
2431
+ if let Some ( _) = tcx. hir ( ) . opt_const_param_default_param_hir_id ( hir_id) {
2432
+ let item_id = tcx. hir ( ) . get_parent_item ( hir_id) ;
2445
2433
let item_def_id = tcx. hir ( ) . local_def_id ( item_id) . to_def_id ( ) ;
2446
2434
return tcx. explicit_predicates_of ( item_def_id) ;
2447
2435
}
0 commit comments