@@ -80,6 +80,7 @@ import std::map::str_hash;
80
80
type self_info = {
81
81
self_ty : ty:: t ,
82
82
node_id : ast:: node_id ,
83
+ explicit_self : ast:: self_ty_
83
84
} ;
84
85
85
86
type fn_ctxt_ =
@@ -367,14 +368,20 @@ fn check_fn(ccx: @crate_ctxt,
367
368
368
369
fn check_method ( ccx : @crate_ctxt , method : @ast:: method ,
369
370
self_info : self_info ) {
371
+
370
372
check_bare_fn ( ccx, method. decl , method. body , method. id , some ( self_info) ) ;
371
373
}
372
374
373
- fn check_class_member ( ccx : @crate_ctxt , class_t : self_info ,
375
+ fn check_class_member ( ccx : @crate_ctxt , self_ty : ty:: t ,
376
+ node_id : ast:: node_id ,
374
377
cm : @ast:: class_member ) {
375
378
match cm. node {
376
379
ast:: instance_var( _, t, _, _, _) => ( ) ,
377
- ast:: class_method( m) => check_method ( ccx, m, class_t)
380
+ ast:: class_method( m) => {
381
+ let class_t = { self_ty: self_ty, node_id: node_id,
382
+ explicit_self: m. self_ty . node } ;
383
+ check_method ( ccx, m, class_t)
384
+ }
378
385
}
379
386
}
380
387
@@ -404,9 +411,11 @@ fn check_no_duplicate_fields(tcx: ty::ctxt, fields:
404
411
fn check_struct( ccx : @crate_ctxt , struct_def : @ast:: struct_def ,
405
412
id : ast:: node_id , span : span ) {
406
413
let tcx = ccx. tcx ;
407
- let class_t = { self_ty : ty:: node_id_to_type ( tcx, id) , node_id : id } ;
414
+ let self_ty = ty:: node_id_to_type ( tcx, id) ;
408
415
409
416
do option:: iter ( struct_def. ctor ) |ctor| {
417
+ let class_t = { self_ty: self_ty, node_id: id,
418
+ explicit_self: ast:: sty_by_ref} ;
410
419
// typecheck the ctor
411
420
check_bare_fn ( ccx, ctor. node . dec ,
412
421
ctor. node . body , ctor. node . id ,
@@ -416,6 +425,8 @@ fn check_struct(ccx: @crate_ctxt, struct_def: @ast::struct_def,
416
425
}
417
426
418
427
do option:: iter ( struct_def. dtor ) |dtor| {
428
+ let class_t = { self_ty: self_ty, node_id: id,
429
+ explicit_self: ast:: sty_by_ref} ;
419
430
// typecheck the dtor
420
431
check_bare_fn ( ccx, ast_util:: dtor_dec ( ) ,
421
432
dtor. node . body , dtor. node . id ,
@@ -426,7 +437,7 @@ fn check_struct(ccx: @crate_ctxt, struct_def: @ast::struct_def,
426
437
427
438
// typecheck the members
428
439
for struct_def. members. each |m| {
429
- check_class_member( ccx, class_t , m) ;
440
+ check_class_member( ccx, self_ty , id , m) ;
430
441
}
431
442
// Check that there's at least one field
432
443
let ( fields, _) = split_class_items( struct_def. members) ;
@@ -450,9 +461,12 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) {
450
461
let rp = ccx. tcx . region_paramd_items . contains_key ( it. id ) ;
451
462
debug ! { "item_impl %s with id %d rp %b" ,
452
463
* it. ident, it. id, rp} ;
453
- let self_info = { self_ty: ccx. to_ty ( rscope:: type_rscope ( rp) , ty) ,
454
- node_id: it. id } ;
455
- for ms. each |m| { check_method( ccx, m, self_info) ; }
464
+ let self_ty = ccx. to_ty ( rscope:: type_rscope ( rp) , ty) ;
465
+ for ms. each |m| {
466
+ let self_info = { self_ty: self_ty, node_id: it. id ,
467
+ explicit_self: m. self_ty . node } ;
468
+ check_method ( ccx, m, self_info)
469
+ }
456
470
}
457
471
ast:: item_trait( _, _, trait_methods) => {
458
472
for trait_methods. each |trait_method| {
@@ -463,7 +477,8 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) {
463
477
}
464
478
provided( m) => {
465
479
let self_info = { self_ty: ty:: mk_self ( ccx. tcx ) ,
466
- node_id: it. id } ;
480
+ node_id: it. id ,
481
+ explicit_self: m. self_ty . node } ;
467
482
check_method ( ccx, m, self_info) ;
468
483
}
469
484
}
@@ -742,7 +757,8 @@ fn check_expr(fcx: @fn_ctxt, expr: @ast::expr,
742
757
// declared on the impl declaration e.g., `impl<A,B> for ~[(A,B)]`
743
758
// would return ($0, $1) where $0 and $1 are freshly instantiated type
744
759
// variables.
745
- fn impl_self_ty( fcx : @fn_ctxt , did : ast:: def_id ) -> ty_param_substs_and_ty {
760
+ fn impl_self_ty( fcx : @fn_ctxt , did : ast:: def_id , require_rp : bool )
761
+ -> ty_param_substs_and_ty {
746
762
let tcx = fcx. ccx . tcx ;
747
763
748
764
let { n_tps, rp, raw_ty} = if did. crate == ast:: local_crate {
@@ -778,6 +794,7 @@ fn impl_self_ty(fcx: @fn_ctxt, did: ast::def_id) -> ty_param_substs_and_ty {
778
794
raw_ty: ity. ty }
779
795
} ;
780
796
797
+ let rp = rp || require_rp;
781
798
let self_r = if rp { some ( fcx. infcx . next_region_var_nb ( ) ) } else { none} ;
782
799
let tps = fcx. infcx . next_ty_vars ( n_tps) ;
783
800
@@ -2216,7 +2233,10 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
2216
2233
ast::def_self(_) => {
2217
2234
match fcx.self_info {
2218
2235
some(self_info) => {
2219
- return no_params(self_info.self_ty);
2236
+ let self_region = fcx.in_scope_regions.find(ty::br_self);
2237
+ return no_params(method::transform_self_type_for_method(
2238
+ fcx.tcx(), self_region,
2239
+ self_info.self_ty, self_info.explicit_self));
2220
2240
}
2221
2241
none => {
2222
2242
fcx.ccx.tcx.sess.span_bug(sp, ~" def_self with no self_info");
0 commit comments