@@ -156,15 +156,18 @@ fn get_enum_variant_types(ccx: @crate_ctxt,
156
156
}
157
157
}
158
158
159
- fn ensure_trait_methods ( ccx : @crate_ctxt , id : ast:: node_id ) {
159
+ fn ensure_trait_methods ( ccx : @crate_ctxt , id : ast:: node_id , trait_ty : ty :: t ) {
160
160
fn store_methods < T > ( ccx : @crate_ctxt , id : ast:: node_id ,
161
161
stuff : ~[ T ] , f : fn @( T ) -> ty:: method ) {
162
162
ty:: store_trait_methods ( ccx. tcx , id, @vec:: map ( stuff, f) ) ;
163
163
}
164
164
165
- fn make_static_method_ty ( ccx : @crate_ctxt , id : ast :: node_id ,
165
+ fn make_static_method_ty ( ccx : @crate_ctxt ,
166
166
am : ast:: ty_method ,
167
167
rp : bool , m : ty:: method ,
168
+ // Take this as an argument b/c we may check
169
+ // the impl before the trait.
170
+ trait_ty : ty:: t ,
168
171
trait_bounds : @~[ ty:: param_bounds ] ) {
169
172
// We need to create a typaram that replaces self. This param goes
170
173
// *in between* the typarams from the trait and those from the
@@ -188,7 +191,6 @@ fn ensure_trait_methods(ccx: @crate_ctxt, id: ast::node_id) {
188
191
let substs = { self_r: none, self_ty: some ( self_param) ,
189
192
tps: non_shifted_trait_tps + shifted_method_tps } ;
190
193
let ty = ty:: subst ( ccx. tcx , & substs, ty:: mk_fn ( ccx. tcx , m. fty ) ) ;
191
- let trait_ty = ty:: node_id_to_type ( ccx. tcx , id) ;
192
194
let bounds = @( * trait_bounds + ~[ @~[ ty:: bound_trait ( trait_ty) ] ]
193
195
+ * m. tps ) ;
194
196
ccx. tcx . tcache . insert ( local_def ( am. id ) ,
@@ -205,8 +207,8 @@ fn ensure_trait_methods(ccx: @crate_ctxt, id: ast::node_id) {
205
207
let ty_m = trait_method_to_ty_method ( m) ;
206
208
let method_ty = ty_of_ty_method ( ccx, ty_m, rp) ;
207
209
if ty_m. self_ty . node == ast:: sty_static {
208
- make_static_method_ty ( ccx, id , ty_m, rp,
209
- method_ty, trait_bounds) ;
210
+ make_static_method_ty ( ccx, ty_m, rp,
211
+ method_ty, trait_ty , trait_bounds) ;
210
212
}
211
213
method_ty
212
214
} ) ;
@@ -319,7 +321,7 @@ fn check_methods_against_trait(ccx: @crate_ctxt,
319
321
let tcx = ccx. tcx ;
320
322
let ( did, tpt) = instantiate_trait_ref ( ccx, a_trait_ty, rp) ;
321
323
if did. crate == ast:: local_crate {
322
- ensure_trait_methods ( ccx, did. node ) ;
324
+ ensure_trait_methods ( ccx, did. node , tpt . ty ) ;
323
325
}
324
326
for vec:: each( * ty:: trait_methods( tcx, did) ) |trait_m| {
325
327
match vec:: find( impl_ms, |impl_m| trait_m. ident == impl_m. mty. ident) {
@@ -430,7 +432,7 @@ fn convert(ccx: @crate_ctxt, it: @ast::item) {
430
432
debug ! { "item_trait(it.id=%d, tpt.ty=%s)" ,
431
433
it. id, ty_to_str( tcx, tpt. ty) } ;
432
434
write_ty_to_tcx ( tcx, it. id , tpt. ty ) ;
433
- ensure_trait_methods ( ccx, it. id ) ;
435
+ ensure_trait_methods ( ccx, it. id , tpt . ty ) ;
434
436
435
437
let ( _, provided_methods) = split_trait_methods ( trait_methods) ;
436
438
let selfty = ty:: mk_self ( tcx) ;
@@ -499,7 +501,7 @@ fn convert_struct(ccx: @crate_ctxt, rp: bool, struct_def: @ast::struct_def,
499
501
rp: rp,
500
502
ty: t_dtor} ) ;
501
503
} ;
502
- ensure_trait_methods ( ccx, id) ;
504
+ ensure_trait_methods ( ccx, id, tpt . ty ) ;
503
505
504
506
// Write the type of each of the members
505
507
let ( fields, methods) = split_class_items ( struct_def. members ) ;
0 commit comments