about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2010-11-08 15:45:30 -0800
committerGraydon Hoare <graydon@mozilla.com>2010-11-08 15:45:30 -0800
commit3e9be14757bfcaa65e388a9acd7e2ca97cccfbd0 (patch)
tree999975b3f2c277e05cc687618323fc77876016d6 /src
parentc5720b2fc4cff4551a999ff66ed3a12dbd26c6c1 (diff)
downloadrust-3e9be14757bfcaa65e388a9acd7e2ca97cccfbd0.tar.gz
rust-3e9be14757bfcaa65e388a9acd7e2ca97cccfbd0.zip
Add a check for binding an alias. Good thing, as we had two instances in our library.
Diffstat (limited to 'src')
-rw-r--r--src/boot/me/alias.ml26
-rw-r--r--src/lib/bitv.rs2
-rw-r--r--src/lib/deque.rs2
-rw-r--r--src/test/compile-fail/bind-alias.rs7
4 files changed, 35 insertions, 2 deletions
diff --git a/src/boot/me/alias.ml b/src/boot/me/alias.ml
index e109f82b634..77bc769ee53 100644
--- a/src/boot/me/alias.ml
+++ b/src/boot/me/alias.ml
@@ -48,6 +48,29 @@ let alias_analysis_visitor
         | _ -> ()
   in
 
+  let check_no_alias_bindings
+      (fn:Ast.lval)
+      (args:(Ast.atom option) array)
+      : unit =
+    let fty = match lval_ty cx fn with
+        Ast.TY_fn tfn -> tfn
+      | _ -> err (Some (lval_base_id fn)) "binding non-fn"
+    in
+    let arg_slots = (fst fty).Ast.sig_input_slots in
+      Array.iteri
+        begin
+          fun i arg ->
+            match arg with
+                None -> ()
+              | Some _ ->
+                  match arg_slots.(i).Ast.slot_mode with
+                      Ast.MODE_local -> ()
+                    | Ast.MODE_alias ->
+                        err (Some (lval_base_id fn)) "binding alias slot"
+        end
+        args
+  in
+
   let visit_stmt_pre s =
     Stack.push s.id curr_stmt;
     begin
@@ -62,6 +85,9 @@ let alias_analysis_visitor
           | Ast.STMT_spawn (dst, _, _, callee, args)
             -> alias_call_args dst callee args
 
+          | Ast.STMT_bind (_, fn, args) ->
+              check_no_alias_bindings fn args
+
           | Ast.STMT_send (_, src) -> alias src
           | Ast.STMT_recv (dst, _) -> alias dst
           | Ast.STMT_new_port (dst) -> alias dst
diff --git a/src/lib/bitv.rs b/src/lib/bitv.rs
index 2a8c7d0ee53..adb3dc86279 100644
--- a/src/lib/bitv.rs
+++ b/src/lib/bitv.rs
@@ -139,7 +139,7 @@ impure fn set(&t v, uint i, bool x) {
     }
 }
 
-fn init_to_vec(&t v, uint i) -> uint {
+fn init_to_vec(t v, uint i) -> uint {
     if (get(v, i)) {
         ret 1u;
     } else {
diff --git a/src/lib/deque.rs b/src/lib/deque.rs
index 8e3051954e7..4a4aab4e066 100644
--- a/src/lib/deque.rs
+++ b/src/lib/deque.rs
@@ -35,7 +35,7 @@ fn create[T]() -> t[T] {
         check (nelts == _vec.len[cell[T]](elts));
 
         fn fill[T](uint i, uint nelts, uint lo,
-                   &vec[cell[T]] old) -> cell[T] {
+                   vec[cell[T]] old) -> cell[T] {
             if (i < nelts) {
                 ret old.((lo + i) % nelts);
             } else {
diff --git a/src/test/compile-fail/bind-alias.rs b/src/test/compile-fail/bind-alias.rs
new file mode 100644
index 00000000000..b2f53252c69
--- /dev/null
+++ b/src/test/compile-fail/bind-alias.rs
@@ -0,0 +1,7 @@
+// error-pattern: binding alias slot
+
+fn f(&int x) {}
+
+fn main() {
+  bind f(10);
+}