@@ -79,11 +79,16 @@ import typeck::infer::{resolve_type, force_tvar};
79
79
80
80
import std:: map:: str_hash;
81
81
82
+ type self_info = {
83
+ self_ty : ty:: t ,
84
+ node_id : ast:: node_id ,
85
+ } ;
86
+
82
87
type fn_ctxt_ =
83
88
// var_bindings, locals and next_var_id are shared
84
89
// with any nested functions that capture the environment
85
90
// (and with any functions whose environment is being captured).
86
- { self_ty : option < ty :: t > ,
91
+ { self_info : option < self_info > ,
87
92
ret_ty : ty:: t ,
88
93
// Used by loop bodies that return from the outer function
89
94
indirect_ret_ty : option < ty:: t > ,
@@ -122,7 +127,7 @@ fn blank_fn_ctxt(ccx: @crate_ctxt, rty: ty::t,
122
127
region_bnd : ast:: node_id ) -> @fn_ctxt {
123
128
// It's kind of a kludge to manufacture a fake function context
124
129
// and statement context, but we might as well do write the code only once
125
- @fn_ctxt_ ( { self_ty : none,
130
+ @fn_ctxt_ ( { self_info : none,
126
131
ret_ty: rty,
127
132
indirect_ret_ty: none,
128
133
purity: ast:: pure_fn,
@@ -170,14 +175,14 @@ fn check_bare_fn(ccx: @crate_ctxt,
170
175
decl : ast:: fn_decl ,
171
176
body : ast:: blk ,
172
177
id : ast:: node_id ,
173
- self_ty : option < ty :: t > ) {
178
+ self_info : option < self_info > ) {
174
179
let fty = ty:: node_id_to_type ( ccx. tcx , id) ;
175
180
let fn_ty = alt check ty:: get ( fty) . struct { ty:: ty_fn ( f) { f} } ;
176
- check_fn ( ccx, self_ty , fn_ty, decl, body, false , none) ;
181
+ check_fn ( ccx, self_info , fn_ty, decl, body, false , none) ;
177
182
}
178
183
179
184
fn check_fn( ccx : @crate_ctxt ,
180
- self_ty : option < ty :: t > ,
185
+ self_info : option < self_info > ,
181
186
fn_ty : ty:: fn_ty ,
182
187
decl : ast:: fn_decl ,
183
188
body : ast:: blk ,
@@ -191,20 +196,20 @@ fn check_fn(ccx: @crate_ctxt,
191
196
// types with free ones. The free region references will be bound
192
197
// the node_id of the body block.
193
198
194
- let { isr, self_ty , fn_ty} = {
199
+ let { isr, self_info , fn_ty} = {
195
200
let old_isr = option:: map_default ( old_fcx, @nil,
196
201
|fcx| fcx. in_scope_regions ) ;
197
- replace_bound_regions_in_fn_ty ( tcx, old_isr, self_ty , fn_ty,
202
+ replace_bound_regions_in_fn_ty ( tcx, old_isr, self_info , fn_ty,
198
203
|br| ty:: re_free ( body. node . id , br) )
199
204
} ;
200
205
201
206
let arg_tys = fn_ty. inputs . map ( |a| a. ty ) ;
202
207
let ret_ty = fn_ty. output ;
203
208
204
- debug ! { "check_fn(arg_tys=%?, ret_ty=%?, self_ty=%?)" ,
209
+ debug ! { "check_fn(arg_tys=%?, ret_ty=%?, self_info. self_ty=%?)" ,
205
210
arg_tys. map( |a| ty_to_str( tcx, a) ) ,
206
211
ty_to_str( tcx, ret_ty) ,
207
- option:: map( self_ty , |st | ty_to_str( tcx, st ) ) } ;
212
+ option:: map( self_info , |s | ty_to_str( tcx, s . self_ty ) ) } ;
208
213
209
214
// ______________________________________________________________________
210
215
// Create the function context. This is either derived from scratch or,
@@ -237,7 +242,7 @@ fn check_fn(ccx: @crate_ctxt,
237
242
}
238
243
} else { none } ;
239
244
240
- @fn_ctxt_ ( { self_ty : self_ty ,
245
+ @fn_ctxt_ ( { self_info : self_info ,
241
246
ret_ty: ret_ty,
242
247
indirect_ret_ty: indirect_ret_ty,
243
248
purity: purity,
@@ -359,11 +364,12 @@ fn check_fn(ccx: @crate_ctxt,
359
364
}
360
365
}
361
366
362
- fn check_method( ccx: @crate_ctxt, method: @ast:: method, self_ty: ty:: t) {
363
- check_bare_fn ( ccx, method. decl , method. body , method. id , some ( self_ty) ) ;
367
+ fn check_method( ccx: @crate_ctxt, method: @ast:: method,
368
+ self_info: self_info) {
369
+ check_bare_fn ( ccx, method. decl , method. body , method. id , some ( self_info) ) ;
364
370
}
365
371
366
- fn check_class_member ( ccx : @crate_ctxt , class_t : ty :: t ,
372
+ fn check_class_member ( ccx : @crate_ctxt , class_t : self_info ,
367
373
cm : @ast:: class_member ) {
368
374
alt cm. node {
369
375
ast:: instance_var ( _, t, _, _, _) { }
@@ -409,20 +415,22 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) {
409
415
let rp = ccx. tcx . region_paramd_items . contains_key ( it. id ) ;
410
416
debug ! { "item_impl %s with id %d rp %b" ,
411
417
* it. ident, it. id, rp} ;
412
- let self_ty = ccx. to_ty ( rscope:: type_rscope ( rp) , ty) ;
413
- for ms. each |m| { check_method( ccx, m, self_ty) ; }
418
+ let self_info = { self_ty: ccx. to_ty ( rscope:: type_rscope ( rp) , ty) ,
419
+ node_id: it. id } ;
420
+ for ms. each |m| { check_method( ccx, m, self_info) ; }
414
421
}
415
422
ast:: item_class ( tps, traits, members, m_ctor, m_dtor) {
416
423
let tcx = ccx. tcx ;
417
- let class_t = ty:: node_id_to_type ( tcx, it. id ) ;
424
+ let class_t = { self_ty: ty:: node_id_to_type ( tcx, it. id ) ,
425
+ node_id: it. id } ;
418
426
419
427
do option:: iter ( m_ctor) |ctor| {
420
428
// typecheck the ctor
421
429
check_bare_fn ( ccx, ctor. node . dec ,
422
430
ctor. node . body , ctor. node . id ,
423
431
some ( class_t) ) ;
424
432
// Write the ctor's self's type
425
- write_ty_to_tcx ( tcx, ctor. node . self_id , class_t) ;
433
+ write_ty_to_tcx ( tcx, ctor. node . self_id , class_t. self_ty ) ;
426
434
}
427
435
428
436
do option:: iter ( m_dtor) |dtor| {
@@ -431,7 +439,7 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) {
431
439
dtor. node . body , dtor. node . id ,
432
440
some ( class_t) ) ;
433
441
// Write the dtor's self's type
434
- write_ty_to_tcx ( tcx, dtor. node . self_id , class_t) ;
442
+ write_ty_to_tcx ( tcx, dtor. node . self_id , class_t. self_ty ) ;
435
443
} ;
436
444
437
445
// typecheck the members
@@ -1123,7 +1131,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
1123
1131
1124
1132
fcx. write_ty( expr. id, fty) ;
1125
1133
1126
- check_fn( fcx. ccx, fcx. self_ty , fn_ty, decl, body,
1134
+ check_fn( fcx. ccx, fcx. self_info , fn_ty, decl, body,
1127
1135
is_loop_body, some( fcx) ) ;
1128
1136
}
1129
1137
@@ -2145,12 +2153,12 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
2145
2153
ret no_params(typ);
2146
2154
}
2147
2155
ast::def_self(_) {
2148
- alt fcx.self_ty {
2149
- some(self_ty ) {
2150
- ret no_params(self_ty);
2156
+ alt fcx.self_info {
2157
+ some(self_info ) {
2158
+ ret no_params(self_info. self_ty);
2151
2159
}
2152
2160
none {
2153
- fcx.ccx.tcx.sess.span_bug(sp, ~" def_self with no self_ty ");
2161
+ fcx.ccx.tcx.sess.span_bug(sp, ~" def_self with no self_info ");
2154
2162
}
2155
2163
}
2156
2164
}
0 commit comments