@@ -13,7 +13,7 @@ use back::abi;
13
13
use back:: link;
14
14
use llvm:: { ValueRef , get_param} ;
15
15
use metadata:: csearch;
16
- use middle:: subst:: Substs ;
16
+ use middle:: subst:: { Subst , Substs } ;
17
17
use middle:: subst:: VecPerParamSpace ;
18
18
use middle:: subst;
19
19
use middle:: traits;
@@ -784,6 +784,7 @@ fn emit_vtable_methods<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
784
784
785
785
ty:: populate_implementations_for_trait_if_necessary ( tcx, trt_id) ;
786
786
787
+ let nullptr = C_null ( Type :: nil ( ccx) . ptr_to ( ) ) ;
787
788
let trait_item_def_ids = ty:: trait_item_def_ids ( tcx, trt_id) ;
788
789
trait_item_def_ids
789
790
. iter ( )
@@ -809,6 +810,12 @@ fn emit_vtable_methods<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
809
810
} ;
810
811
let name = trait_method_type. name ;
811
812
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
+
812
819
debug ! ( "emit_vtable_methods: trait_method_type={}" ,
813
820
trait_method_type. repr( tcx) ) ;
814
821
@@ -820,35 +827,17 @@ fn emit_vtable_methods<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
820
827
ty:: TypeTraitItem ( _) => ccx. sess ( ) . bug ( "should be a method, not assoc type" )
821
828
} ;
822
829
823
- debug ! ( "emit_vtable_methods: m ={}" ,
830
+ debug ! ( "emit_vtable_methods: impl_method_type ={}" ,
824
831
impl_method_type. repr( tcx) ) ;
825
832
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
-
841
833
// If this is a default method, it's possible that it
842
834
// relies on where clauses that do not hold for this
843
835
// particular set of type parameters. Note that this
844
836
// method could then never be called, so we do not want to
845
837
// try and trans it, in that case. Issue #23435.
846
838
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 ( ) ) {
852
841
debug ! ( "emit_vtable_methods: predicates do not hold" ) ;
853
842
return nullptr;
854
843
}
0 commit comments