From ad70c748c35958f8afdc70cf67054dd1968e4b78 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 19 Mar 2013 11:58:59 -0400 Subject: [PATCH] Apply explicit self transformation before we enter check_fn --- src/librustc/middle/typeck/check/mod.rs | 53 ++++++------------- .../middle/typeck/check/regionmanip.rs | 14 +---- src/librustc/middle/typeck/check/writeback.rs | 4 +- 3 files changed, 21 insertions(+), 50 deletions(-) diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index d79e71a926e..472e042d128 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -144,8 +144,7 @@ pub mod method; pub struct SelfInfo { self_ty: ty::t, self_id: ast::node_id, - def_id: ast::def_id, - explicit_self: ast::self_ty + span: span } /// Fields that are part of a `FnCtxt` which are inherited by @@ -339,25 +338,6 @@ pub fn check_fn(ccx: @mut CrateCtxt, } }; - // Update the SelfInfo to contain an accurate self type (taking - // into account explicit self). - let self_info = do self_info.chain_ref |self_info| { - // If the self type is sty_static, we don't have a self ty. - if self_info.explicit_self.node == ast::sty_static { - None - } else { - let in_scope_regions = fcx.in_scope_regions; - let self_region = in_scope_regions.find(ty::br_self); - let ty = method::transform_self_type_for_method( - fcx.tcx(), - self_region, - self_info.self_ty, - self_info.explicit_self.node, - TransformTypeNormally); - Some(SelfInfo { self_ty: ty,.. *self_info }) - } - }; - gather_locals(fcx, decl, body, arg_tys, self_info); check_block(fcx, body); @@ -495,20 +475,25 @@ pub fn check_fn(ccx: @mut CrateCtxt, pub fn check_method(ccx: @mut CrateCtxt, method: @ast::method, - self_ty: ty::t, - self_impl_def_id: ast::def_id) { - let self_info = SelfInfo { - self_ty: self_ty, - self_id: method.self_id, - def_id: self_impl_def_id, - explicit_self: method.self_ty + self_ty: ty::t) +{ + let self_info = if method.self_ty.node == ast::sty_static {None} else { + let ty = method::transform_self_type_for_method( + ccx.tcx, + Some(ty::re_bound(ty::br_self)), + self_ty, + method.self_ty.node, + TransformTypeNormally); + Some(SelfInfo {self_ty: ty, self_id: method.self_id, + span: method.self_ty.span}) }; + check_bare_fn( ccx, &method.decl, &method.body, method.id, - Some(self_info) + self_info ); } @@ -545,11 +530,7 @@ pub fn check_struct(ccx: @mut CrateCtxt, let class_t = SelfInfo { self_ty: self_ty, self_id: dtor.node.self_id, - def_id: local_def(id), - explicit_self: spanned { - node: ast::sty_by_ref, - span: codemap::dummy_sp() - } + span: dtor.span, }; // typecheck the dtor let dtor_dec = ast_util::dtor_dec(); @@ -589,7 +570,7 @@ pub fn check_item(ccx: @mut CrateCtxt, it: @ast::item) { *ccx.tcx.sess.str_of(it.ident), it.id, rp); let self_ty = ccx.to_ty(&rscope::type_rscope(rp), ty); for ms.each |m| { - check_method(ccx, *m, self_ty, local_def(it.id)); + check_method(ccx, *m, self_ty); } } ast::item_trait(_, _, ref trait_methods) => { @@ -601,7 +582,7 @@ pub fn check_item(ccx: @mut CrateCtxt, it: @ast::item) { } provided(m) => { let self_ty = ty::mk_self(ccx.tcx, local_def(it.id)); - check_method(ccx, m, self_ty, local_def(it.id)); + check_method(ccx, m, self_ty); } } } diff --git a/src/librustc/middle/typeck/check/regionmanip.rs b/src/librustc/middle/typeck/check/regionmanip.rs index a76a7f08f0e..c78a91b95e4 100644 --- a/src/librustc/middle/typeck/check/regionmanip.rs +++ b/src/librustc/middle/typeck/check/regionmanip.rs @@ -40,18 +40,8 @@ pub fn replace_bound_regions_in_fn_sig( let mut all_tys = ty::tys_in_fn_sig(fn_sig); - match self_info { - Some(SelfInfo { - explicit_self: codemap::spanned { - node: ast::sty_region(_, m), - // FIXME(#4846) ------^ Use this lifetime instead of self - _}, _}) => { - let region = ty::re_bound(ty::br_self); - let ty = ty::mk_rptr(tcx, region, - ty::mt { ty: ty::mk_nil(tcx), mutbl: m }); - all_tys.push(ty); - } - _ => {} + for self_info.each |self_info| { + all_tys.push(self_info.self_ty); } for self_ty.each |t| { all_tys.push(*t) } diff --git a/src/librustc/middle/typeck/check/writeback.rs b/src/librustc/middle/typeck/check/writeback.rs index 5cfb7973b96..18f23237916 100644 --- a/src/librustc/middle/typeck/check/writeback.rs +++ b/src/librustc/middle/typeck/check/writeback.rs @@ -283,8 +283,8 @@ pub fn resolve_type_vars_in_fn(fcx: @mut FnCtxt, let visit = mk_visitor(); (visit.visit_block)(blk, wbcx, visit); for self_info.each |self_info| { - if self_info.explicit_self.node == ast::sty_static { break; } - resolve_type_vars_for_node(wbcx, self_info.explicit_self.span, + resolve_type_vars_for_node(wbcx, + self_info.span, self_info.self_id); } for decl.inputs.each |arg| {