Skip to content

Commit ad70c74

Browse files
committed
Apply explicit self transformation before we enter check_fn
1 parent 00f97b9 commit ad70c74

File tree

3 files changed

+21
-50
lines changed

3 files changed

+21
-50
lines changed

Diff for: src/librustc/middle/typeck/check/mod.rs

+17-36
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ pub mod method;
144144
pub struct SelfInfo {
145145
self_ty: ty::t,
146146
self_id: ast::node_id,
147-
def_id: ast::def_id,
148-
explicit_self: ast::self_ty
147+
span: span
149148
}
150149

151150
/// Fields that are part of a `FnCtxt` which are inherited by
@@ -339,25 +338,6 @@ pub fn check_fn(ccx: @mut CrateCtxt,
339338
}
340339
};
341340

342-
// Update the SelfInfo to contain an accurate self type (taking
343-
// into account explicit self).
344-
let self_info = do self_info.chain_ref |self_info| {
345-
// If the self type is sty_static, we don't have a self ty.
346-
if self_info.explicit_self.node == ast::sty_static {
347-
None
348-
} else {
349-
let in_scope_regions = fcx.in_scope_regions;
350-
let self_region = in_scope_regions.find(ty::br_self);
351-
let ty = method::transform_self_type_for_method(
352-
fcx.tcx(),
353-
self_region,
354-
self_info.self_ty,
355-
self_info.explicit_self.node,
356-
TransformTypeNormally);
357-
Some(SelfInfo { self_ty: ty,.. *self_info })
358-
}
359-
};
360-
361341
gather_locals(fcx, decl, body, arg_tys, self_info);
362342
check_block(fcx, body);
363343

@@ -495,20 +475,25 @@ pub fn check_fn(ccx: @mut CrateCtxt,
495475

496476
pub fn check_method(ccx: @mut CrateCtxt,
497477
method: @ast::method,
498-
self_ty: ty::t,
499-
self_impl_def_id: ast::def_id) {
500-
let self_info = SelfInfo {
501-
self_ty: self_ty,
502-
self_id: method.self_id,
503-
def_id: self_impl_def_id,
504-
explicit_self: method.self_ty
478+
self_ty: ty::t)
479+
{
480+
let self_info = if method.self_ty.node == ast::sty_static {None} else {
481+
let ty = method::transform_self_type_for_method(
482+
ccx.tcx,
483+
Some(ty::re_bound(ty::br_self)),
484+
self_ty,
485+
method.self_ty.node,
486+
TransformTypeNormally);
487+
Some(SelfInfo {self_ty: ty, self_id: method.self_id,
488+
span: method.self_ty.span})
505489
};
490+
506491
check_bare_fn(
507492
ccx,
508493
&method.decl,
509494
&method.body,
510495
method.id,
511-
Some(self_info)
496+
self_info
512497
);
513498
}
514499

@@ -545,11 +530,7 @@ pub fn check_struct(ccx: @mut CrateCtxt,
545530
let class_t = SelfInfo {
546531
self_ty: self_ty,
547532
self_id: dtor.node.self_id,
548-
def_id: local_def(id),
549-
explicit_self: spanned {
550-
node: ast::sty_by_ref,
551-
span: codemap::dummy_sp()
552-
}
533+
span: dtor.span,
553534
};
554535
// typecheck the dtor
555536
let dtor_dec = ast_util::dtor_dec();
@@ -589,7 +570,7 @@ pub fn check_item(ccx: @mut CrateCtxt, it: @ast::item) {
589570
*ccx.tcx.sess.str_of(it.ident), it.id, rp);
590571
let self_ty = ccx.to_ty(&rscope::type_rscope(rp), ty);
591572
for ms.each |m| {
592-
check_method(ccx, *m, self_ty, local_def(it.id));
573+
check_method(ccx, *m, self_ty);
593574
}
594575
}
595576
ast::item_trait(_, _, ref trait_methods) => {
@@ -601,7 +582,7 @@ pub fn check_item(ccx: @mut CrateCtxt, it: @ast::item) {
601582
}
602583
provided(m) => {
603584
let self_ty = ty::mk_self(ccx.tcx, local_def(it.id));
604-
check_method(ccx, m, self_ty, local_def(it.id));
585+
check_method(ccx, m, self_ty);
605586
}
606587
}
607588
}

Diff for: src/librustc/middle/typeck/check/regionmanip.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,8 @@ pub fn replace_bound_regions_in_fn_sig(
4040

4141
let mut all_tys = ty::tys_in_fn_sig(fn_sig);
4242

43-
match self_info {
44-
Some(SelfInfo {
45-
explicit_self: codemap::spanned {
46-
node: ast::sty_region(_, m),
47-
// FIXME(#4846) ------^ Use this lifetime instead of self
48-
_}, _}) => {
49-
let region = ty::re_bound(ty::br_self);
50-
let ty = ty::mk_rptr(tcx, region,
51-
ty::mt { ty: ty::mk_nil(tcx), mutbl: m });
52-
all_tys.push(ty);
53-
}
54-
_ => {}
43+
for self_info.each |self_info| {
44+
all_tys.push(self_info.self_ty);
5545
}
5646

5747
for self_ty.each |t| { all_tys.push(*t) }

Diff for: src/librustc/middle/typeck/check/writeback.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ pub fn resolve_type_vars_in_fn(fcx: @mut FnCtxt,
283283
let visit = mk_visitor();
284284
(visit.visit_block)(blk, wbcx, visit);
285285
for self_info.each |self_info| {
286-
if self_info.explicit_self.node == ast::sty_static { break; }
287-
resolve_type_vars_for_node(wbcx, self_info.explicit_self.span,
286+
resolve_type_vars_for_node(wbcx,
287+
self_info.span,
288288
self_info.self_id);
289289
}
290290
for decl.inputs.each |arg| {

0 commit comments

Comments
 (0)