@@ -461,84 +461,55 @@ pub(super) fn explicit_predicates_of<'tcx>(
461
461
}
462
462
}
463
463
} else {
464
- if matches ! ( def_kind, DefKind :: AnonConst ) && tcx. features ( ) . generic_const_exprs {
465
- let hir_id = tcx. local_def_id_to_hir_id ( def_id) ;
466
- // FIXME(generic_const_exprs): The parenting of this def id is sketchy.
467
- // That should be fixed.
468
- let parent_def_id = tcx. hir ( ) . get_parent_item ( hir_id) ;
469
-
470
- if let Some ( defaulted_param_def_id) =
471
- tcx. hir ( ) . opt_const_param_default_param_def_id ( hir_id)
472
- {
473
- // In `generics_of` we set the generics' parent to be our parent's parent which means that
474
- // we lose out on the predicates of our actual parent if we dont return those predicates here.
475
- // (See comment in `generics_of` for more information on why the parent shenanigans is necessary)
476
- //
477
- // struct Foo<T, const N: usize = { <T as Trait>::ASSOC }>(T) where T: Trait;
478
- // ^^^ ^^^^^^^^^^^^^^^^^^^^^^^ the def id we are calling
479
- // ^^^ explicit_predicates_of on
480
- // parent item we dont have set as the
481
- // parent of generics returned by `generics_of`
482
- //
483
- // In the above code we want the anon const to have predicates in its param env for `T: Trait`
484
- // and we would be calling `explicit_predicates_of(Foo)` here
485
- let parent_preds = tcx. explicit_predicates_of ( parent_def_id) ;
486
-
487
- // If we dont filter out `ConstArgHasType` predicates then every single defaulted const parameter
488
- // will ICE because of #106994. FIXME(generic_const_exprs): remove this when a more general solution
489
- // to #106994 is implemented.
490
- let filtered_predicates = parent_preds
491
- . predicates
492
- . into_iter ( )
493
- . filter ( |( pred, _) | {
494
- if let ty:: ClauseKind :: ConstArgHasType ( ct, _) = pred. kind ( ) . skip_binder ( ) {
495
- match ct. kind ( ) {
496
- ty:: ConstKind :: Param ( param_const) => {
497
- let defaulted_param_idx = tcx
498
- . generics_of ( parent_def_id)
499
- . param_def_id_to_index [ & defaulted_param_def_id. to_def_id ( ) ] ;
500
- param_const. index < defaulted_param_idx
501
- }
502
- _ => bug ! (
503
- "`ConstArgHasType` in `predicates_of`\
504
- that isn't a `Param` const"
505
- ) ,
464
+ if matches ! ( def_kind, DefKind :: AnonConst )
465
+ && tcx. features ( ) . generic_const_exprs
466
+ && let Some ( defaulted_param_def_id) =
467
+ tcx. hir ( ) . opt_const_param_default_param_def_id ( tcx. local_def_id_to_hir_id ( def_id) )
468
+ {
469
+ // In `generics_of` we set the generics' parent to be our parent's parent which means that
470
+ // we lose out on the predicates of our actual parent if we dont return those predicates here.
471
+ // (See comment in `generics_of` for more information on why the parent shenanigans is necessary)
472
+ //
473
+ // struct Foo<T, const N: usize = { <T as Trait>::ASSOC }>(T) where T: Trait;
474
+ // ^^^ ^^^^^^^^^^^^^^^^^^^^^^^ the def id we are calling
475
+ // ^^^ explicit_predicates_of on
476
+ // parent item we dont have set as the
477
+ // parent of generics returned by `generics_of`
478
+ //
479
+ // In the above code we want the anon const to have predicates in its param env for `T: Trait`
480
+ // and we would be calling `explicit_predicates_of(Foo)` here
481
+ let parent_def_id = tcx. local_parent ( def_id) ;
482
+ let parent_preds = tcx. explicit_predicates_of ( parent_def_id) ;
483
+
484
+ // If we dont filter out `ConstArgHasType` predicates then every single defaulted const parameter
485
+ // will ICE because of #106994. FIXME(generic_const_exprs): remove this when a more general solution
486
+ // to #106994 is implemented.
487
+ let filtered_predicates = parent_preds
488
+ . predicates
489
+ . into_iter ( )
490
+ . filter ( |( pred, _) | {
491
+ if let ty:: ClauseKind :: ConstArgHasType ( ct, _) = pred. kind ( ) . skip_binder ( ) {
492
+ match ct. kind ( ) {
493
+ ty:: ConstKind :: Param ( param_const) => {
494
+ let defaulted_param_idx = tcx
495
+ . generics_of ( parent_def_id)
496
+ . param_def_id_to_index [ & defaulted_param_def_id. to_def_id ( ) ] ;
497
+ param_const. index < defaulted_param_idx
506
498
}
507
- } else {
508
- true
499
+ _ => bug ! (
500
+ "`ConstArgHasType` in `predicates_of`\
501
+ that isn't a `Param` const"
502
+ ) ,
509
503
}
510
- } )
511
- . cloned ( ) ;
512
- return GenericPredicates {
513
- parent : parent_preds. parent ,
514
- predicates : { tcx. arena . alloc_from_iter ( filtered_predicates) } ,
515
- } ;
516
- }
517
-
518
- let parent_def_kind = tcx. def_kind ( parent_def_id) ;
519
- if matches ! ( parent_def_kind, DefKind :: OpaqueTy ) {
520
- // In `instantiate_identity` we inherit the predicates of our parent.
521
- // However, opaque types do not have a parent (see `gather_explicit_predicates_of`), which means
522
- // that we lose out on the predicates of our actual parent if we dont return those predicates here.
523
- //
524
- //
525
- // fn foo<T: Trait>() -> impl Iterator<Output = Another<{ <T as Trait>::ASSOC }> > { todo!() }
526
- // ^^^^^^^^^^^^^^^^^^^ the def id we are calling
527
- // explicit_predicates_of on
528
- //
529
- // In the above code we want the anon const to have predicates in its param env for `T: Trait`.
530
- // However, the anon const cannot inherit predicates from its parent since it's opaque.
531
- //
532
- // To fix this, we call `explicit_predicates_of` directly on `foo`, the parent's parent.
533
-
534
- let ( hir:: OpaqueTyOrigin :: FnReturn ( item_owner_def_id)
535
- | hir:: OpaqueTyOrigin :: AsyncFn ( item_owner_def_id)
536
- | hir:: OpaqueTyOrigin :: TyAlias { parent : item_owner_def_id, .. } ) =
537
- tcx. opaque_type_origin ( parent_def_id. def_id ) ;
538
-
539
- // In the above code example we would be calling `explicit_predicates_of(foo)` here
540
- return tcx. explicit_predicates_of ( item_owner_def_id) ;
541
- }
504
+ } else {
505
+ true
506
+ }
507
+ } )
508
+ . cloned ( ) ;
509
+ return GenericPredicates {
510
+ parent : parent_preds. parent ,
511
+ predicates : { tcx. arena . alloc_from_iter ( filtered_predicates) } ,
512
+ } ;
542
513
}
543
514
gather_explicit_predicates_of ( tcx, def_id)
544
515
}
0 commit comments