Enforce copyability in bind_by_value match arms (fix #3255)

This commit is contained in:
Ben Blum 2012-08-24 15:24:04 -04:00
parent e47d2f6060
commit 37bcd67a09
2 changed files with 15 additions and 2 deletions

View file

@ -74,6 +74,7 @@ fn check_crate(tcx: ty::ctxt,
last_use_map: last_use_map,
current_item: -1};
let visit = visit::mk_vt(@{
visit_arm: check_arm,
visit_expr: check_expr,
visit_stmt: check_stmt,
visit_block: check_block,
@ -225,6 +226,19 @@ fn check_block(b: blk, cx: ctx, v: visit::vt<ctx>) {
visit::visit_block(b, cx, v);
}
fn check_arm(a: arm, cx: ctx, v: visit::vt<ctx>) {
for vec::each(a.pats) |p| {
do pat_util::pat_bindings(cx.tcx.def_map, p) |mode, id, span, _path| {
if mode == bind_by_value {
let t = ty::node_id_to_type(cx.tcx, id);
let reason = "consider binding with `ref` or `move` instead";
check_copy(cx, id, t, span, false, some((reason,reason)));
}
}
}
visit::visit_arm(a, cx, v);
}
fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
debug!("kind::check_expr(%s)", expr_to_str(e, cx.tcx.sess.intr()));

View file

@ -23,8 +23,7 @@ macro_rules! select_if (
} => {
if $index == $count {
match move pipes::try_recv($port) {
$(some($message($($(copy $x,)+)* next)) => {
// FIXME (#2329) we really want move out of enum here.
$(some($message($($(move $x,)+)* next)) => {
let $next = unsafe { let x <- *ptr::addr_of(next); x };
$e
})+