about summary refs log tree commit diff
path: root/src/rustc
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2012-05-29 15:37:50 -0700
committerNiko Matsakis <niko@alum.mit.edu>2012-05-29 16:22:17 -0700
commitf90228b8a82deb8da178d32322057d7e17245a77 (patch)
treec3121277e2296d1e65d4ca405e376914d51acb7a /src/rustc
parent47375439ed3563f0ba8e37f5d7737011383ecbd0 (diff)
downloadrust-f90228b8a82deb8da178d32322057d7e17245a77.tar.gz
rust-f90228b8a82deb8da178d32322057d7e17245a77.zip
make all arguments modes immutable
note: you can still move from copy/move mode args
Diffstat (limited to 'src/rustc')
-rw-r--r--src/rustc/middle/borrowck.rs11
-rw-r--r--src/rustc/middle/liveness.rs46
2 files changed, 45 insertions, 12 deletions
diff --git a/src/rustc/middle/borrowck.rs b/src/rustc/middle/borrowck.rs
index d6e7ce1b990..71a1e9d2d21 100644
--- a/src/rustc/middle/borrowck.rs
+++ b/src/rustc/middle/borrowck.rs
@@ -843,11 +843,8 @@ impl methods for check_loan_ctxt {
                self.bccx.cmt_to_repr(cmt)];
 
         alt cmt.cat {
-          // Rvalues and locals can be moved:
-          cat_rvalue | cat_local(_) { }
-
-          // Owned arguments can be moved:
-          cat_arg(_) if cmt.mutbl == m_mutbl { }
+          // Rvalues, locals, and arguments can be moved:
+          cat_rvalue | cat_local(_) | cat_arg(_) { }
 
           // We allow moving out of static items because the old code
           // did.  This seems consistent with permitting moves out of
@@ -1348,7 +1345,7 @@ impl categorize_methods for borrowck_ctxt {
                  lp: none}
               }
               ast::by_move | ast::by_copy {
-                {m: m_mutbl,
+                {m: m_imm,
                  lp: some(@lp_arg(vid))}
               }
               ast::by_ref {
@@ -1506,7 +1503,7 @@ impl categorize_methods for borrowck_ctxt {
           cat_special(sk_heap_upvar) { "upvar" }
           cat_rvalue { "non-lvalue" }
           cat_local(_) { mut_str + " local variable" }
-          cat_arg(_) { mut_str + " argument" }
+          cat_arg(_) { "argument" }
           cat_deref(_, _, pk) { #fmt["dereference of %s %s pointer",
                                      mut_str, self.pk_to_sigil(pk)] }
           cat_stack_upvar(_) { mut_str + " upvar" }
diff --git a/src/rustc/middle/liveness.rs b/src/rustc/middle/liveness.rs
index 9b732d08052..3f82e647ab6 100644
--- a/src/rustc/middle/liveness.rs
+++ b/src/rustc/middle/liveness.rs
@@ -1506,10 +1506,7 @@ impl check_methods for @liveness {
             (*self.ir).add_spill(var);
           }
           some(lnk) {
-            self.report_illegal_read(span, lnk, var, moved_variable);
-            self.tcx.sess.span_note(
-                span,
-                "move of variable occurred here");
+            self.report_illegal_move(span, lnk, var);
           }
         }
     }
@@ -1637,6 +1634,44 @@ impl check_methods for @liveness {
         }
     }
 
+    fn report_illegal_move(move_span: span,
+                           lnk: live_node_kind,
+                           var: variable) {
+
+        // the only time that it is possible to have a moved variable
+        // used by lnk_exit would be arguments or fields in a ctor.
+        // we give a slightly different error message in those cases.
+        if lnk == lnk_exit {
+            let vk = self.ir.var_kinds[*var];
+            alt vk {
+              vk_arg(_, name, _) {
+                self.tcx.sess.span_err(
+                    move_span,
+                    #fmt["illegal move from argument `%s`, which is not \
+                          copy or move mode", name]);
+                ret;
+              }
+              vk_field(name) {
+                self.tcx.sess.span_err(
+                    move_span,
+                    #fmt["illegal move from field `%s`", name]);
+                ret;
+              }
+              vk_local(*) | vk_self | vk_implicit_ret {
+                self.tcx.sess.span_bug(
+                    move_span,
+                    #fmt["illegal reader (%?) for `%?`",
+                         lnk, vk]);
+              }
+            }
+        }
+
+        self.report_illegal_read(move_span, lnk, var, moved_variable);
+        self.tcx.sess.span_note(
+            move_span, "move of variable occurred here");
+
+    }
+
     fn report_illegal_read(chk_span: span,
                            lnk: live_node_kind,
                            var: variable,
@@ -1658,7 +1693,8 @@ impl check_methods for @liveness {
                 span,
                 #fmt["use of %s: `%s`", msg, name]);
           }
-          lnk_exit | lnk_vdef(_) {
+          lnk_exit |
+          lnk_vdef(_) {
             self.tcx.sess.span_bug(
                 chk_span,
                 #fmt["illegal reader: %?", lnk]);