@@ -17,6 +17,7 @@ import tritv::ttrue;
17
17
import bitvectors:: * ;
18
18
import syntax:: ast:: * ;
19
19
import syntax:: ast_util:: * ;
20
+ import syntax:: codemap:: span;
20
21
import middle:: ty:: expr_ty;
21
22
import middle:: ty:: type_is_nil;
22
23
import middle:: ty:: type_is_bot;
@@ -31,10 +32,28 @@ import util::common::log_stmt;
31
32
import util:: common:: log_stmt_err;
32
33
import util:: common:: log_expr_err;
33
34
35
+ fn forbid_upvar ( fcx : & fn_ctxt , rhs_id : & node_id , sp : & span ,
36
+ t : oper_type ) {
37
+ alt t {
38
+ oper_move. {
39
+ alt local_node_id_to_def( fcx, rhs_id) {
40
+ some ( def_upvar ( _, _, _) ) {
41
+ fcx. ccx . tcx . sess . span_err ( sp, "Tried to deinitialize a variable \
42
+ declared in a different scope") ;
43
+ }
44
+ _ { }
45
+ }
46
+ }
47
+ _ { /* do nothing */ }
48
+ }
49
+ }
50
+
34
51
fn handle_move_or_copy ( fcx : & fn_ctxt , post : & poststate , rhs_path : & path ,
35
52
rhs_id : & node_id , instlhs : & inst , init_op : & init_op ) {
36
- let rhs_d = local_node_id_to_def_id ( fcx, rhs_id) ;
37
- alt rhs_d {
53
+ forbid_upvar ( fcx, rhs_id, rhs_path. span , op_to_oper_ty ( init_op) ) ;
54
+
55
+ let rhs_d_id = local_node_id_to_def_id ( fcx, rhs_id) ;
56
+ alt rhs_d_id {
38
57
some( rhsid) {
39
58
// RHS is a local var
40
59
let instrhs =
@@ -110,6 +129,7 @@ fn find_pre_post_state_two(fcx: &fn_ctxt, pres: &prestate, lhs: &@expr,
110
129
changed =
111
130
find_pre_post_state_expr ( fcx, expr_poststate ( fcx. ccx , lhs) , rhs) ||
112
131
changed;
132
+ forbid_upvar ( fcx, rhs. id , rhs. span , ty) ;
113
133
114
134
let post = tritv_clone ( expr_poststate ( fcx. ccx , rhs) ) ;
115
135
0 commit comments