rustc: Add some missing cases in various folds for reference types and some broken trans code for the address-of operator

This commit is contained in:
Patrick Walton
2012-03-08 15:54:36 -08:00
parent 0c5fdc8745
commit 0722786664
3 changed files with 19 additions and 3 deletions

View File

@@ -95,7 +95,7 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) ->
ty::ty_uniq(mt) { is_mutbl = mt.mutbl == m_mutbl; }
ty::ty_res(_, _, _) { }
ty::ty_enum(_, _) { }
ty::ty_ptr(mt) {
ty::ty_ptr(mt) | ty::ty_rptr(_, mt) {
is_mutbl = mt.mutbl == m_mutbl;
ptr = true;
}

View File

@@ -1646,7 +1646,13 @@ fn trans_unary(bcx: block, op: ast::unop, e: @ast::expr,
trans_unary()");
}
ast::addr_of {
bcx.sess().bug("TODO pcwalton");
// FIXME: This is wrong.
let {bcx, val, kind} = trans_temp_lval(bcx, e);
if kind != owned {
bcx.sess().span_bug(e.span,
"can't take the address of an rvalue");
}
ret store_in_dest(bcx, val, dest);
}
}
}
@@ -2516,7 +2522,7 @@ fn trans_lval(cx: block, e: @ast::expr) -> lval_result {
} else { T_typaram_ptr(ccx.tn) };
PointerCast(sub.bcx, sub.val, ellty)
}
ty::ty_ptr(_) | ty::ty_uniq(_) { sub.val }
ty::ty_ptr(_) | ty::ty_uniq(_) | ty::ty_rptr(_,_) { sub.val }
};
ret lval_owned(sub.bcx, val);
}

View File

@@ -272,6 +272,7 @@ enum type_err {
terr_ret_style_mismatch(ast::ret_style, ast::ret_style),
terr_box_mutability,
terr_ptr_mutability,
terr_ref_mutability,
terr_vec_mutability,
terr_tuple_size(uint, uint),
terr_record_size(uint, uint),
@@ -570,6 +571,9 @@ fn fold_ty(cx: ctxt, fld: fold_mode, ty_0: t) -> t {
ty_ptr(tm) {
ty = mk_ptr(cx, {ty: fold_ty(cx, fld, tm.ty), mutbl: tm.mutbl});
}
ty_rptr(r, tm) {
ty = mk_rptr(cx, r, {ty: fold_ty(cx, fld, tm.ty), mutbl: tm.mutbl});
}
ty_vec(tm) {
ty = mk_vec(cx, {ty: fold_ty(cx, fld, tm.ty), mutbl: tm.mutbl});
}
@@ -1940,6 +1944,11 @@ mod unify {
(ty_ptr(e_mt), ty_ptr(a_mt)) {
unify_mt(cx, e_mt, a_mt, variance, terr_ptr_mutability, mk_ptr)
}
(ty_rptr(e_region, e_mt), ty_rptr(a_region, a_mt)) {
// TODO: Unify regions. Take covariance/invariance into account.
unify_mt(cx, e_mt, a_mt, variance, terr_ref_mutability,
bind mk_rptr(_, re_block(0), _))
}
(ty_res(e_id, e_inner, e_tps), ty_res(a_id, a_inner, a_tps))
if e_id == a_id {
alt unify_step(cx, e_inner, a_inner, variance) {
@@ -2116,6 +2125,7 @@ fn type_err_to_str(err: type_err) -> str {
terr_box_mutability { ret "boxed values differ in mutability"; }
terr_vec_mutability { ret "vectors differ in mutability"; }
terr_ptr_mutability { ret "pointers differ in mutability"; }
terr_ref_mutability { ret "references differ in mutability"; }
terr_tuple_size(e_sz, a_sz) {
ret "expected a tuple with " + uint::to_str(e_sz, 10u) +
" elements but found one with " + uint::to_str(a_sz, 10u) +