@@ -13,7 +13,7 @@ use back::abi;
1313use back:: link;
1414use llvm:: { ValueRef , get_param} ;
1515use metadata:: csearch;
16- use middle:: subst:: Substs ;
16+ use middle:: subst:: { Subst , Substs } ;
1717use middle:: subst:: VecPerParamSpace ;
1818use middle:: subst;
1919use middle:: traits;
@@ -784,6 +784,7 @@ fn emit_vtable_methods<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
784784
785785 ty:: populate_implementations_for_trait_if_necessary ( tcx, trt_id) ;
786786
787+ let nullptr = C_null ( Type :: nil ( ccx) . ptr_to ( ) ) ;
787788 let trait_item_def_ids = ty:: trait_item_def_ids ( tcx, trt_id) ;
788789 trait_item_def_ids
789790 . iter ( )
@@ -809,6 +810,12 @@ fn emit_vtable_methods<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
809810 } ;
810811 let name = trait_method_type. name ;
811812
813+ // Some methods cannot be called on an object; skip those.
814+ if !traits:: is_vtable_safe_method ( tcx, trt_id, & trait_method_type) {
815+ debug ! ( "emit_vtable_methods: not vtable safe" ) ;
816+ return nullptr;
817+ }
818+
812819 debug ! ( "emit_vtable_methods: trait_method_type={}" ,
813820 trait_method_type. repr( tcx) ) ;
814821
@@ -820,35 +827,17 @@ fn emit_vtable_methods<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
820827 ty:: TypeTraitItem ( _) => ccx. sess ( ) . bug ( "should be a method, not assoc type" )
821828 } ;
822829
823- debug ! ( "emit_vtable_methods: m ={}" ,
830+ debug ! ( "emit_vtable_methods: impl_method_type ={}" ,
824831 impl_method_type. repr( tcx) ) ;
825832
826- let nullptr = C_null ( Type :: nil ( ccx) . ptr_to ( ) ) ;
827-
828- if impl_method_type. generics . has_type_params ( subst:: FnSpace ) {
829- debug ! ( "emit_vtable_methods: generic" ) ;
830- return nullptr;
831- }
832-
833- let bare_fn_ty =
834- ty:: mk_bare_fn ( tcx, None , tcx. mk_bare_fn ( impl_method_type. fty . clone ( ) ) ) ;
835- if ty:: type_has_self ( bare_fn_ty) {
836- debug ! ( "emit_vtable_methods: type_has_self {}" ,
837- bare_fn_ty. repr( tcx) ) ;
838- return nullptr;
839- }
840-
841833 // If this is a default method, it's possible that it
842834 // relies on where clauses that do not hold for this
843835 // particular set of type parameters. Note that this
844836 // method could then never be called, so we do not want to
845837 // try and trans it, in that case. Issue #23435.
846838 if ty:: provided_source ( tcx, impl_method_def_id) . is_some ( ) {
847- let predicates =
848- monomorphize:: apply_param_substs ( tcx,
849- & substs,
850- & impl_method_type. predicates . predicates ) ;
851- if !predicates_hold ( ccx, predicates. into_vec ( ) ) {
839+ let predicates = impl_method_type. predicates . predicates . subst ( tcx, & substs) ;
840+ if !normalize_and_test_predicates ( ccx, predicates. into_vec ( ) ) {
852841 debug ! ( "emit_vtable_methods: predicates do not hold" ) ;
853842 return nullptr;
854843 }
0 commit comments