@@ -66,7 +66,8 @@ pub use self::util::{
66
66
get_vtable_index_of_object_method, impl_item_is_final, predicate_for_trait_def, upcast_choices,
67
67
} ;
68
68
pub use self :: util:: {
69
- supertrait_def_ids, supertraits, transitive_bounds, SupertraitDefIds , Supertraits ,
69
+ supertraits, supertraits_with_repetitions, supertrait_def_ids, transitive_bounds, Supertraits ,
70
+ SupertraitDefIds ,
70
71
} ;
71
72
72
73
pub use rustc_infer:: traits:: * ;
@@ -471,51 +472,52 @@ fn vtable_methods<'tcx>(
471
472
) -> & ' tcx [ & ' tcx [ Option < ( DefId , SubstsRef < ' tcx > ) > ] ] {
472
473
debug ! ( "vtable_methods({:?})" , trait_ref) ;
473
474
474
- tcx. arena . alloc_from_iter ( supertraits ( tcx, trait_ref) . map ( move |trait_ref| {
475
- let trait_methods = tcx
476
- . associated_items ( trait_ref. def_id ( ) )
477
- . in_definition_order ( )
478
- . filter ( |item| item. kind == ty:: AssocKind :: Fn ) ;
479
-
480
- // Now, list each method's `DefId` and `InternalSubsts` (for within its trait).
481
- // If the method can never be called from this object, produce `None`.
482
- & * tcx. arena . alloc_from_iter ( trait_methods. map ( move |trait_method| {
483
- debug ! ( "vtable_methods: trait_method={:?}" , trait_method) ;
484
- let def_id = trait_method. def_id ;
485
-
486
- // Some methods cannot be called on an object; skip those.
487
- if !is_vtable_safe_method ( tcx, trait_ref. def_id ( ) , & trait_method) {
488
- debug ! ( "vtable_methods: not vtable safe" ) ;
489
- return None ;
490
- }
475
+ tcx. arena . alloc_from_iter ( supertraits_with_repetitions ( tcx, trait_ref)
476
+ . map ( move |trait_ref| {
477
+ let trait_methods = tcx
478
+ . associated_items ( trait_ref. def_id ( ) )
479
+ . in_definition_order ( )
480
+ . filter ( |item| item. kind == ty:: AssocKind :: Fn ) ;
481
+
482
+ // Now, list each method's `DefId` and `InternalSubsts` (for within its trait).
483
+ // If the method can never be called from this object, produce `None`.
484
+ & * tcx. arena . alloc_from_iter ( trait_methods. map ( move |trait_method| {
485
+ debug ! ( "vtable_methods: trait_method={:?}" , trait_method) ;
486
+ let def_id = trait_method. def_id ;
487
+
488
+ // Some methods cannot be called on an object; skip those.
489
+ if !is_vtable_safe_method ( tcx, trait_ref. def_id ( ) , & trait_method) {
490
+ debug ! ( "vtable_methods: not vtable safe" ) ;
491
+ return None ;
492
+ }
491
493
492
- // The method may have some early-bound lifetimes; add regions for those.
493
- let substs = trait_ref. map_bound ( |trait_ref| {
494
- InternalSubsts :: for_item ( tcx, def_id, |param, _| match param. kind {
495
- GenericParamDefKind :: Lifetime => tcx. lifetimes . re_erased . into ( ) ,
496
- GenericParamDefKind :: Type { .. } | GenericParamDefKind :: Const => {
497
- trait_ref. substs [ param. index as usize ]
498
- }
499
- } )
500
- } ) ;
501
-
502
- // The trait type may have higher-ranked lifetimes in it;
503
- // erase them if they appear, so that we get the type
504
- // at some particular call site.
505
- let substs =
506
- tcx. normalize_erasing_late_bound_regions ( ty:: ParamEnv :: reveal_all ( ) , & substs) ;
507
-
508
- // It's possible that the method relies on where-clauses that
509
- // do not hold for this particular set of type parameters.
510
- // Note that this method could then never be called, so we
511
- // do not want to try and codegen it, in that case (see #23435).
512
- let predicates = tcx. predicates_of ( def_id) . instantiate_own ( tcx, substs) ;
513
- if !normalize_and_test_predicates ( tcx, predicates. predicates ) {
514
- debug ! ( "vtable_methods: predicates do not hold" ) ;
515
- return None ;
516
- }
494
+ // The method may have some early-bound lifetimes; add regions for those.
495
+ let substs = trait_ref. map_bound ( |trait_ref| {
496
+ InternalSubsts :: for_item ( tcx, def_id, |param, _| match param. kind {
497
+ GenericParamDefKind :: Lifetime => tcx. lifetimes . re_erased . into ( ) ,
498
+ GenericParamDefKind :: Type { .. } | GenericParamDefKind :: Const => {
499
+ trait_ref. substs [ param. index as usize ]
500
+ }
501
+ } )
502
+ } ) ;
503
+
504
+ // The trait type may have higher-ranked lifetimes in it;
505
+ // erase them if they appear, so that we get the type
506
+ // at some particular call site.
507
+ let substs =
508
+ tcx. normalize_erasing_late_bound_regions ( ty:: ParamEnv :: reveal_all ( ) , & substs) ;
509
+
510
+ // It's possible that the method relies on where-clauses that
511
+ // do not hold for this particular set of type parameters.
512
+ // Note that this method could then never be called, so we
513
+ // do not want to try and codegen it, in that case (see #23435).
514
+ let predicates = tcx. predicates_of ( def_id) . instantiate_own ( tcx, substs) ;
515
+ if !normalize_and_test_predicates ( tcx, predicates. predicates ) {
516
+ debug ! ( "vtable_methods: predicates do not hold" ) ;
517
+ return None ;
518
+ }
517
519
518
- Some ( ( def_id, substs) )
520
+ Some ( ( def_id, substs) )
519
521
} ) )
520
522
} ) )
521
523
}
0 commit comments