From aa4278a3f5f3e999459ce5784c7158c5933daade Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Wed, 18 Apr 2012 17:08:32 +0200 Subject: [PATCH] Require values to be copyable when cast Closes #2222 --- src/rustc/middle/kind.rs | 2 +- src/rustc/middle/typeck.rs | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/rustc/middle/kind.rs b/src/rustc/middle/kind.rs index df274ea06f2..0b29b0c52cd 100644 --- a/src/rustc/middle/kind.rs +++ b/src/rustc/middle/kind.rs @@ -141,7 +141,7 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt) { alt e.node { expr_assign(_, ex) | expr_assign_op(_, _, ex) | expr_unary(box(_), ex) | expr_unary(uniq(_), ex) | - expr_ret(some(ex)) { maybe_copy(cx, ex); } + expr_ret(some(ex)) | expr_cast(ex, _) { maybe_copy(cx, ex); } expr_copy(expr) { check_copy_ex(cx, expr, false); } // Vector add copies. expr_binary(add, ls, rs) { maybe_copy(cx, ls); maybe_copy(cx, rs); } diff --git a/src/rustc/middle/typeck.rs b/src/rustc/middle/typeck.rs index bb01c879e0a..4a6e48a681f 100644 --- a/src/rustc/middle/typeck.rs +++ b/src/rustc/middle/typeck.rs @@ -376,7 +376,8 @@ impl of region_scope for @fn_ctxt { } enum anon_rscope = {anon: ty::region, base: region_scope}; -fn in_anon_rscope(self: RS, r: ty::region) -> @anon_rscope { +fn in_anon_rscope(self: RS, r: ty::region) + -> @anon_rscope { @anon_rscope({anon: r, base: self as region_scope}) } impl of region_scope for @anon_rscope { @@ -395,7 +396,7 @@ impl of region_scope for self_rscope { } enum binding_rscope = {base: region_scope}; -fn in_binding_rscope(self: RS) -> @binding_rscope { +fn in_binding_rscope(self: RS) -> @binding_rscope { let base = self as region_scope; @binding_rscope({base: base}) } @@ -410,7 +411,7 @@ impl of region_scope for @binding_rscope { } } -fn ast_region_to_region( +fn ast_region_to_region( self: AC, rscope: RS, span: span, a_r: ast::region) -> ty::region { alt a_r.node { @@ -437,16 +438,16 @@ fn ast_region_to_region( // Parses the programmer's textual representation of a type into our // internal notion of a type. `getter` is a function that returns the type // corresponding to a definition ID: -fn ast_ty_to_ty( +fn ast_ty_to_ty( self: AC, rscope: RS, &&ast_ty: @ast::ty) -> ty::t { - fn ast_mt_to_mt( + fn ast_mt_to_mt( self: AC, rscope: RS, mt: ast::mt) -> ty::mt { ret {ty: ast_ty_to_ty(self, rscope, mt.ty), mutbl: mt.mutbl}; } - fn instantiate( + fn instantiate( self: AC, rscope: RS, sp: span, id: ast::def_id, path_id: ast::node_id, args: [@ast::ty]) -> ty::t { @@ -478,7 +479,7 @@ fn ast_ty_to_ty( ret ty; } - fn mk_vstore( + fn mk_vstore( self: AC, rscope: RS, a_seq_ty: @ast::ty, vst: ty::vstore) -> ty::t { let tcx = self.tcx(); @@ -819,7 +820,7 @@ fn replace_bound_regions( } } -fn ty_of_arg( +fn ty_of_arg( self: AC, rscope: RS, a: ast::arg) -> ty::arg { fn arg_mode(tcx: ty::ctxt, m: ast::mode, ty: ty::t) -> ast::mode { @@ -849,7 +850,7 @@ fn ty_of_arg( let mode = arg_mode(self.tcx(), a.mode, ty); {mode: mode, ty: ty} } -fn ty_of_fn_decl( +fn ty_of_fn_decl( self: AC, rscope: RS, proto: ast::proto, decl: ast::fn_decl) -> ty::fn_ty {