Skip to content

Commit b59f2ea

Browse files
bblumcatamorphism
authored andcommitted
Enforce copyability in bind_by_value match arms (fix rust-lang#3255)
1 parent 55bf31c commit b59f2ea

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Diff for: src/rustc/middle/kind.rs

+14
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ fn check_crate(tcx: ty::ctxt,
7474
last_use_map: last_use_map,
7575
current_item: -1};
7676
let visit = visit::mk_vt(@{
77+
visit_arm: check_arm,
7778
visit_expr: check_expr,
7879
visit_stmt: check_stmt,
7980
visit_block: check_block,
@@ -225,6 +226,19 @@ fn check_block(b: blk, cx: ctx, v: visit::vt<ctx>) {
225226
visit::visit_block(b, cx, v);
226227
}
227228

229+
fn check_arm(a: arm, cx: ctx, v: visit::vt<ctx>) {
230+
for vec::each(a.pats) |p| {
231+
do pat_util::pat_bindings(cx.tcx.def_map, p) |mode, id, span, _path| {
232+
if mode == bind_by_value {
233+
let t = ty::node_id_to_type(cx.tcx, id);
234+
let reason = "consider binding with `ref` or `move` instead";
235+
check_copy(cx, id, t, span, false, some((reason,reason)));
236+
}
237+
}
238+
}
239+
visit::visit_arm(a, cx, v);
240+
}
241+
228242
fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
229243
debug!("kind::check_expr(%s)", expr_to_str(e, cx.tcx.sess.intr()));
230244

Diff for: src/test/run-pass/pipe-presentation-examples.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ macro_rules! select_if (
2323
} => {
2424
if $index == $count {
2525
match move pipes::try_recv($port) {
26-
$(some($message($($(copy $x,)+)* next)) => {
27-
// FIXME (#2329) we really want move out of enum here.
26+
$(some($message($($(move $x,)+)* next)) => {
2827
let $next = unsafe { let x <- *ptr::addr_of(next); x };
2928
$e
3029
})+

0 commit comments

Comments
 (0)