@@ -670,6 +670,23 @@ where
670
670
} ) ;
671
671
}
672
672
673
+ let mk_dyn_vtable = || {
674
+ tcx. mk_imm_ref ( tcx. lifetimes . re_static , tcx. mk_array ( tcx. types . usize , 3 ) )
675
+ /* FIXME: use actual fn pointers
676
+ Warning: naively computing the number of entries in the
677
+ vtable by counting the methods on the trait + methods on
678
+ all parent traits does not work, because some methods can
679
+ be not object safe and thus excluded from the vtable.
680
+ Increase this counter if you tried to implement this but
681
+ failed to do it without duplicating a lot of code from
682
+ other places in the compiler: 2
683
+ tcx.mk_tup(&[
684
+ tcx.mk_array(tcx.types.usize, 3),
685
+ tcx.mk_array(Option<fn()>),
686
+ ])
687
+ */
688
+ } ;
689
+
673
690
let metadata = if let Some ( metadata_def_id) = tcx. lang_items ( ) . metadata_type ( ) {
674
691
let metadata = tcx. normalize_erasing_regions (
675
692
cx. param_env ( ) ,
@@ -684,48 +701,14 @@ where
684
701
&& Some ( def. did ( ) ) == tcx. lang_items ( ) . dyn_metadata ( )
685
702
&& substs. type_at ( 0 ) . is_trait ( )
686
703
{
687
- tcx. mk_imm_ref (
688
- tcx. lifetimes . re_static ,
689
- tcx. mk_array ( tcx. types . usize , 3 ) ,
690
- )
691
- /* FIXME: use actual fn pointers
692
- Warning: naively computing the number of entries in the
693
- vtable by counting the methods on the trait + methods on
694
- all parent traits does not work, because some methods can
695
- be not object safe and thus excluded from the vtable.
696
- Increase this counter if you tried to implement this but
697
- failed to do it without duplicating a lot of code from
698
- other places in the compiler: 2
699
- tcx.mk_tup(&[
700
- tcx.mk_array(tcx.types.usize, 3),
701
- tcx.mk_array(Option<fn()>),
702
- ])
703
- */
704
+ mk_dyn_vtable ( )
704
705
} else {
705
706
metadata
706
707
}
707
708
} else {
708
709
match tcx. struct_tail_erasing_lifetimes ( pointee, cx. param_env ( ) ) . kind ( ) {
709
710
ty:: Slice ( _) | ty:: Str => tcx. types . usize ,
710
- ty:: Dynamic ( _, _, ty:: Dyn ) => {
711
- tcx. mk_imm_ref (
712
- tcx. lifetimes . re_static ,
713
- tcx. mk_array ( tcx. types . usize , 3 ) ,
714
- )
715
- /* FIXME: use actual fn pointers
716
- Warning: naively computing the number of entries in the
717
- vtable by counting the methods on the trait + methods on
718
- all parent traits does not work, because some methods can
719
- be not object safe and thus excluded from the vtable.
720
- Increase this counter if you tried to implement this but
721
- failed to do it without duplicating a lot of code from
722
- other places in the compiler: 2
723
- tcx.mk_tup(&[
724
- tcx.mk_array(tcx.types.usize, 3),
725
- tcx.mk_array(Option<fn()>),
726
- ])
727
- */
728
- }
711
+ ty:: Dynamic ( _, _, ty:: Dyn ) => mk_dyn_vtable ( ) ,
729
712
_ => bug ! ( "TyAndLayout::field({:?}): not applicable" , this) ,
730
713
}
731
714
} ;
0 commit comments