From 755001725aee4c220258402f246714057be0648a Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 26 Sep 2011 19:59:49 -0700 Subject: [PATCH] Prevent copying of uncopyable things via compound assignment ops --- src/comp/middle/kind.rs | 5 ++++- src/test/compile-fail/vec-pinned-nocopy-2.rs | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/vec-pinned-nocopy-2.rs diff --git a/src/comp/middle/kind.rs b/src/comp/middle/kind.rs index 1f88820340d5..a06333df46ca 100644 --- a/src/comp/middle/kind.rs +++ b/src/comp/middle/kind.rs @@ -170,7 +170,10 @@ fn check_expr(tcx: ty::ctxt, e: @ast::expr) { need_shared_lhs_rhs(tcx, a, b, "="); check_copy(tcx, b); } - ast::expr_assign_op(_, a, b) { need_shared_lhs_rhs(tcx, a, b, "op="); } + ast::expr_assign_op(_, a, b) { + need_shared_lhs_rhs(tcx, a, b, "op="); + check_copy(tcx, b); + } ast::expr_swap(a, b) { need_shared_lhs_rhs(tcx, a, b, "<->"); } ast::expr_copy(a) { need_expr_kind(tcx, a, ast::kind_shared, "'copy' operand"); diff --git a/src/test/compile-fail/vec-pinned-nocopy-2.rs b/src/test/compile-fail/vec-pinned-nocopy-2.rs new file mode 100644 index 000000000000..1848d491bcc0 --- /dev/null +++ b/src/test/compile-fail/vec-pinned-nocopy-2.rs @@ -0,0 +1,9 @@ +// error-pattern: mismatched kind + +resource r(b: bool) { +} + +fn main() { + let i = [r(true)]; + i += [r(true)]; +} \ No newline at end of file