about summary refs log tree commit diff
path: root/src/lib
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2011-10-06 12:26:12 +0200
committerMarijn Haverbeke <marijnh@gmail.com>2011-10-07 09:09:50 +0200
commitf9fbd86f52cf597b85359ade1ca60b8d6ebf7286 (patch)
treed6f0cdd039642052f3ccb4ba8f3b9821bb7cbaaf /src/lib
parent4709038d641ad009b44ed2bf5980fa3a252d6927 (diff)
downloadrust-f9fbd86f52cf597b85359ade1ca60b8d6ebf7286.tar.gz
rust-f9fbd86f52cf597b85359ade1ca60b8d6ebf7286.zip
Parse and typecheck by-value and by-ref arg specs
Add sprinkle && throughout the compiler to make it typecheck again.

Issue #1008
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/io.rs13
-rw-r--r--src/lib/list.rs2
-rw-r--r--src/lib/map.rs8
-rw-r--r--src/lib/option.rs5
-rw-r--r--src/lib/vec.rs11
5 files changed, 26 insertions, 13 deletions
diff --git a/src/lib/io.rs b/src/lib/io.rs
index 73460e50588..d8f7f36b24f 100644
--- a/src/lib/io.rs
+++ b/src/lib/io.rs
@@ -175,14 +175,11 @@ fn stdin() -> reader {
 }
 
 fn file_reader(path: str) -> reader {
-    let f =
-        str::as_buf(path,
-                    {|pathbuf|
-                        str::as_buf("r",
-                                    {|modebuf|
-                                        os::libc::fopen(pathbuf, modebuf)
-                                    })
-                    });
+    let f = str::as_buf(path, {|pathbuf|
+        str::as_buf("r", {|modebuf|
+            os::libc::fopen(pathbuf, modebuf)
+        })
+    });
     if f as uint == 0u { log_err "error opening " + path; fail; }
     ret new_reader(FILE_buf_reader(f, option::some(@FILE_res(f))));
 }
diff --git a/src/lib/list.rs b/src/lib/list.rs
index 7037cff365a..58f976110d9 100644
--- a/src/lib/list.rs
+++ b/src/lib/list.rs
@@ -49,7 +49,7 @@ fn has<@T>(ls_: list<T>, elt: T) -> bool {
 }
 
 fn length<@T>(ls: list<T>) -> uint {
-    fn count<T>(_t: T, u: uint) -> uint { ret u + 1u; }
+    fn count<T>(_t: T, &&u: uint) -> uint { ret u + 1u; }
     ret foldl(ls, 0u, count);
 }
 
diff --git a/src/lib/map.rs b/src/lib/map.rs
index 81be20a6620..c63183b1893 100644
--- a/src/lib/map.rs
+++ b/src/lib/map.rs
@@ -199,14 +199,14 @@ fn new_str_hash<@V>() -> hashmap<str, V> {
 }
 
 fn new_int_hash<@V>() -> hashmap<int, V> {
-    fn hash_int(x: int) -> uint { ret x as uint; }
-    fn eq_int(a: int, b: int) -> bool { ret a == b; }
+    fn hash_int(&&x: int) -> uint { ret x as uint; }
+    fn eq_int(&&a: int, &&b: int) -> bool { ret a == b; }
     ret mk_hashmap(hash_int, eq_int);
 }
 
 fn new_uint_hash<@V>() -> hashmap<uint, V> {
-    fn hash_uint(x: uint) -> uint { ret x; }
-    fn eq_uint(a: uint, b: uint) -> bool { ret a == b; }
+    fn hash_uint(&&x: uint) -> uint { ret x; }
+    fn eq_uint(&&a: uint, &&b: uint) -> bool { ret a == b; }
     ret mk_hashmap(hash_uint, eq_uint);
 }
 
diff --git a/src/lib/option.rs b/src/lib/option.rs
index 53c19ba8c0a..56b56b5f69f 100644
--- a/src/lib/option.rs
+++ b/src/lib/option.rs
@@ -9,6 +9,11 @@ fn get<@T>(opt: t<T>) -> &T {
 fn map<@T, @U>(f: block(T) -> U, opt: t<T>) -> t<U> {
     alt opt { some(x) { some(f(x)) } none. { none } }
 }
+// FIXME This is needed to make working with by-value functions a bit less
+// painful. We should come up with a better solution.
+fn map_imm<@T, @U>(f: block(+T) -> U, opt: t<T>) -> t<U> {
+    alt opt { some(x) { some(f(x)) } none. { none } }
+}
 
 fn is_none<@T>(opt: t<T>) -> bool {
     alt opt { none. { true } some(_) { false } }
diff --git a/src/lib/vec.rs b/src/lib/vec.rs
index 59f29d40d7c..bc4334a06bc 100644
--- a/src/lib/vec.rs
+++ b/src/lib/vec.rs
@@ -191,6 +191,17 @@ fn map<@T, @U>(f: block(T) -> U, v: [mutable? T]) -> [U] {
     }
     ret result;
 }
+// FIXME This is needed to make working with by-value functions a bit less
+// painful. We should come up with a better solution.
+fn map_imm<@T, @U>(f: block(+T) -> U, v: [mutable? T]) -> [U] {
+    let result = [];
+    reserve(result, len(v));
+    for elem: T in v {
+        let elem2 = elem; // satisfies alias checker
+        result += [f(elem2)];
+    }
+    ret result;
+}
 
 fn map2<@T, @U, @V>(f: block(T, U) -> V, v0: [T], v1: [U]) -> [V] {
     let v0_len = len::<T>(v0);