1
1
use rustc:: hir:: def_id:: DefId ;
2
2
use rustc:: traits:: { self , Reveal , SelectionContext } ;
3
- use rustc:: ty:: subst:: { Substs , Subst } ;
3
+ use rustc:: ty:: subst:: Substs ;
4
4
use rustc:: ty;
5
5
6
6
use super :: EvalContext ;
@@ -35,7 +35,12 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
35
35
self . get_vtable_methods ( id, substs)
36
36
. into_iter ( )
37
37
. map ( |opt_mth| opt_mth. map ( |mth| {
38
- let fn_ty = self . tcx . erase_regions ( & mth. method . fty ) ;
38
+ let fn_ty = self . tcx . item_type ( mth. method . def_id ) ;
39
+ let fn_ty = match fn_ty. sty {
40
+ ty:: TyFnDef ( _, _, fn_ty) => fn_ty,
41
+ _ => bug ! ( "bad function type: {}" , fn_ty) ,
42
+ } ;
43
+ let fn_ty = self . tcx . erase_regions ( & fn_ty) ;
39
44
self . memory . create_fn_ptr ( self . tcx , mth. method . def_id , mth. substs , fn_ty)
40
45
} ) )
41
46
. collect :: < Vec < _ > > ( )
@@ -85,8 +90,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
85
90
self . memory . write_usize ( vtable, 0 ) ?;
86
91
if let ty:: TyAdt ( adt_def, substs) = trait_ref. self_ty ( ) . sty {
87
92
if let Some ( drop_def_id) = adt_def. destructor ( ) {
88
- let ty_scheme = self . tcx . lookup_item_type ( drop_def_id) ;
89
- let fn_ty = match ty_scheme. ty . sty {
93
+ let fn_ty = match self . tcx . item_type ( drop_def_id) . sty {
90
94
ty:: TyFnDef ( _, _, fn_ty) => self . tcx . erase_regions ( & fn_ty) ,
91
95
_ => bug ! ( "drop method is not a TyFnDef" ) ,
92
96
} ;
@@ -120,18 +124,15 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
120
124
121
125
self . tcx . populate_implementations_for_trait_if_necessary ( trait_id) ;
122
126
123
- let trait_item_def_ids = self . tcx . impl_or_trait_items ( trait_id) ;
124
- trait_item_def_ids
125
- . iter ( )
126
-
127
+ self . tcx
128
+ . associated_items ( trait_id)
127
129
// Filter out non-method items.
128
- . filter_map ( |& trait_method_def_id| {
129
- let trait_method_type = match self . tcx . impl_or_trait_item ( trait_method_def_id) {
130
- ty:: MethodTraitItem ( trait_method_type) => trait_method_type,
131
- _ => return None ,
132
- } ;
133
- debug ! ( "get_vtable_methods: trait_method_def_id={:?}" ,
134
- trait_method_def_id) ;
130
+ . filter_map ( |trait_method_type| {
131
+ if trait_method_type. kind != ty:: AssociatedKind :: Method {
132
+ return None ;
133
+ }
134
+ debug ! ( "get_vtable_methods: trait_method_type={:?}" ,
135
+ trait_method_type) ;
135
136
136
137
let name = trait_method_type. name ;
137
138
@@ -146,7 +147,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
146
147
147
148
// the method may have some early-bound lifetimes, add
148
149
// regions for those
149
- let method_substs = Substs :: for_item ( self . tcx , trait_method_def_id ,
150
+ let method_substs = Substs :: for_item ( self . tcx , trait_method_type . def_id ,
150
151
|_, _| self . tcx . mk_region ( ty:: ReErased ) ,
151
152
|_, _| self . tcx . types . err ) ;
152
153
@@ -162,8 +163,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
162
163
// method could then never be called, so we do not want to
163
164
// try and trans it, in that case. Issue #23435.
164
165
if mth. is_provided {
165
- let predicates = mth . method . predicates . predicates . subst ( self . tcx , mth. substs ) ;
166
- if !self . normalize_and_test_predicates ( predicates) {
166
+ let predicates = self . tcx . item_predicates ( trait_method_type . def_id ) . instantiate_own ( self . tcx , mth. substs ) ;
167
+ if !self . normalize_and_test_predicates ( predicates. predicates ) {
167
168
debug ! ( "get_vtable_methods: predicates do not hold" ) ;
168
169
return Some ( None ) ;
169
170
}
0 commit comments