Skip to content

Commit 663f298

Browse files
committed
Get rid of cast on every self reference.
1 parent 3c86711 commit 663f298

File tree

3 files changed

+17
-24
lines changed

3 files changed

+17
-24
lines changed

src/librustc/middle/trans/base.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,21 +1683,20 @@ pub fn copy_args_to_allocas(fcx: fn_ctxt,
16831683

16841684
match fcx.llself {
16851685
Some(slf) => {
1686-
// We really should do this regardless of whether self is owned, but
1687-
// it doesn't work right with default method impls yet. (FIXME: #2794)
1688-
if slf.is_owned {
1689-
let self_val = if datum::appropriate_mode(slf.t).is_by_value() {
1690-
let tmp = BitCast(bcx, slf.v, type_of(bcx.ccx(), slf.t));
1691-
let alloc = alloc_ty(bcx, slf.t);
1692-
Store(bcx, tmp, alloc);
1693-
alloc
1694-
} else {
1695-
PointerCast(bcx, slf.v, type_of(bcx.ccx(), slf.t).ptr_to())
1696-
};
1697-
1698-
fcx.llself = Some(ValSelfData {v: self_val, ..slf});
1699-
add_clean(bcx, self_val, slf.t);
1700-
}
1686+
let self_val = if slf.is_owned
1687+
&& datum::appropriate_mode(slf.t).is_by_value() {
1688+
let tmp = BitCast(bcx, slf.v, type_of(bcx.ccx(), slf.t));
1689+
let alloc = alloc_ty(bcx, slf.t);
1690+
Store(bcx, tmp, alloc);
1691+
alloc
1692+
} else {
1693+
PointerCast(bcx, slf.v, type_of(bcx.ccx(), slf.t).ptr_to())
1694+
};
1695+
1696+
fcx.llself = Some(ValSelfData {v: self_val, ..slf});
1697+
if slf.is_owned {
1698+
add_clean(bcx, self_val, slf.t);
1699+
}
17011700
}
17021701
_ => {}
17031702
}

src/librustc/middle/trans/expr.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,14 +1051,8 @@ pub fn trans_local_var(bcx: block, def: ast::def) -> Datum {
10511051
debug!("def_self() reference, self_info.t=%s",
10521052
self_info.t.repr(bcx.tcx()));
10531053

1054-
// This cast should not be necessary. We should cast self *once*,
1055-
// but right now this conflicts with default methods.
1056-
let real_self_ty = monomorphize_type(bcx, self_info.t);
1057-
let llselfty = type_of::type_of(bcx.ccx(), real_self_ty).ptr_to();
1058-
1059-
let casted_val = PointerCast(bcx, self_info.v, llselfty);
10601054
Datum {
1061-
val: casted_val,
1055+
val: self_info.v,
10621056
ty: self_info.t,
10631057
mode: ByRef(ZeroMem)
10641058
}

src/librustc/middle/trans/meth.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ pub fn trans_method(ccx: @mut CrateContext,
103103
let self_ty = ty::node_id_to_type(ccx.tcx, method.self_id);
104104
let self_ty = match param_substs {
105105
None => self_ty,
106-
Some(@param_substs {tys: ref tys, _}) => {
107-
ty::subst_tps(ccx.tcx, *tys, None, self_ty)
106+
Some(@param_substs {tys: ref tys, self_ty: ref self_sub, _}) => {
107+
ty::subst_tps(ccx.tcx, *tys, *self_sub, self_ty)
108108
}
109109
};
110110
debug!("calling trans_fn with self_ty %s",

0 commit comments

Comments
 (0)