]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #8245 : alexcrichton/rust/fmt2, r=graydon
authorbors <bors@rust-lang.org>
Thu, 8 Aug 2013 07:22:52 +0000 (00:22 -0700)
committerbors <bors@rust-lang.org>
Thu, 8 Aug 2013 07:22:52 +0000 (00:22 -0700)
This is a reopening of #8182, although this removes any abuse of the compiler internals. Now it's just a pure syntax extension (hard coded what the attribute names are).

119 files changed:
Makefile.in
doc/tutorial-tasks.md
doc/tutorial.md
src/compiletest/compiletest.rs
src/compiletest/runtest.rs
src/libextra/arc.rs
src/libextra/base64.rs
src/libextra/dlist.rs
src/libextra/extra.rs
src/libextra/hex.rs [new file with mode: 0644]
src/libextra/iter.rs [deleted file]
src/libextra/num/bigint.rs
src/libextra/ringbuf.rs
src/libextra/smallintmap.rs
src/libextra/stats.rs
src/libextra/sync.rs
src/libextra/term.rs
src/libextra/test.rs
src/libextra/treemap.rs
src/libextra/workcache.rs
src/librust/rust.rs
src/librustc/driver/driver.rs
src/librustc/front/config.rs
src/librustc/lib/llvm.rs
src/librustc/metadata/cstore.rs
src/librustc/metadata/decoder.rs
src/librustc/middle/borrowck/mod.rs
src/librustc/middle/const_eval.rs
src/librustc/middle/lang_items.rs
src/librustc/middle/liveness.rs
src/librustc/middle/region.rs
src/librustc/middle/resolve.rs
src/librustc/middle/trans/base.rs
src/librustc/middle/trans/cabi_mips.rs
src/librustc/middle/trans/common.rs
src/librustc/middle/trans/context.rs
src/librustc/middle/trans/foreign.rs
src/librustc/middle/trans/meth.rs
src/librustc/middle/trans/type_use.rs
src/librustc/middle/ty.rs
src/librustc/middle/typeck/astconv.rs
src/librustc/middle/typeck/check/_match.rs
src/librustc/middle/typeck/check/mod.rs
src/librustc/middle/typeck/check/regionmanip.rs
src/librustc/middle/typeck/check/vtable.rs
src/librustc/middle/typeck/collect.rs
src/librustc/middle/typeck/infer/mod.rs
src/librustc/rustc.rs
src/librustdoc/config.rs
src/librustdoc/markdown_pass.rs
src/librustdoc/tystr_pass.rs
src/librusti/rusti.rs
src/librustpkg/tests.rs
src/libstd/borrow.rs
src/libstd/cmp.rs
src/libstd/hashmap.rs
src/libstd/iterator.rs
src/libstd/local_data.rs
src/libstd/managed.rs
src/libstd/num/num.rs
src/libstd/option.rs
src/libstd/os.rs
src/libstd/owned.rs
src/libstd/prelude.rs
src/libstd/ptr.rs
src/libstd/result.rs
src/libstd/rt/comm.rs
src/libstd/rt/env.rs
src/libstd/rt/kill.rs
src/libstd/rt/local.rs
src/libstd/rt/mod.rs
src/libstd/rt/sched.rs
src/libstd/rt/task.rs
src/libstd/rt/test.rs
src/libstd/str.rs
src/libstd/task/mod.rs
src/libstd/task/spawn.rs
src/libstd/unstable/intrinsics.rs
src/libstd/unstable/lang.rs
src/libstd/vec.rs
src/libsyntax/ast_util.rs
src/libsyntax/attr.rs
src/libsyntax/diagnostic.rs
src/libsyntax/ext/base.rs
src/libsyntax/ext/build.rs
src/libsyntax/ext/deriving/cmp/totalord.rs
src/libsyntax/fold.rs
src/libsyntax/parse/parser.rs
src/libsyntax/parse/token.rs
src/test/bench/core-set.rs
src/test/bench/noise.rs
src/test/bench/shootout-chameneos-redux.rs
src/test/bench/shootout-fannkuch-redux.rs
src/test/bench/shootout-fasta-redux.rs
src/test/bench/shootout-k-nucleotide.rs
src/test/bench/shootout-mandelbrot.rs
src/test/bench/shootout-nbody.rs
src/test/bench/shootout-spectralnorm.rs
src/test/bench/task-perf-alloc-unwind.rs
src/test/bench/task-perf-linked-failure.rs
src/test/debug-info/option-like-enum.rs
src/test/run-fail/extern-fail.rs
src/test/run-fail/linked-failure.rs
src/test/run-fail/linked-failure2.rs
src/test/run-fail/linked-failure3.rs
src/test/run-fail/linked-failure4.rs
src/test/run-fail/spawnfail.rs
src/test/run-fail/task-comm-recv-block.rs
src/test/run-pass/class-impl-parameterized-trait.rs [deleted file]
src/test/run-pass/class-implements-multiple-traits.rs [deleted file]
src/test/run-pass/coerce-reborrow-imm-vec-arg.rs
src/test/run-pass/coerce-reborrow-imm-vec-rcvr.rs
src/test/run-pass/deriving-cmp-shortcircuit.rs [new file with mode: 0644]
src/test/run-pass/issue-3168.rs
src/test/run-pass/lots-a-fail.rs
src/test/run-pass/rcvr-borrowed-to-region.rs
src/test/run-pass/send-iloop.rs
src/test/run-pass/task-killjoin-rsrc.rs
src/test/run-pass/task-killjoin.rs

index d78176e569999ad162b0f03b0f59c0522454f744..a9a41a073d03366291a404187213a417cd608de6 100644 (file)
@@ -297,7 +297,7 @@ COMPILER_INPUTS := $(wildcard $(addprefix $(S)src/librustc/,      \
 
 LIBSYNTAX_CRATE := $(S)src/libsyntax/syntax.rs
 LIBSYNTAX_INPUTS := $(wildcard $(addprefix $(S)src/libsyntax/, \
-                           *.rs */*.rs */*/*.rs))
+                           *.rs */*.rs */*/*.rs */*/*/*.rs))
 
 DRIVER_CRATE := $(S)src/driver/driver.rs
 
index b2ef624d1ac3e6b1c90cb17a3c9dbfecfafe7637..d190c332e6633ade92d1a9ac944aef034caca1db 100644 (file)
@@ -424,7 +424,7 @@ there is no way to "catch" the exception.
 All tasks are, by default, _linked_ to each other. That means that the fates
 of all tasks are intertwined: if one fails, so do all the others.
 
-~~~
+~~~{.xfail-test .linked-failure}
 # use std::task::spawn;
 # use std::task;
 # fn do_some_work() { loop { task::yield() } }
@@ -447,7 +447,7 @@ pattern-match on a result to check whether it's an `Ok` result with an `int`
 field (representing a successful result) or an `Err` result (representing
 termination with an error).
 
-~~~
+~~~{.xfail-test .linked-failure}
 # use std::task;
 # fn some_condition() -> bool { false }
 # fn calculate_result() -> int { 0 }
@@ -490,9 +490,10 @@ proceed). Hence, you will need different _linked failure modes_.
 By default, task failure is _bidirectionally linked_, which means that if
 either task fails, it kills the other one.
 
-~~~
+~~~{.xfail-test .linked-failure}
 # use std::task;
-# fn sleep_forever() { loop { task::yield() } }
+# use std::comm::oneshot;
+# fn sleep_forever() { loop { let (p, c) = oneshot::<()>(); p.recv(); } }
 # do task::try {
 do spawn {
     do spawn {
@@ -511,11 +512,12 @@ function `task::try`, which we saw previously, uses `spawn_supervised`
 internally, with additional logic to wait for the child task to finish
 before returning. Hence:
 
-~~~
+~~~{.xfail-test .linked-failure}
 # use std::comm::{stream, Chan, Port};
+# use std::comm::oneshot;
 # use std::task::{spawn, try};
 # use std::task;
-# fn sleep_forever() { loop { task::yield() } }
+# fn sleep_forever() { loop { let (p, c) = oneshot::<()>(); p.recv(); } }
 # do task::try {
 let (receiver, sender): (Port<int>, Chan<int>) = stream();
 do spawn {  // Bidirectionally linked
@@ -541,10 +543,11 @@ also fail.
 Supervised task failure propagates across multiple generations even if
 an intermediate generation has already exited:
 
-~~~
+~~~{.xfail-test .linked-failure}
 # use std::task;
-# fn sleep_forever() { loop { task::yield() } }
-# fn wait_for_a_while() { do 1000.times { task::yield() } }
+# use std::comm::oneshot;
+# fn sleep_forever() { loop { let (p, c) = oneshot::<()>(); p.recv(); } }
+# fn wait_for_a_while() { for _ in range(0, 1000u) { task::yield() } }
 # do task::try::<int> {
 do task::spawn_supervised {
     do task::spawn_supervised {
@@ -560,10 +563,10 @@ fail!();  // Will kill grandchild even if child has already exited
 Finally, tasks can be configured to not propagate failure to each
 other at all, using `task::spawn_unlinked` for _isolated failure_.
 
-~~~
+~~~{.xfail-test .linked-failure}
 # use std::task;
 # fn random() -> uint { 100 }
-# fn sleep_for(i: uint) { do i.times { task::yield() } }
+# fn sleep_for(i: uint) { for _ in range(0, i) { task::yield() } }
 # do task::try::<()> {
 let (time1, time2) = (random(), random());
 do task::spawn_unlinked {
@@ -588,7 +591,7 @@ that repeatedly receives a `uint` message, converts it to a string, and sends
 the string in response.  The child terminates when it receives `0`.
 Here is the function that implements the child task:
 
-~~~~
+~~~{.xfail-test .linked-failure}
 # use extra::comm::DuplexStream;
 # use std::uint;
 fn stringifier(channel: &DuplexStream<~str, uint>) {
@@ -611,7 +614,7 @@ response itself is simply the stringified version of the received value,
 
 Here is the code for the parent task:
 
-~~~~
+~~~{.xfail-test .linked-failure}
 # use std::task::spawn;
 # use std::uint;
 # use extra::comm::DuplexStream;
index a5f2001eaf515b2f624d101c8860f60f0f0f9f39..6e6b804aa9d3408123dffe40f2a70c5f2a85a702 100644 (file)
@@ -1894,7 +1894,7 @@ struct TimeBomb {
 
 impl Drop for TimeBomb {
     fn drop(&self) {
-        do self.explosivity.times {
+        for _ in range(0, self.explosivity) {
             println("blam!");
         }
     }
index 4e4261e8b2bbda8b8dd19dfc6a3d3704a941dd6d..4262aba9a85946c2f30ee8dc6bdfa4be5dc75d5e 100644 (file)
@@ -109,8 +109,8 @@ fn opt_path(m: &getopts::Matches, nm: &str) -> Path {
         compile_lib_path: getopts::opt_str(matches, "compile-lib-path"),
         run_lib_path: getopts::opt_str(matches, "run-lib-path"),
         rustc_path: opt_path(matches, "rustc-path"),
-        clang_path: getopts::opt_maybe_str(matches, "clang-path").map(|s| Path(*s)),
-        llvm_bin_path: getopts::opt_maybe_str(matches, "llvm-bin-path").map(|s| Path(*s)),
+        clang_path: getopts::opt_maybe_str(matches, "clang-path").map_move(|s| Path(s)),
+        llvm_bin_path: getopts::opt_maybe_str(matches, "llvm-bin-path").map_move(|s| Path(s)),
         src_base: opt_path(matches, "src-base"),
         build_base: opt_path(matches, "build-base"),
         aux_base: opt_path(matches, "aux-base"),
@@ -123,14 +123,14 @@ fn opt_path(m: &getopts::Matches, nm: &str) -> Path {
             } else {
                 None
             },
-        logfile: getopts::opt_maybe_str(matches, "logfile").map(|s| Path(*s)),
-        save_metrics: getopts::opt_maybe_str(matches, "save-metrics").map(|s| Path(*s)),
+        logfile: getopts::opt_maybe_str(matches, "logfile").map_move(|s| Path(s)),
+        save_metrics: getopts::opt_maybe_str(matches, "save-metrics").map_move(|s| Path(s)),
         ratchet_metrics:
-            getopts::opt_maybe_str(matches, "ratchet-metrics").map(|s| Path(*s)),
+            getopts::opt_maybe_str(matches, "ratchet-metrics").map_move(|s| Path(s)),
         ratchet_noise_percent:
             getopts::opt_maybe_str(matches,
-                                   "ratchet-noise-percent").map(|s|
-                                                                f64::from_str(*s).unwrap()),
+                                   "ratchet-noise-percent").map_move(|s|
+                                                                     f64::from_str(s).unwrap()),
         runtool: getopts::opt_maybe_str(matches, "runtool"),
         rustcflags: getopts::opt_maybe_str(matches, "rustcflags"),
         jit: getopts::opt_present(matches, "jit"),
index 5c1cc78d678f361f1525226fbcb8e1bf7f807f34..0d1c5c8eb43516c738c7df112f9c0fe5f48694c9 100644 (file)
@@ -162,9 +162,8 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
         round += 1;
     }
 
-    let mut expected =
-        match props.pp_exact {
-          Some(ref file) => {
+    let mut expected = match props.pp_exact {
+        Some(ref file) => {
             let filepath = testfile.dir_path().push_rel(file);
             io::read_whole_file_str(&filepath).unwrap()
           }
index cb4468f48ecb1473b65c3805ff15e22a2581c69f..17f4cbbd1527e04fe1bf48efdf51cf7dbf571693 100644 (file)
@@ -611,6 +611,7 @@ fn test_mutex_arc_condvar() {
             }
         }
     }
+
     #[test] #[should_fail] #[ignore(cfg(windows))]
     fn test_arc_condvar_poison() {
         unsafe {
index 550b891a4db16c22356d20be362f55ca7b06e6cb..b4431004bd74cff0dd38693c5093d4b590c479be 100644 (file)
@@ -9,6 +9,7 @@
 // except according to those terms.
 
 //! Base64 binary-to-text encoding
+use std::str;
 
 /// Available encoding character sets
 pub enum CharacterSet {
@@ -40,21 +41,13 @@ pub struct Config {
 pub static MIME: Config =
     Config {char_set: Standard, pad: true, line_length: Some(76)};
 
-static STANDARD_CHARS: [char, ..64] = [
-    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
-    'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
-    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
-    'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
-    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
-];
-
-static URLSAFE_CHARS: [char, ..64] = [
-    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
-    'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
-    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
-    'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
-    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_'
-];
+static STANDARD_CHARS: &'static[u8] = bytes!("ABCDEFGHIJKLMNOPQRSTUVWXYZ",
+                                             "abcdefghijklmnopqrstuvwxyz",
+                                             "0123456789+/");
+
+static URLSAFE_CHARS: &'static[u8] = bytes!("ABCDEFGHIJKLMNOPQRSTUVWXYZ",
+                                            "abcdefghijklmnopqrstuvwxyz",
+                                            "0123456789-_");
 
 /// A trait for converting a value to base64 encoding.
 pub trait ToBase64 {
@@ -80,12 +73,12 @@ impl<'self> ToBase64 for &'self [u8] {
      * ~~~
      */
     fn to_base64(&self, config: Config) -> ~str {
-        let chars = match config.char_set {
+        let bytes = match config.char_set {
             Standard => STANDARD_CHARS,
             UrlSafe => URLSAFE_CHARS
         };
 
-        let mut s = ~"";
+        let mut v: ~[u8] = ~[];
         let mut i = 0;
         let mut cur_length = 0;
         let len = self.len();
@@ -93,7 +86,8 @@ fn to_base64(&self, config: Config) -> ~str {
             match config.line_length {
                 Some(line_length) =>
                     if cur_length >= line_length {
-                        s.push_str("\r\n");
+                        v.push('\r' as u8);
+                        v.push('\n' as u8);
                         cur_length = 0;
                     },
                 None => ()
@@ -104,10 +98,10 @@ fn to_base64(&self, config: Config) -> ~str {
                     (self[i + 2] as u32);
 
             // This 24-bit number gets separated into four 6-bit numbers.
-            s.push_char(chars[(n >> 18) & 63]);
-            s.push_char(chars[(n >> 12) & 63]);
-            s.push_char(chars[(n >> 6 ) & 63]);
-            s.push_char(chars[n & 63]);
+            v.push(bytes[(n >> 18) & 63]);
+            v.push(bytes[(n >> 12) & 63]);
+            v.push(bytes[(n >> 6 ) & 63]);
+            v.push(bytes[n & 63]);
 
             cur_length += 4;
             i += 3;
@@ -117,7 +111,8 @@ fn to_base64(&self, config: Config) -> ~str {
             match config.line_length {
                 Some(line_length) =>
                     if cur_length >= line_length {
-                        s.push_str("\r\n");
+                        v.push('\r' as u8);
+                        v.push('\n' as u8);
                     },
                 None => ()
             }
@@ -129,48 +124,29 @@ fn to_base64(&self, config: Config) -> ~str {
             0 => (),
             1 => {
                 let n = (self[i] as u32) << 16;
-                s.push_char(chars[(n >> 18) & 63]);
-                s.push_char(chars[(n >> 12) & 63]);
+                v.push(bytes[(n >> 18) & 63]);
+                v.push(bytes[(n >> 12) & 63]);
                 if config.pad {
-                    s.push_str("==");
+                    v.push('=' as u8);
+                    v.push('=' as u8);
                 }
             }
             2 => {
                 let n = (self[i] as u32) << 16 |
                     (self[i + 1u] as u32) << 8;
-                s.push_char(chars[(n >> 18) & 63]);
-                s.push_char(chars[(n >> 12) & 63]);
-                s.push_char(chars[(n >> 6 ) & 63]);
+                v.push(bytes[(n >> 18) & 63]);
+                v.push(bytes[(n >> 12) & 63]);
+                v.push(bytes[(n >> 6 ) & 63]);
                 if config.pad {
-                    s.push_char('=');
+                    v.push('=' as u8);
                 }
             }
             _ => fail!("Algebra is broken, please alert the math police")
         }
-        s
-    }
-}
 
-impl<'self> ToBase64 for &'self str {
-    /**
-     * Convert any string (literal, `@`, `&`, or `~`) to base64 encoding.
-     *
-     *
-     * # Example
-     *
-     * ~~~ {.rust}
-     * extern mod extra;
-     * use extra::base64::{ToBase64, standard};
-     *
-     * fn main () {
-     *     let str = "Hello, World".to_base64(standard);
-     *     printfln!("%s", str);
-     * }
-     * ~~~
-     *
-     */
-    fn to_base64(&self, config: Config) -> ~str {
-        self.as_bytes().to_base64(config)
+        unsafe {
+            str::raw::from_bytes_owned(v)
+        }
     }
 }
 
@@ -181,22 +157,31 @@ pub trait FromBase64 {
     fn from_base64(&self) -> Result<~[u8], ~str>;
 }
 
-impl<'self> FromBase64 for &'self [u8] {
+impl<'self> FromBase64 for &'self str {
     /**
-     * Convert base64 `u8` vector into u8 byte values.
-     * Every 4 encoded characters is converted into 3 octets, modulo padding.
+     * Convert any base64 encoded string (literal, `@`, `&`, or `~`)
+     * to the byte values it encodes.
+     *
+     * You can use the `from_bytes` function in `std::str`
+     * to turn a `[u8]` into a string with characters corresponding to those
+     * values.
      *
      * # Example
      *
+     * This converts a string literal to base64 and back.
+     *
      * ~~~ {.rust}
      * extern mod extra;
      * use extra::base64::{ToBase64, FromBase64, standard};
+     * use std::str;
      *
      * fn main () {
-     *     let str = [52,32].to_base64(standard);
-     *     printfln!("%s", str);
-     *     let bytes = str.from_base64();
+     *     let hello_str = "Hello, World".to_base64(standard);
+     *     printfln!("%s", hello_str);
+     *     let bytes = hello_str.from_base64();
      *     printfln!("%?", bytes);
+     *     let result_str = str::from_bytes(bytes);
+     *     printfln!("%s", result_str);
      * }
      * ~~~
      */
@@ -205,12 +190,11 @@ fn from_base64(&self) -> Result<~[u8], ~str> {
         let mut buf: u32 = 0;
         let mut modulus = 0;
 
-        let mut it = self.iter();
-        for &byte in it {
-            let ch = byte as char;
+        let mut it = self.byte_iter().enumerate();
+        for (idx, byte) in it {
             let val = byte as u32;
 
-            match ch {
+            match byte as char {
                 'A'..'Z' => buf |= val - 0x41,
                 'a'..'z' => buf |= val - 0x47,
                 '0'..'9' => buf |= val + 0x04,
@@ -218,7 +202,8 @@ fn from_base64(&self) -> Result<~[u8], ~str> {
                 '/'|'_' => buf |= 0x3F,
                 '\r'|'\n' => loop,
                 '=' => break,
-                _ => return Err(~"Invalid Base64 character")
+                _ => return Err(fmt!("Invalid character '%c' at position %u",
+                                     self.char_at(idx), idx))
             }
 
             buf <<= 6;
@@ -231,8 +216,11 @@ fn from_base64(&self) -> Result<~[u8], ~str> {
             }
         }
 
-        if !it.all(|&byte| {byte as char == '='}) {
-            return Err(~"Invalid Base64 character");
+        for (idx, byte) in it {
+            if (byte as char) != '=' {
+                return Err(fmt!("Invalid character '%c' at position %u",
+                                self.char_at(idx), idx));
+            }
         }
 
         match modulus {
@@ -251,39 +239,6 @@ fn from_base64(&self) -> Result<~[u8], ~str> {
     }
 }
 
-impl<'self> FromBase64 for &'self str {
-    /**
-     * Convert any base64 encoded string (literal, `@`, `&`, or `~`)
-     * to the byte values it encodes.
-     *
-     * You can use the `from_bytes` function in `std::str`
-     * to turn a `[u8]` into a string with characters corresponding to those
-     * values.
-     *
-     * # Example
-     *
-     * This converts a string literal to base64 and back.
-     *
-     * ~~~ {.rust}
-     * extern mod extra;
-     * use extra::base64::{ToBase64, FromBase64, standard};
-     * use std::str;
-     *
-     * fn main () {
-     *     let hello_str = "Hello, World".to_base64(standard);
-     *     printfln!("%s", hello_str);
-     *     let bytes = hello_str.from_base64();
-     *     printfln!("%?", bytes);
-     *     let result_str = str::from_bytes(bytes);
-     *     printfln!("%s", result_str);
-     * }
-     * ~~~
-     */
-    fn from_base64(&self) -> Result<~[u8], ~str> {
-        self.as_bytes().from_base64()
-    }
-}
-
 #[cfg(test)]
 mod test {
     use test::BenchHarness;
@@ -291,27 +246,28 @@ mod test {
 
     #[test]
     fn test_to_base64_basic() {
-        assert_eq!("".to_base64(STANDARD), ~"");
-        assert_eq!("f".to_base64(STANDARD), ~"Zg==");
-        assert_eq!("fo".to_base64(STANDARD), ~"Zm8=");
-        assert_eq!("foo".to_base64(STANDARD), ~"Zm9v");
-        assert_eq!("foob".to_base64(STANDARD), ~"Zm9vYg==");
-        assert_eq!("fooba".to_base64(STANDARD), ~"Zm9vYmE=");
-        assert_eq!("foobar".to_base64(STANDARD), ~"Zm9vYmFy");
+        assert_eq!("".as_bytes().to_base64(STANDARD), ~"");
+        assert_eq!("f".as_bytes().to_base64(STANDARD), ~"Zg==");
+        assert_eq!("fo".as_bytes().to_base64(STANDARD), ~"Zm8=");
+        assert_eq!("foo".as_bytes().to_base64(STANDARD), ~"Zm9v");
+        assert_eq!("foob".as_bytes().to_base64(STANDARD), ~"Zm9vYg==");
+        assert_eq!("fooba".as_bytes().to_base64(STANDARD), ~"Zm9vYmE=");
+        assert_eq!("foobar".as_bytes().to_base64(STANDARD), ~"Zm9vYmFy");
     }
 
     #[test]
     fn test_to_base64_line_break() {
         assert!(![0u8, 1000].to_base64(Config {line_length: None, ..STANDARD})
                 .contains("\r\n"));
-        assert_eq!("foobar".to_base64(Config {line_length: Some(4), ..STANDARD}),
+        assert_eq!("foobar".as_bytes().to_base64(Config {line_length: Some(4),
+                                                         ..STANDARD}),
                    ~"Zm9v\r\nYmFy");
     }
 
     #[test]
     fn test_to_base64_padding() {
-        assert_eq!("f".to_base64(Config {pad: false, ..STANDARD}), ~"Zg");
-        assert_eq!("fo".to_base64(Config {pad: false, ..STANDARD}), ~"Zm8");
+        assert_eq!("f".as_bytes().to_base64(Config {pad: false, ..STANDARD}), ~"Zg");
+        assert_eq!("fo".as_bytes().to_base64(Config {pad: false, ..STANDARD}), ~"Zm8");
     }
 
     #[test]
@@ -345,7 +301,7 @@ fn test_from_base64_urlsafe() {
     #[test]
     fn test_from_base64_invalid_char() {
         assert!("Zm$=".from_base64().is_err())
-            assert!("Zg==$".from_base64().is_err());
+        assert!("Zg==$".from_base64().is_err());
     }
 
     #[test]
@@ -369,20 +325,20 @@ fn test_base64_random() {
     }
 
     #[bench]
-    pub fn to_base64(bh: & mut BenchHarness) {
+    pub fn bench_to_base64(bh: & mut BenchHarness) {
         let s = "イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム \
                  ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン";
         do bh.iter {
-            s.to_base64(STANDARD);
+            s.as_bytes().to_base64(STANDARD);
         }
         bh.bytes = s.len() as u64;
     }
 
     #[bench]
-    pub fn from_base64(bh: & mut BenchHarness) {
+    pub fn bench_from_base64(bh: & mut BenchHarness) {
         let s = "イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム \
                  ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン";
-        let b = s.to_base64(STANDARD);
+        let b = s.as_bytes().to_base64(STANDARD);
         do bh.iter {
             b.from_base64();
         }
index 75487a44f2600253e4d50091eaccc1517c299e06..b0839a55795b760ccf0efdaba987c0d9edf6df35 100644 (file)
@@ -164,7 +164,7 @@ fn push_front_node(&mut self, mut new_head: ~Node<T>) {
     /// Remove the first Node and return it, or None if the list is empty
     #[inline]
     fn pop_front_node(&mut self) -> Option<~Node<T>> {
-        do self.list_head.take().map_consume |mut front_node| {
+        do self.list_head.take().map_move |mut front_node| {
             self.length -= 1;
             match front_node.next.take() {
                 Some(node) => self.list_head = link_with_prev(node, Rawlink::none()),
@@ -190,7 +190,7 @@ fn push_back_node(&mut self, mut new_tail: ~Node<T>) {
     /// Remove the last Node and return it, or None if the list is empty
     #[inline]
     fn pop_back_node(&mut self) -> Option<~Node<T>> {
-        do self.list_tail.resolve().map_consume_default(None) |tail| {
+        do self.list_tail.resolve().map_move_default(None) |tail| {
             self.length -= 1;
             self.list_tail = tail.prev;
             match tail.prev.resolve() {
@@ -237,7 +237,7 @@ fn push_front(&mut self, elt: T) {
     ///
     /// O(1)
     fn pop_front(&mut self) -> Option<T> {
-        self.pop_front_node().map_consume(|~Node{value, _}| value)
+        self.pop_front_node().map_move(|~Node{value, _}| value)
     }
 
     /// Add an element last in the list
@@ -251,7 +251,7 @@ fn push_back(&mut self, elt: T) {
     ///
     /// O(1)
     fn pop_back(&mut self) -> Option<T> {
-        self.pop_back_node().map_consume(|~Node{value, _}| value)
+        self.pop_back_node().map_move(|~Node{value, _}| value)
     }
 }
 
@@ -267,7 +267,7 @@ pub fn new() -> DList<T> {
     /// If the list is empty, do nothing.
     #[inline]
     pub fn rotate_forward(&mut self) {
-        do self.pop_back_node().map_consume |tail| {
+        do self.pop_back_node().map_move |tail| {
             self.push_front_node(tail)
         };
     }
@@ -277,7 +277,7 @@ pub fn rotate_forward(&mut self) {
     /// If the list is empty, do nothing.
     #[inline]
     pub fn rotate_backward(&mut self) {
-        do self.pop_front_node().map_consume |head| {
+        do self.pop_front_node().map_move |head| {
             self.push_back_node(head)
         };
     }
@@ -463,7 +463,7 @@ fn next_back(&mut self) -> Option<&'self A> {
         if self.nelem == 0 {
             return None;
         }
-        do self.tail.resolve().map_consume |prev| {
+        do self.tail.resolve().map_move |prev| {
             self.nelem -= 1;
             self.tail = prev.prev;
             &prev.value
@@ -477,7 +477,7 @@ fn next(&mut self) -> Option<&'self mut A> {
         if self.nelem == 0 {
             return None;
         }
-        do self.head.resolve().map_consume |next| {
+        do self.head.resolve().map_move |next| {
             self.nelem -= 1;
             self.head = match next.next {
                 Some(ref mut node) => Rawlink::some(&mut **node),
@@ -499,7 +499,7 @@ fn next_back(&mut self) -> Option<&'self mut A> {
         if self.nelem == 0 {
             return None;
         }
-        do self.tail.resolve().map_consume |prev| {
+        do self.tail.resolve().map_move |prev| {
             self.nelem -= 1;
             self.tail = prev.prev;
             &mut prev.value
@@ -553,7 +553,7 @@ fn peek_next<'a>(&'a mut self) -> Option<&'a mut A> {
         if self.nelem == 0 {
             return None
         }
-        self.head.resolve().map_consume(|head| &mut head.value)
+        self.head.resolve().map_move(|head| &mut head.value)
     }
 }
 
index 58929778a59e20f6afb11105979894b771755207..44781a1fd19b632f0794802ae3d9ee8cbae167ce 100644 (file)
 pub mod semver;
 pub mod fileinput;
 pub mod flate;
+pub mod hex;
 
 #[cfg(unicode)]
 mod unicode;
diff --git a/src/libextra/hex.rs b/src/libextra/hex.rs
new file mode 100644 (file)
index 0000000..d5345cb
--- /dev/null
@@ -0,0 +1,193 @@
+// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Hex binary-to-text encoding
+use std::str;
+use std::vec;
+
+/// A trait for converting a value to hexadecimal encoding
+pub trait ToHex {
+    /// Converts the value of `self` to a hex value, returning the owned
+    /// string.
+    fn to_hex(&self) -> ~str;
+}
+
+static CHARS: &'static[u8] = bytes!("0123456789abcdef");
+
+impl<'self> ToHex for &'self [u8] {
+    /**
+     * Turn a vector of `u8` bytes into a hexadecimal string.
+     *
+     * # Example
+     *
+     * ~~~ {.rust}
+     * extern mod extra;
+     * use extra::hex::ToHex;
+     *
+     * fn main () {
+     *     let str = [52,32].to_hex();
+     *     printfln!("%s", str);
+     * }
+     * ~~~
+     */
+    fn to_hex(&self) -> ~str {
+        let mut v = vec::with_capacity(self.len() * 2);
+        for &byte in self.iter() {
+            v.push(CHARS[byte >> 4]);
+            v.push(CHARS[byte & 0xf]);
+        }
+
+        unsafe {
+            str::raw::from_bytes_owned(v)
+        }
+    }
+}
+
+/// A trait for converting hexadecimal encoded values
+pub trait FromHex {
+    /// Converts the value of `self`, interpreted as hexadecimal encoded data,
+    /// into an owned vector of bytes, returning the vector.
+    fn from_hex(&self) -> Result<~[u8], ~str>;
+}
+
+impl<'self> FromHex for &'self str {
+    /**
+     * Convert any hexadecimal encoded string (literal, `@`, `&`, or `~`)
+     * to the byte values it encodes.
+     *
+     * You can use the `from_bytes` function in `std::str`
+     * to turn a `[u8]` into a string with characters corresponding to those
+     * values.
+     *
+     * # Example
+     *
+     * This converts a string literal to hexadecimal and back.
+     *
+     * ~~~ {.rust}
+     * extern mod extra;
+     * use extra::hex::{FromHex, ToHex};
+     * use std::str;
+     *
+     * fn main () {
+     *     let hello_str = "Hello, World".to_hex();
+     *     printfln!("%s", hello_str);
+     *     let bytes = hello_str.from_hex().unwrap();
+     *     printfln!("%?", bytes);
+     *     let result_str = str::from_bytes(bytes);
+     *     printfln!("%s", result_str);
+     * }
+     * ~~~
+     */
+    fn from_hex(&self) -> Result<~[u8], ~str> {
+        // This may be an overestimate if there is any whitespace
+        let mut b = vec::with_capacity(self.len() / 2);
+        let mut modulus = 0;
+        let mut buf = 0u8;
+
+        for (idx, byte) in self.byte_iter().enumerate() {
+            buf <<= 4;
+
+            match byte as char {
+                'A'..'F' => buf |= byte - ('A' as u8) + 10,
+                'a'..'f' => buf |= byte - ('a' as u8) + 10,
+                '0'..'9' => buf |= byte - ('0' as u8),
+                ' '|'\r'|'\n'|'\t' => {
+                    buf >>= 4;
+                    loop
+                }
+                _ => return Err(fmt!("Invalid character '%c' at position %u",
+                                     self.char_at(idx), idx))
+            }
+
+            modulus += 1;
+            if modulus == 2 {
+                modulus = 0;
+                b.push(buf);
+            }
+        }
+
+        match modulus {
+            0 => Ok(b),
+            _ => Err(~"Invalid input length")
+        }
+    }
+}
+
+#[cfg(test)]
+mod tests {
+    use test::BenchHarness;
+    use hex::*;
+
+    #[test]
+    pub fn test_to_hex() {
+        assert_eq!("foobar".as_bytes().to_hex(), ~"666f6f626172");
+    }
+
+    #[test]
+    pub fn test_from_hex_okay() {
+        assert_eq!("666f6f626172".from_hex().unwrap(),
+                   "foobar".as_bytes().to_owned());
+        assert_eq!("666F6F626172".from_hex().unwrap(),
+                   "foobar".as_bytes().to_owned());
+    }
+
+    #[test]
+    pub fn test_from_hex_odd_len() {
+        assert!("666".from_hex().is_err());
+        assert!("66 6".from_hex().is_err());
+    }
+
+    #[test]
+    pub fn test_from_hex_invalid_char() {
+        assert!("66y6".from_hex().is_err());
+    }
+
+    #[test]
+    pub fn test_from_hex_ignores_whitespace() {
+        assert_eq!("666f 6f6\r\n26172 ".from_hex().unwrap(),
+                   "foobar".as_bytes().to_owned());
+    }
+
+    #[test]
+    pub fn test_to_hex_all_bytes() {
+        for i in range(0, 256) {
+            assert_eq!([i as u8].to_hex(), fmt!("%02x", i as uint));
+        }
+    }
+
+    #[test]
+    pub fn test_from_hex_all_bytes() {
+        for i in range(0, 256) {
+            assert_eq!(fmt!("%02x", i as uint).from_hex().unwrap(), ~[i as u8]);
+            assert_eq!(fmt!("%02X", i as uint).from_hex().unwrap(), ~[i as u8]);
+        }
+    }
+
+    #[bench]
+    pub fn bench_to_hex(bh: & mut BenchHarness) {
+        let s = "イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム \
+                 ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン";
+        do bh.iter {
+            s.as_bytes().to_hex();
+        }
+        bh.bytes = s.len() as u64;
+    }
+
+    #[bench]
+    pub fn bench_from_hex(bh: & mut BenchHarness) {
+        let s = "イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム \
+                 ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン";
+        let b = s.as_bytes().to_hex();
+        do bh.iter {
+            b.from_hex();
+        }
+        bh.bytes = b.len() as u64;
+    }
+}
diff --git a/src/libextra/iter.rs b/src/libextra/iter.rs
deleted file mode 100644 (file)
index 7fd47fd..0000000
+++ /dev/null
@@ -1,331 +0,0 @@
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-/*! Composable internal iterators
-
-Internal iterators are functions implementing the protocol used by the `for` loop.
-
-An internal iterator takes `fn(...) -> bool` as a parameter, with returning `false` used to signal
-breaking out of iteration. The adaptors in the module work with any such iterator, not just ones
-tied to specific traits. For example:
-
-~~~ {.rust}
-println(iter::to_vec(|f| uint::range(0, 20, f)).to_str());
-~~~
-
-An external iterator object implementing the interface in the `iterator` module can be used as an
-internal iterator by calling the `advance` method. For example:
-
-~~~ {.rust}
-let xs = [0u, 1, 2, 3, 4, 5];
-let ys = [30, 40, 50, 60];
-let mut it = xs.iter().chain(ys.iter());
-for &x: &uint in it {
-    println(x.to_str());
-}
-~~~
-
-Internal iterators provide a subset of the functionality of an external iterator. It's not possible
-to interleave them to implement algorithms like `zip`, `union` and `merge`. However, they're often
-much easier to implement.
-
-*/
-
-use std::vec;
-use std::cmp::Ord;
-use std::option::{Option, Some, None};
-use std::num::{One, Zero};
-use std::ops::{Add, Mul};
-
-#[allow(missing_doc)]
-pub trait FromIter<T> {
-    /// Build a container with elements from an internal iterator.
-    ///
-    /// # Example:
-    ///
-    /// ~~~ {.rust}
-    /// let xs = ~[1, 2, 3];
-    /// let ys: ~[int] = do FromIter::from_iter |f| { xs.iter().advance(|x| f(*x)) };
-    /// assert_eq!(xs, ys);
-    /// ~~~
-    pub fn from_iter(iter: &fn(f: &fn(T) -> bool) -> bool) -> Self;
-}
-
-/**
- * Return true if `predicate` is true for any values yielded by an internal iterator.
- *
- * Example:
- *
- * ~~~ {.rust}
- * let xs = ~[1u, 2, 3, 4, 5];
- * assert!(any(|&x: &uint| x > 2, |f| xs.iter().advance(f)));
- * assert!(!any(|&x: &uint| x > 5, |f| xs.iter().advance(f)));
- * ~~~
- */
-#[inline]
-pub fn any<T>(predicate: &fn(T) -> bool,
-              iter: &fn(f: &fn(T) -> bool) -> bool) -> bool {
-    do iter |x| {
-        predicate(x)
-    }
-}
-
-/**
- * Return true if `predicate` is true for all values yielded by an internal iterator.
- *
- * # Example:
- *
- * ~~~ {.rust}
- * assert!(all(|&x: &uint| x < 6, |f| uint::range(1, 6, f)));
- * assert!(!all(|&x: &uint| x < 5, |f| uint::range(1, 6, f)));
- * ~~~
- */
-#[inline]
-pub fn all<T>(predicate: &fn(T) -> bool,
-              iter: &fn(f: &fn(T) -> bool) -> bool) -> bool {
-    // If we ever break, iter will return false, so this will only return true
-    // if predicate returns true for everything.
-    iter(|x| predicate(x))
-}
-
-/**
- * Return the first element where `predicate` returns `true`. Return `None` if no element is found.
- *
- * # Example:
- *
- * ~~~ {.rust}
- * let xs = ~[1u, 2, 3, 4, 5, 6];
- * assert_eq!(*find(|& &x: & &uint| x > 3, |f| xs.iter().advance(f)).unwrap(), 4);
- * ~~~
- */
-#[inline]
-pub fn find<T>(predicate: &fn(&T) -> bool,
-               iter: &fn(f: &fn(T) -> bool) -> bool) -> Option<T> {
-    let mut ret = None;
-    do iter |x| {
-        if predicate(&x) {
-            ret = Some(x);
-            false
-        } else { true }
-    };
-    ret
-}
-
-/**
- * Return the largest item yielded by an iterator. Return `None` if the iterator is empty.
- *
- * # Example:
- *
- * ~~~ {.rust}
- * let xs = ~[8, 2, 3, 1, -5, 9, 11, 15];
- * assert_eq!(max(|f| xs.iter().advance(f)).unwrap(), &15);
- * ~~~
- */
-#[inline]
-pub fn max<T: Ord>(iter: &fn(f: &fn(T) -> bool) -> bool) -> Option<T> {
-    let mut result = None;
-    do iter |x| {
-        match result {
-            Some(ref mut y) => {
-                if x > *y {
-                    *y = x;
-                }
-            }
-            None => result = Some(x)
-        }
-        true
-    };
-    result
-}
-
-/**
- * Return the smallest item yielded by an iterator. Return `None` if the iterator is empty.
- *
- * # Example:
- *
- * ~~~ {.rust}
- * let xs = ~[8, 2, 3, 1, -5, 9, 11, 15];
- * assert_eq!(max(|f| xs.iter().advance(f)).unwrap(), &-5);
- * ~~~
- */
-#[inline]
-pub fn min<T: Ord>(iter: &fn(f: &fn(T) -> bool) -> bool) -> Option<T> {
-    let mut result = None;
-    do iter |x| {
-        match result {
-            Some(ref mut y) => {
-                if x < *y {
-                    *y = x;
-                }
-            }
-            None => result = Some(x)
-        }
-        true
-    };
-    result
-}
-
-/**
- * Reduce an iterator to an accumulated value.
- *
- * # Example:
- *
- * ~~~ {.rust}
- * assert_eq!(fold(0i, |f| int::range(1, 5, f), |a, x| *a += x), 10);
- * ~~~
- */
-#[inline]
-pub fn fold<T, U>(start: T, iter: &fn(f: &fn(U) -> bool) -> bool, f: &fn(&mut T, U)) -> T {
-    let mut result = start;
-    do iter |x| {
-        f(&mut result, x);
-        true
-    };
-    result
-}
-
-/**
- * Reduce an iterator to an accumulated value.
- *
- * `fold_ref` is usable in some generic functions where `fold` is too lenient to type-check, but it
- * forces the iterator to yield borrowed pointers.
- *
- * # Example:
- *
- * ~~~ {.rust}
- * fn product<T: One + Mul<T, T>>(iter: &fn(f: &fn(&T) -> bool) -> bool) -> T {
- *     fold_ref(One::one::<T>(), iter, |a, x| *a = a.mul(x))
- * }
- * ~~~
- */
-#[inline]
-pub fn fold_ref<T, U>(start: T, iter: &fn(f: &fn(&U) -> bool) -> bool, f: &fn(&mut T, &U)) -> T {
-    let mut result = start;
-    do iter |x| {
-        f(&mut result, x);
-        true
-    };
-    result
-}
-
-/**
- * Return the sum of the items yielding by an iterator.
- *
- * # Example:
- *
- * ~~~ {.rust}
- * let xs: ~[int] = ~[1, 2, 3, 4];
- * assert_eq!(do sum |f| { xs.iter().advance(f) }, 10);
- * ~~~
- */
-#[inline]
-pub fn sum<T: Zero + Add<T, T>>(iter: &fn(f: &fn(&T) -> bool) -> bool) -> T {
-    fold_ref(Zero::zero::<T>(), iter, |a, x| *a = a.add(x))
-}
-
-/**
- * Return the product of the items yielded by an iterator.
- *
- * # Example:
- *
- * ~~~ {.rust}
- * let xs: ~[int] = ~[1, 2, 3, 4];
- * assert_eq!(do product |f| { xs.iter().advance(f) }, 24);
- * ~~~
- */
-#[inline]
-pub fn product<T: One + Mul<T, T>>(iter: &fn(f: &fn(&T) -> bool) -> bool) -> T {
-    fold_ref(One::one::<T>(), iter, |a, x| *a = a.mul(x))
-}
-
-impl<T> FromIter<T> for ~[T]{
-    #[inline]
-    pub fn from_iter(iter: &fn(f: &fn(T) -> bool) -> bool) -> ~[T] {
-        let mut v = ~[];
-        do iter |x| { v.push(x); true };
-        v
-    }
-}
-
-#[cfg(test)]
-mod tests {
-    use super::*;
-    use prelude::*;
-
-    use int;
-    use uint;
-
-    #[test]
-    fn test_from_iter() {
-        let xs = ~[1, 2, 3];
-        let ys: ~[int] = do FromIter::from_iter |f| { xs.iter().advance(|x| f(*x)) };
-        assert_eq!(xs, ys);
-    }
-
-    #[test]
-    fn test_any() {
-        let xs = ~[1u, 2, 3, 4, 5];
-        assert!(any(|&x: &uint| x > 2, |f| xs.iter().advance(f)));
-        assert!(!any(|&x: &uint| x > 5, |f| xs.iter().advance(f)));
-    }
-
-    #[test]
-    fn test_all() {
-        assert!(all(|x: uint| x < 6, |f| uint::range(1, 6, f)));
-        assert!(!all(|x: uint| x < 5, |f| uint::range(1, 6, f)));
-    }
-
-    #[test]
-    fn test_find() {
-        let xs = ~[1u, 2, 3, 4, 5, 6];
-        assert_eq!(*find(|& &x: & &uint| x > 3, |f| xs.iter().advance(f)).unwrap(), 4);
-    }
-
-    #[test]
-    fn test_max() {
-        let xs = ~[8, 2, 3, 1, -5, 9, 11, 15];
-        assert_eq!(max(|f| xs.iter().advance(f)).unwrap(), &15);
-    }
-
-    #[test]
-    fn test_min() {
-        let xs = ~[8, 2, 3, 1, -5, 9, 11, 15];
-        assert_eq!(min(|f| xs.iter().advance(f)).unwrap(), &-5);
-    }
-
-    #[test]
-    fn test_fold() {
-        assert_eq!(fold(0i, |f| int::range(1, 5, f), |a, x| *a += x), 10);
-    }
-
-    #[test]
-    fn test_sum() {
-        let xs: ~[int] = ~[1, 2, 3, 4];
-        assert_eq!(do sum |f| { xs.iter().advance(f) }, 10);
-    }
-
-    #[test]
-    fn test_empty_sum() {
-        let xs: ~[int] = ~[];
-        assert_eq!(do sum |f| { xs.iter().advance(f) }, 0);
-    }
-
-    #[test]
-    fn test_product() {
-        let xs: ~[int] = ~[1, 2, 3, 4];
-        assert_eq!(do product |f| { xs.iter().advance(f) }, 24);
-    }
-
-    #[test]
-    fn test_empty_product() {
-        let xs: ~[int] = ~[];
-        assert_eq!(do product |f| { xs.iter().advance(f) }, 1);
-    }
-}
index bced00902c95f5abdcc62dee20adb3b42f14d372..c3737d44e385ff8f5686345b0027686e51f24d05 100644 (file)
@@ -548,7 +548,7 @@ impl BigUint {
 
     pub fn new(v: ~[BigDigit]) -> BigUint {
         // omit trailing zeros
-        let new_len = v.rposition(|n| *n != 0).map_default(0, |p| *p + 1);
+        let new_len = v.rposition(|n| *n != 0).map_move_default(0, |p| p + 1);
 
         if new_len == v.len() { return BigUint { data: v }; }
         let mut v = v;
@@ -1145,7 +1145,7 @@ pub fn parse_bytes(buf: &[u8], radix: uint)
             start = 1;
         }
         return BigUint::parse_bytes(buf.slice(start, buf.len()), radix)
-            .map_consume(|bu| BigInt::from_biguint(sign, bu));
+            .map_move(|bu| BigInt::from_biguint(sign, bu));
     }
 
     pub fn to_uint(&self) -> uint {
@@ -2028,7 +2028,7 @@ fn check(n: int, ans: &str) {
     #[test]
     fn test_from_str_radix() {
         fn check(s: &str, ans: Option<int>) {
-            let ans = ans.map(|&n| IntConvertible::from_int::<BigInt>(n));
+            let ans = ans.map_move(|n| IntConvertible::from_int::<BigInt>(n));
             assert_eq!(FromStrRadix::from_str_radix(s, 10), ans);
         }
         check("10", Some(10));
index 9833bd5d1cbf2cebe758fe7213832681d2bba76c..da8089250b34587a24cd3191031c87c286b40f1d 100644 (file)
@@ -696,7 +696,7 @@ fn test_from_iterator() {
         let u: ~[int] = deq.iter().transform(|&x| x).collect();
         assert_eq!(u, v);
 
-        let mut seq = iterator::Counter::new(0u, 2).take_(256);
+        let mut seq = iterator::count(0u, 2).take_(256);
         let deq: RingBuf<uint> = seq.collect();
         for (i, &x) in deq.iter().enumerate() {
             assert_eq!(2*i, x);
index 3f62317eb8908ca7b083f91b7edfee1e0b08af3c..e5116f19afa513feb04e17c97fd23e3097304a16 100644 (file)
@@ -203,7 +203,7 @@ pub fn consume(&mut self)
     {
         let values = replace(&mut self.v, ~[]);
         values.consume_iter().enumerate().filter_map(|(i, v)| {
-            v.map_consume(|v| (i, v))
+            v.map_move(|v| (i, v))
         })
     }
 }
index 68d5af43688a241f9ff827ff6ebe31253f3a1976..9238034cba33ccced0408caee1a27a93d0eec06e 100644 (file)
@@ -10,6 +10,7 @@
 
 use sort;
 use std::cmp;
+use std::hashmap;
 use std::io;
 use std::num;
 
@@ -352,6 +353,16 @@ pub fn write_boxplot(w: @io::Writer, s: &Summary, width_hint: uint) {
     w.write_str(histr);
 }
 
+/// Returns a HashMap with the number of occurences of every element in the
+/// sequence that the iterator exposes.
+pub fn freq_count<T: Iterator<U>, U: Eq+Hash>(mut iter: T) -> hashmap::HashMap<U, uint> {
+    let mut map = hashmap::HashMap::new::<U, uint>();
+    for elem in iter {
+        map.insert_or_update_with(elem, 1, |_, count| *count += 1);
+    }
+    map
+}
+
 // Test vectors generated from R, using the script src/etc/stat-test-vectors.r.
 
 #[cfg(test)]
index 63e371899a9bdbf8ed6c34ed4dbca5ec09eac33f..4172c715adb96309701da1228c37f66eb4f492b9 100644 (file)
@@ -935,6 +935,7 @@ fn test_mutex_killed_simple() {
         // child task must have finished by the time try returns
         do m.lock { }
     }
+    #[ignore(reason = "linked failure")]
     #[test] #[ignore(cfg(windows))]
     fn test_mutex_killed_cond() {
         // Getting killed during cond wait must not corrupt the mutex while
@@ -961,6 +962,7 @@ fn test_mutex_killed_cond() {
             assert!(!woken);
         }
     }
+    #[ignore(reason = "linked failure")]
     #[test] #[ignore(cfg(windows))]
     fn test_mutex_killed_broadcast() {
         use std::unstable::finally::Finally;
index 1cfb4f4afa6277b6df7b3b64b4c570fe070b720a..2173eb838e5ee9e65f72199944429335cd3924db 100644 (file)
@@ -127,7 +127,7 @@ pub fn new(out: @io::Writer) -> Result<Terminal, ~str> {
         let inf = ti.unwrap();
         let nc = if inf.strings.find_equiv(&("setaf")).is_some()
                  && inf.strings.find_equiv(&("setab")).is_some() {
-                     inf.numbers.find_equiv(&("colors")).map_consume_default(0, |&n| n)
+                     inf.numbers.find_equiv(&("colors")).map_move_default(0, |&n| n)
                  } else { 0 };
 
         return Ok(Terminal {out: out, ti: inf, num_colors: nc});
@@ -220,7 +220,7 @@ pub fn reset(&self) {
                 cap = self.ti.strings.find_equiv(&("op"));
             }
         }
-        let s = do cap.map_consume_default(Err(~"can't find terminfo capability `sgr0`")) |op| {
+        let s = do cap.map_move_default(Err(~"can't find terminfo capability `sgr0`")) |op| {
             expand(*op, [], &mut Variables::new())
         };
         if s.is_ok() {
index e87be1462267468dc8cc3b6772c41b191da6895e..761cb1bd76f929198e5011cd8595f3840fe30996 100644 (file)
@@ -238,20 +238,20 @@ pub fn parse_opts(args: &[~str]) -> OptRes {
     let run_ignored = getopts::opt_present(&matches, "ignored");
 
     let logfile = getopts::opt_maybe_str(&matches, "logfile");
-    let logfile = logfile.map(|s| Path(*s));
+    let logfile = logfile.map_move(|s| Path(s));
 
     let run_benchmarks = getopts::opt_present(&matches, "bench");
     let run_tests = ! run_benchmarks ||
         getopts::opt_present(&matches, "test");
 
     let ratchet_metrics = getopts::opt_maybe_str(&matches, "ratchet-metrics");
-    let ratchet_metrics = ratchet_metrics.map(|s| Path(*s));
+    let ratchet_metrics = ratchet_metrics.map_move(|s| Path(s));
 
     let ratchet_noise_percent = getopts::opt_maybe_str(&matches, "ratchet-noise-percent");
-    let ratchet_noise_percent = ratchet_noise_percent.map(|s| f64::from_str(*s).unwrap());
+    let ratchet_noise_percent = ratchet_noise_percent.map_move(|s| f64::from_str(s).unwrap());
 
     let save_metrics = getopts::opt_maybe_str(&matches, "save-metrics");
-    let save_metrics = save_metrics.map(|s| Path(*s));
+    let save_metrics = save_metrics.map_move(|s| Path(s));
 
     let test_opts = TestOpts {
         filter: filter,
index 487ad050e78643bf5bd759c7180d88a8375dd05c..ab7d47255dac60da1aceb794d943910ff9fe7b3e 100644 (file)
@@ -394,7 +394,7 @@ impl<'self, T> Iterator<&'self T> for TreeSetIterator<'self, T> {
     /// Advance the iterator to the next node (in order). If there are no more nodes, return `None`.
     #[inline]
     fn next(&mut self) -> Option<&'self T> {
-        do self.iter.next().map |&(value, _)| { value }
+        do self.iter.next().map_move |(value, _)| { value }
     }
 }
 
index 0256519abb7e835c257cd29943140cfdfa4aeb42..b4ba8acae476974cff76b27e2945718900e12350 100644 (file)
@@ -221,7 +221,7 @@ fn digest<T:Encodable<json::Encoder>>(t: &T) -> ~str {
 fn digest_file(path: &Path) -> ~str {
     let mut sha = ~Sha1::new();
     let s = io::read_whole_file_str(path);
-    (*sha).input_str(*s.get_ref());
+    (*sha).input_str(s.unwrap());
     (*sha).result_str()
 }
 
@@ -378,7 +378,7 @@ fn test() {
     let pth = Path("foo.c");
     {
         let r = io::file_writer(&pth, [io::Create]);
-        r.get_ref().write_str("int main() { return 0; }");
+        r.unwrap().write_str("int main() { return 0; }");
     }
 
     let cx = Context::new(RWArc::new(Database::new(Path("db.json"))),
index 1ac8146bb589aab17141eddb25a67090331fe0d4..010486cdf855c7747df7c33c46362d3b1cd69f95 100644 (file)
@@ -130,7 +130,7 @@ fn rustc_help() {
 fn find_cmd(command_string: &str) -> Option<Command> {
     do COMMANDS.iter().find_ |command| {
         command.cmd == command_string
-    }.map_consume(|x| *x)
+    }.map_move(|x| *x)
 }
 
 fn cmd_help(args: &[~str]) -> ValidUsage {
index 2c642d54253b6b79c4cf28d142ab5de3653d8042..61ab826e9ee51f5728c25c15edbdaca8d89c355c 100644 (file)
@@ -669,8 +669,7 @@ pub fn build_session_options(binary: @str,
         } else if opt_present(matches, "emit-llvm") {
             link::output_type_bitcode
         } else { link::output_type_exe };
-    let sysroot_opt = getopts::opt_maybe_str(matches, "sysroot");
-    let sysroot_opt = sysroot_opt.map(|m| @Path(*m));
+    let sysroot_opt = getopts::opt_maybe_str(matches, "sysroot").map_move(|m| @Path(m));
     let target_opt = getopts::opt_maybe_str(matches, "target");
     let target_feature_opt = getopts::opt_maybe_str(matches, "target-feature");
     let save_temps = getopts::opt_present(matches, "save-temps");
index d8b59d579c8154ece425d0be7d5f0d0c7c28afbd..d6584846655d2db01bc28f9cbfdabfcc699a7ce8 100644 (file)
@@ -61,7 +61,9 @@ fn fold_mod(cx: @Context, m: &ast::_mod, fld: @fold::ast_fold) -> ast::_mod {
         filter_item(cx, *a).chain(|x| fld.fold_item(x))
     }.collect();
     let filtered_view_items = do m.view_items.iter().filter_map |a| {
-        filter_view_item(cx, a).map(|&x| fld.fold_view_item(x))
+        do filter_view_item(cx, a).map_move |x| {
+            fld.fold_view_item(x)
+        }
     }.collect();
     ast::_mod {
         view_items: filtered_view_items,
@@ -83,7 +85,9 @@ fn fold_foreign_mod(
 ) -> ast::foreign_mod {
     let filtered_items = nm.items.iter().filter_map(|a| filter_foreign_item(cx, *a)).collect();
     let filtered_view_items = do nm.view_items.iter().filter_map |a| {
-        filter_view_item(cx, a).map(|&x| fld.fold_view_item(x))
+        do filter_view_item(cx, a).map_move |x| {
+            fld.fold_view_item(x)
+        }
     }.collect();
     ast::foreign_mod {
         sort: nm.sort,
@@ -138,7 +142,7 @@ fn fold_block(
         filter_stmt(cx, *a).chain(|stmt| fld.fold_stmt(stmt))
     }.collect();
     let filtered_view_items = do b.view_items.iter().filter_map |a| {
-        filter_view_item(cx, a).map(|&x| fld.fold_view_item(x))
+        filter_view_item(cx, a).map(|x| fld.fold_view_item(*x))
     }.collect();
     ast::Block {
         view_items: filtered_view_items,
index 356cdaf754eebe7b199bf20870b46568e552d317..90db3f8edb0a6eec5ba033ecafd0d6d57190262d 100644 (file)
@@ -2159,7 +2159,7 @@ pub fn find_name<'r>(&'r self, ty: &Type) -> Option<&'r str> {
     }
 
     pub fn find_type(&self, s: &str) -> Option<Type> {
-        self.named_types.find_equiv(&s).map_consume(|x| Type::from_ref(*x))
+        self.named_types.find_equiv(&s).map_move(|x| Type::from_ref(*x))
     }
 
     // We have a depth count, because we seem to make infinite types.
index 33623a40cfb2ac6a1f34b2b743b892dfb454444a..a5f541412ded9b84715b777e58f1c4aabdc093eb 100644 (file)
@@ -133,7 +133,7 @@ pub fn add_extern_mod_stmt_cnum(cstore: &mut CStore,
 pub fn find_extern_mod_stmt_cnum(cstore: &CStore,
                                  emod_id: ast::NodeId)
                        -> Option<ast::CrateNum> {
-    cstore.extern_mod_crate_map.find(&emod_id).map_consume(|x| *x)
+    cstore.extern_mod_crate_map.find(&emod_id).map_move(|x| *x)
 }
 
 #[deriving(Clone)]
index c3097d1aa66577c85ff5d71324ccf208e85c4c6c..8d3571260184b679ec621756110ac3230e021c0c 100644 (file)
@@ -198,8 +198,8 @@ fn item_def_id(d: ebml::Doc, cdata: cmd) -> ast::def_id {
 }
 
 fn get_provided_source(d: ebml::Doc, cdata: cmd) -> Option<ast::def_id> {
-    do reader::maybe_get_doc(d, tag_item_method_provided_source).map |doc| {
-        translate_def_id(cdata, reader::with_doc_data(*doc, parse_def_id))
+    do reader::maybe_get_doc(d, tag_item_method_provided_source).map_move |doc| {
+        translate_def_id(cdata, reader::with_doc_data(doc, parse_def_id))
     }
 }
 
@@ -265,10 +265,10 @@ fn item_ty_param_defs(item: ebml::Doc, tcx: ty::ctxt, cdata: cmd,
 }
 
 fn item_ty_region_param(item: ebml::Doc) -> Option<ty::region_variance> {
-    reader::maybe_get_doc(item, tag_region_param).map(|doc| {
-        let mut decoder = reader::Decoder(*doc);
+    do reader::maybe_get_doc(item, tag_region_param).map_move |doc| {
+        let mut decoder = reader::Decoder(doc);
         Decodable::decode(&mut decoder)
-    })
+    }
 }
 
 fn item_ty_param_count(item: ebml::Doc) -> uint {
@@ -415,7 +415,7 @@ pub fn get_impl_trait(cdata: cmd,
                        tcx: ty::ctxt) -> Option<@ty::TraitRef>
 {
     let item_doc = lookup_item(id, cdata.data);
-    do reader::maybe_get_doc(item_doc, tag_item_trait_ref).map |&tp| {
+    do reader::maybe_get_doc(item_doc, tag_item_trait_ref).map_move |tp| {
         @doc_trait_ref(tp, tcx, cdata)
     }
 }
index 3db90ed5d74948981544249b1e153be66905128b..d410021063c238496b76f4ce94ce296d7468a7b6 100644 (file)
@@ -286,13 +286,15 @@ pub fn opt_loan_path(cmt: mc::cmt) -> Option<@LoanPath> {
         }
 
         mc::cat_deref(cmt_base, _, _) => {
-            opt_loan_path(cmt_base).map(
-                |&lp| @LpExtend(lp, cmt.mutbl, LpDeref))
+            do opt_loan_path(cmt_base).map_move |lp| {
+                @LpExtend(lp, cmt.mutbl, LpDeref)
+            }
         }
 
         mc::cat_interior(cmt_base, ik) => {
-            opt_loan_path(cmt_base).map(
-                |&lp| @LpExtend(lp, cmt.mutbl, LpInterior(ik)))
+            do opt_loan_path(cmt_base).map_move |lp| {
+                @LpExtend(lp, cmt.mutbl, LpInterior(ik))
+            }
         }
 
         mc::cat_downcast(cmt_base) |
index 77e81709a03d73370f51043a5a45ba9bc08840c4..3b56764f2fcad1afb0f38f41df22a46f744d794c 100644 (file)
@@ -493,9 +493,9 @@ pub fn compare_lit_exprs(tcx: middle::ty::ctxt, a: &expr, b: &expr) -> Option<in
 }
 
 pub fn lit_expr_eq(tcx: middle::ty::ctxt, a: &expr, b: &expr) -> Option<bool> {
-    compare_lit_exprs(tcx, a, b).map(|&val| val == 0)
+    compare_lit_exprs(tcx, a, b).map_move(|val| val == 0)
 }
 
 pub fn lit_eq(a: &lit, b: &lit) -> Option<bool> {
-    compare_const_vals(&lit_to_const(a), &lit_to_const(b)).map(|&val| val == 0)
+    compare_const_vals(&lit_to_const(a), &lit_to_const(b)).map_move(|val| val == 0)
 }
index 0dfad430f4d656389ecb175cf347e41c67f510ad..42bc435a58a944c48c30bf1b914a4a677c82784f 100644 (file)
@@ -393,7 +393,7 @@ pub fn match_and_collect_item(&mut self,
             return;    // Didn't match.
         }
 
-        let item_index = self.item_refs.find(&value).map(|x| **x);
+        let item_index = self.item_refs.find(&value).map_move(|x| *x);
         // prevent borrow checker from considering   ^~~~~~~~~~~
         // self to be borrowed (annoying)
 
index 0387f344796e26b4f9c58cd05edabe2571262e2d..b39616304906bb4a02a4936c74091446bff12a57 100644 (file)
@@ -607,9 +607,9 @@ pub fn variable_from_path(&self, expr: &expr) -> Option<Variable> {
         match expr.node {
           expr_path(_) => {
             let def = self.tcx.def_map.get_copy(&expr.id);
-            moves::moved_variable_node_id_from_def(def).map(
-                |rdef| self.variable(*rdef, expr.span)
-            )
+            do moves::moved_variable_node_id_from_def(def).map_move |rdef| {
+                self.variable(rdef, expr.span)
+            }
           }
           _ => None
         }
@@ -623,9 +623,9 @@ pub fn variable_from_def_map(&self, node_id: NodeId, span: span)
                                  -> Option<Variable> {
         match self.tcx.def_map.find(&node_id) {
           Some(&def) => {
-            moves::moved_variable_node_id_from_def(def).map(
-                |rdef| self.variable(*rdef, span)
-            )
+            do moves::moved_variable_node_id_from_def(def).map_move |rdef| {
+                self.variable(rdef, span)
+            }
           }
           None => {
             self.tcx.sess.span_bug(
index 2d121209118f8dc28bb8ac69ec3eb6063035cce2..4da22be4428e271f60b8de66ad1da2f1c440a853 100644 (file)
@@ -111,7 +111,7 @@ pub fn record_cleanup_scope(&mut self, scope_id: ast::NodeId) {
     pub fn opt_encl_scope(&self, id: ast::NodeId) -> Option<ast::NodeId> {
         //! Returns the narrowest scope that encloses `id`, if any.
 
-        self.scope_map.find(&id).map(|&x| *x)
+        self.scope_map.find(&id).map_move(|x| *x)
     }
 
     pub fn encl_scope(&self, id: ast::NodeId) -> ast::NodeId {
@@ -579,8 +579,7 @@ pub fn add_variance(&self, variance: region_variance) -> region_variance {
     /// the new variance is joined with the old variance.
     pub fn add_rp(&mut self, id: ast::NodeId, variance: region_variance) {
         assert!(id != 0);
-        let old_variance = self.region_paramd_items.find(&id).
-                                map_consume(|x| *x);
+        let old_variance = self.region_paramd_items.find(&id).map_move(|x| *x);
         let joined_variance = match old_variance {
           None => variance,
           Some(v) => join_variance(v, variance)
index 625dcd5d9cc49d1a5adb75fea9bd225e150c1cff..da0ba1558c9bd988f16bab7b6cdae49fb047c583 100644 (file)
@@ -3358,7 +3358,7 @@ pub fn upvarify(@mut self,
                   // item, it's ok
                   match def {
                     def_ty_param(did, _)
-                        if self.def_map.find(&did.node).map_consume(|x| *x)
+                        if self.def_map.find(&did.node).map_move(|x| *x)
                             == Some(def_typaram_binder(item_id)) => {
                       // ok
                     }
index 2efed8f36d7fff216b0f26bbefc0e1f3ed5acff2..dcaa141cbc2890f144fae2a3067cfe74fd1a4126 100644 (file)
@@ -92,7 +92,7 @@
 static task_local_insn_key: local_data::Key<@~[&'static str]> = &local_data::Key;
 
 pub fn with_insn_ctxt(blk: &fn(&[&'static str])) {
-    let opt = local_data::get(task_local_insn_key, |k| k.map(|&k| *k));
+    let opt = local_data::get(task_local_insn_key, |k| k.map_move(|k| *k));
     if opt.is_some() {
         blk(*opt.unwrap());
     }
@@ -108,7 +108,7 @@ pub struct _InsnCtxt { _x: () }
 impl Drop for _InsnCtxt {
     fn drop(&self) {
         do local_data::modify(task_local_insn_key) |c| {
-            do c.map_consume |ctx| {
+            do c.map_move |ctx| {
                 let mut ctx = (*ctx).clone();
                 ctx.pop();
                 @ctx
@@ -120,7 +120,7 @@ fn drop(&self) {
 pub fn push_ctxt(s: &'static str) -> _InsnCtxt {
     debug!("new InsnCtxt: %s", s);
     do local_data::modify(task_local_insn_key) |c| {
-        do c.map_consume |ctx| {
+        do c.map_move |ctx| {
             let mut ctx = (*ctx).clone();
             ctx.push(s);
             @ctx
index fe1c288d1773f3e3e7125a1055de9358d99ca7bb..f5fb68a70578c2fcf60536019877e5f00e07d236 100644 (file)
@@ -159,7 +159,7 @@ fn struct_ty(ty: Type,
              padding: Option<Type>,
              coerce: bool) -> Type {
     let size = ty_size(ty) * 8;
-    let mut fields = padding.map_default(~[], |p| ~[*p]);
+    let mut fields = padding.map_move_default(~[], |p| ~[p]);
 
     if coerce {
         fields = vec::append(fields, coerce_to_int(size));
index f303e7b82759769696c95b0c9856d28c89cf0341..240696ec1908b5a706b5b1da79ef34308b87bf8f 100644 (file)
@@ -1010,8 +1010,7 @@ pub fn node_id_type_params(bcx: @mut Block, id: ast::NodeId) -> ~[ty::t] {
 pub fn node_vtables(bcx: @mut Block, id: ast::NodeId)
                  -> Option<typeck::vtable_res> {
     let raw_vtables = bcx.ccx().maps.vtable_map.find(&id);
-    raw_vtables.map(
-        |&vts| resolve_vtables_in_fn_ctxt(bcx.fcx, *vts))
+    raw_vtables.map_move(|vts| resolve_vtables_in_fn_ctxt(bcx.fcx, *vts))
 }
 
 pub fn resolve_vtables_in_fn_ctxt(fcx: &FunctionContext, vts: typeck::vtable_res)
index 802163583d6a1dacb8ee552cbf392403f5d7ca27..56ba1ae1694b6684f3a02681c69318032d7abb36 100644 (file)
@@ -241,7 +241,7 @@ fn drop(&self) {
 static task_local_llcx_key: local_data::Key<@ContextRef> = &local_data::Key;
 
 pub fn task_llcx() -> ContextRef {
-    let opt = local_data::get(task_local_llcx_key, |k| k.map(|&k| *k));
+    let opt = local_data::get(task_local_llcx_key, |k| k.map_move(|k| *k));
     *opt.expect("task-local LLVMContextRef wasn't ever set!")
 }
 
index 5153296337daed25055c7751d7d680c61abc37f5..b1e600b9d7376f5466d53ba06a500a948fe8e90d 100644 (file)
@@ -888,6 +888,11 @@ fn count_zeros_intrinsic(bcx: @mut Block, name: &'static str) {
             let offset = get_param(decl, first_real_arg + 1);
             Ret(bcx, GEP(bcx, ptr, [offset]));
         }
+        "offset_inbounds" => {
+            let ptr = get_param(decl, first_real_arg);
+            let offset = get_param(decl, first_real_arg + 1);
+            Ret(bcx, InBoundsGEP(bcx, ptr, [offset]));
+        }
         "memcpy32" => memcpy_intrinsic(bcx, "llvm.memcpy.p0i8.p0i8.i32", substs.tys[0], 32),
         "memcpy64" => memcpy_intrinsic(bcx, "llvm.memcpy.p0i8.p0i8.i64", substs.tys[0], 64),
         "memmove32" => memcpy_intrinsic(bcx, "llvm.memmove.p0i8.p0i8.i32", substs.tys[0], 32),
index b67d88c07e1e6207dae5da20f96ed72150f33ff7..9be01ef1db94f639da751f44bb3ed3ef253e31bd 100644 (file)
@@ -162,7 +162,7 @@ pub fn trans_method_callee(bcx: @mut Block,
                 data: Method(MethodData {
                     llfn: callee_fn.llfn,
                     llself: val,
-                    temp_cleanup: temp_cleanups.head_opt().map(|&v| *v),
+                    temp_cleanup: temp_cleanups.head_opt().map_move(|v| *v),
                     self_ty: node_id_type(bcx, this.id),
                     self_mode: mentry.self_mode,
                 })
@@ -339,7 +339,7 @@ pub fn trans_monomorphized_callee(bcx: @mut Block,
               data: Method(MethodData {
                   llfn: llfn_val,
                   llself: llself_val,
-                  temp_cleanup: temp_cleanups.head_opt().map(|&v| *v),
+                  temp_cleanup: temp_cleanups.head_opt().map_move(|v| *v),
                   self_ty: node_id_type(bcx, base.id),
                   self_mode: mentry.self_mode,
               })
index 42d5527ee43bc39bced200bcb0eed0737d7e792f..ad83286c8c1d75a60353ab2a36c2f248f0665f26 100644 (file)
@@ -148,7 +148,8 @@ fn store_type_uses(cx: Context, fn_id: def_id) -> @~[type_uses] {
                     "visit_tydesc"  | "forget" | "frame_address" |
                     "morestack_addr" => 0,
 
-                    "offset" | "memcpy32" | "memcpy64" | "memmove32" | "memmove64" |
+                    "offset" | "offset_inbounds" |
+                    "memcpy32" | "memcpy64" | "memmove32" | "memmove64" |
                     "memset32" | "memset64" => use_repr,
 
                     "sqrtf32" | "sqrtf64" | "powif32" | "powif64" |
index a53bdff85f9dc2cb4903f2ef47d67b2b69969ce0..849c35cdd2c038eec2662fbf09c77466a2edcfb0 100644 (file)
@@ -3557,7 +3557,7 @@ pub fn def_has_ty_params(def: ast::def) -> bool {
 
 pub fn provided_source(cx: ctxt, id: ast::def_id)
     -> Option<ast::def_id> {
-    cx.provided_method_sources.find(&id).map(|x| **x)
+    cx.provided_method_sources.find(&id).map_move(|x| *x)
 }
 
 pub fn provided_trait_methods(cx: ctxt, id: ast::def_id) -> ~[@Method] {
@@ -3710,8 +3710,9 @@ fn struct_ctor_id(cx: ctxt, struct_did: ast::def_id) -> Option<ast::def_id> {
         Some(&ast_map::node_item(item, _)) => {
             match item.node {
                 ast::item_struct(struct_def, _) => {
-                    struct_def.ctor_id.map(|ctor_id|
-                        ast_util::local_def(*ctor_id))
+                    do struct_def.ctor_id.map_move |ctor_id| {
+                        ast_util::local_def(ctor_id)
+                    }
                 }
                 _ => cx.sess.bug("called struct_ctor_id on non-struct")
             }
@@ -4443,15 +4444,15 @@ pub fn count_traits_and_supertraits(tcx: ctxt,
 }
 
 pub fn get_tydesc_ty(tcx: ctxt) -> Result<t, ~str> {
-    do tcx.lang_items.require(TyDescStructLangItem).map |tydesc_lang_item| {
-        tcx.intrinsic_defs.find_copy(tydesc_lang_item)
+    do tcx.lang_items.require(TyDescStructLangItem).map_move |tydesc_lang_item| {
+        tcx.intrinsic_defs.find_copy(&tydesc_lang_item)
             .expect("Failed to resolve TyDesc")
     }
 }
 
 pub fn get_opaque_ty(tcx: ctxt) -> Result<t, ~str> {
-    do tcx.lang_items.require(OpaqueStructLangItem).map |opaque_lang_item| {
-        tcx.intrinsic_defs.find_copy(opaque_lang_item)
+    do tcx.lang_items.require(OpaqueStructLangItem).map_move |opaque_lang_item| {
+        tcx.intrinsic_defs.find_copy(&opaque_lang_item)
             .expect("Failed to resolve Opaque")
     }
 }
index 53853e4fe1a78be01dedd8e7e1256cb521214e7b..750bd506f3e48583a66c7740b1aeb1806dba6d57 100644 (file)
@@ -621,9 +621,9 @@ fn ty_of_method_or_bare_fn<AC:AstConv,RS:region_scope + Clone + 'static>(
         in_binding_rscope(rscope,
                           RegionParamNames(bound_lifetime_names.clone()));
 
-    let opt_transformed_self_ty = opt_self_info.map(|&self_info| {
+    let opt_transformed_self_ty = do opt_self_info.map_move |self_info| {
         transform_self_ty(this, &rb, self_info)
-    });
+    };
 
     let input_tys = decl.inputs.map(|a| ty_of_arg(this, &rb, a, None));
 
index 7caed39060159bd2c1d321c9466a1a9b20ba5a1d..d8a9350e695d70404f3250bb904ab818d0eebb49 100644 (file)
@@ -158,9 +158,9 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: @ast::pat, path: &ast::Path,
                 None => {
                     fcx.infcx().type_error_message_str_with_expected(pat.span,
                                                        |expected, actual| {
-                                                       expected.map_default(~"", |e| {
+                                                       expected.map_move_default(~"", |e| {
                         fmt!("mismatched types: expected `%s` but found %s",
-                             *e, actual)})},
+                             e, actual)})},
                              Some(expected), ~"a structure pattern",
                              None);
                     fcx.write_error(pat.id);
@@ -201,9 +201,9 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: @ast::pat, path: &ast::Path,
         _ => {
             fcx.infcx().type_error_message_str_with_expected(pat.span,
                                                |expected, actual| {
-                                               expected.map_default(~"", |e| {
+                                               expected.map_move_default(~"", |e| {
                     fmt!("mismatched types: expected `%s` but found %s",
-                         *e, actual)})},
+                         e, actual)})},
                     Some(expected), ~"an enum or structure pattern",
                     None);
             fcx.write_error(pat.id);
@@ -535,9 +535,9 @@ pub fn check_pat(pcx: &pat_ctxt, pat: @ast::pat, expected: ty::t) {
                     _ => ty::terr_mismatch
                 };
                 fcx.infcx().type_error_message_str_with_expected(pat.span, |expected, actual| {
-                expected.map_default(~"", |e| {
+                expected.map_move_default(~"", |e| {
                     fmt!("mismatched types: expected `%s` but found %s",
-                                     *e, actual)})}, Some(expected), ~"tuple", Some(&type_error));
+                                     e, actual)})}, Some(expected), ~"tuple", Some(&type_error));
                 fcx.write_error(pat.id);
             }
         }
@@ -584,9 +584,9 @@ pub fn check_pat(pcx: &pat_ctxt, pat: @ast::pat, expected: ty::t) {
               fcx.infcx().type_error_message_str_with_expected(
                   pat.span,
                   |expected, actual| {
-                      expected.map_default(~"", |e| {
+                      expected.map_move_default(~"", |e| {
                           fmt!("mismatched types: expected `%s` but found %s",
-                               *e, actual)})},
+                               e, actual)})},
                   Some(expected),
                   ~"a vector pattern",
                   None);
@@ -642,9 +642,9 @@ pub fn check_pointer_pat(pcx: &pat_ctxt,
             fcx.infcx().type_error_message_str_with_expected(
                 span,
                 |expected, actual| {
-                    expected.map_default(~"", |e| {
+                    expected.map_move_default(~"", |e| {
                         fmt!("mismatched types: expected `%s` but found %s",
-                             *e, actual)})},
+                             e, actual)})},
                 Some(expected),
                 fmt!("%s pattern", match pointer_kind {
                     Managed => "an @-box",
index ea8a11fc7b3821b425f4ee3fac59c6927a712bb6..da0e219310fde2b64b3f325b892d7cd5d028acc5 100644 (file)
@@ -364,8 +364,8 @@ pub fn check_fn(ccx: @mut CrateCtxt,
                 |br| ty::re_free(ty::FreeRegion {scope_id: body.id,
                                                  bound_region: br}));
         let opt_self_info =
-            opt_self_info.map(
-                |si| SelfInfo {self_ty: opt_self_ty.unwrap(), ..*si});
+            opt_self_info.map_move(
+                |si| SelfInfo {self_ty: opt_self_ty.unwrap(), .. si});
         (isr, opt_self_info, fn_sig)
     };
 
@@ -536,7 +536,7 @@ pub fn check_method(ccx: @mut CrateCtxt,
 {
     let method_def_id = local_def(method.id);
     let method_ty = ty::method(ccx.tcx, method_def_id);
-    let opt_self_info = method_ty.transformed_self_ty.map(|&ty| {
+    let opt_self_info = method_ty.transformed_self_ty.map_move(|ty| {
         SelfInfo {self_ty: ty,
                   self_id: method.self_id,
                   span: method.explicit_self.span}
@@ -557,7 +557,7 @@ pub fn check_no_duplicate_fields(tcx: ty::ctxt,
 
     for p in fields.iter() {
         let (id, sp) = *p;
-        let orig_sp = field_names.find(&id).map_consume(|x| *x);
+        let orig_sp = field_names.find(&id).map_move(|x| *x);
         match orig_sp {
             Some(orig_sp) => {
                 tcx.sess.span_err(sp, fmt!("Duplicate field name %s in record type declaration",
@@ -601,7 +601,7 @@ pub fn check_item(ccx: @mut CrateCtxt, it: @ast::item) {
         check_bare_fn(ccx, decl, body, it.id, None);
       }
       ast::item_impl(_, _, _, ref ms) => {
-        let rp = ccx.tcx.region_paramd_items.find(&it.id).map_consume(|x| *x);
+        let rp = ccx.tcx.region_paramd_items.find(&it.id).map_move(|x| *x);
         debug!("item_impl %s with id %d rp %?",
                ccx.tcx.sess.str_of(it.ident), it.id, rp);
         for m in ms.iter() {
@@ -1877,8 +1877,7 @@ fn check_struct_or_variant_fields(fcx: @mut FnCtxt,
         for field in ast_fields.iter() {
             let mut expected_field_type = ty::mk_err();
 
-            let pair = class_field_map.find(&field.ident).
-                                       map_consume(|x| *x);
+            let pair = class_field_map.find(&field.ident).map_move(|x| *x);
             match pair {
                 None => {
                     tcx.sess.span_err(
@@ -1962,7 +1961,7 @@ fn check_struct_constructor(fcx: @mut FnCtxt,
         if class_id.crate == ast::LOCAL_CRATE {
             region_parameterized =
                 tcx.region_paramd_items.find(&class_id.node).
-                    map_consume(|x| *x);
+                    map_move(|x| *x);
             match tcx.items.find(&class_id.node) {
                 Some(&ast_map::node_item(@ast::item {
                         node: ast::item_struct(_, ref generics),
@@ -2050,7 +2049,7 @@ fn check_struct_enum_variant(fcx: @mut FnCtxt,
         let raw_type;
         if enum_id.crate == ast::LOCAL_CRATE {
             region_parameterized =
-                tcx.region_paramd_items.find(&enum_id.node).map_consume(|x| *x);
+                tcx.region_paramd_items.find(&enum_id.node).map_move(|x| *x);
             match tcx.items.find(&enum_id.node) {
                 Some(&ast_map::node_item(@ast::item {
                         node: ast::item_enum(_, ref generics),
@@ -3481,6 +3480,20 @@ fn param(ccx: @mut CrateCtxt, n: uint) -> ty::t {
                    mutbl: ast::m_imm
                }))
             }
+            "offset_inbounds" => {
+              (1,
+               ~[
+                  ty::mk_ptr(tcx, ty::mt {
+                      ty: param(ccx, 0),
+                      mutbl: ast::m_imm
+                  }),
+                  ty::mk_int()
+               ],
+               ty::mk_ptr(tcx, ty::mt {
+                   ty: param(ccx, 0),
+                   mutbl: ast::m_imm
+               }))
+            }
             "memcpy32" => {
               (1,
                ~[
index 2685055bd84aa6083376511dd2c9098f780ef84a..cb4827104b6275e7f63506060f1146cac7430ec1 100644 (file)
@@ -40,9 +40,9 @@ pub fn replace_bound_regions_in_fn_sig(
 
     debug!("replace_bound_regions_in_fn_sig(self_ty=%?, fn_sig=%s, \
             all_tys=%?)",
-           opt_self_ty.map(|&t| ppaux::ty_to_str(tcx, t)),
+           opt_self_ty.map(|t| ppaux::ty_to_str(tcx, *t)),
            ppaux::fn_sig_to_str(tcx, fn_sig),
-           all_tys.map(|&t| ppaux::ty_to_str(tcx, t)));
+           all_tys.map(|t| ppaux::ty_to_str(tcx, *t)));
     let _i = indenter();
 
     let isr = do create_bound_region_mapping(tcx, isr, all_tys) |br| {
@@ -52,12 +52,12 @@ pub fn replace_bound_regions_in_fn_sig(
     let new_fn_sig = ty::fold_sig(fn_sig, |t| {
         replace_bound_regions(tcx, isr, t)
     });
-    let new_self_ty = opt_self_ty.map(|&t| replace_bound_regions(tcx, isr, t));
+    let new_self_ty = opt_self_ty.map(|t| replace_bound_regions(tcx, isr, *t));
 
     debug!("result of replace_bound_regions_in_fn_sig: \
             new_self_ty=%?, \
             fn_sig=%s",
-           new_self_ty.map(|&t| ppaux::ty_to_str(tcx, t)),
+           new_self_ty.map(|t| ppaux::ty_to_str(tcx, *t)),
            ppaux::fn_sig_to_str(tcx, &new_fn_sig));
 
     return (isr, new_self_ty, new_fn_sig);
index abb97f0d1c7b9d7ed10c1a8cc4b532fa4dacad51..700d96727eae2f9a0f3700e0a9f4c91b09c379df 100644 (file)
@@ -131,9 +131,7 @@ fn lookup_vtables_for_param(vcx: &VtableContext,
     // ty is the value supplied for the type parameter A...
     let mut param_result = ~[];
 
-    do ty::each_bound_trait_and_supertraits(
-        tcx, type_param_bounds.trait_bounds) |trait_ref|
-    {
+    do ty::each_bound_trait_and_supertraits(tcx, type_param_bounds.trait_bounds) |trait_ref| {
         // ...and here trait_ref is each bound that was declared on A,
         // expressed in terms of the type parameters.
 
index 2bef2c08bb22d983e3fa5ea398f981b44bfed85a..907a076b1a1efce000e622877195440379157c62 100644 (file)
@@ -198,7 +198,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
                             trait_id: ast::NodeId)
 {
     let tcx = ccx.tcx;
-    let region_paramd = tcx.region_paramd_items.find(&trait_id).map(|&x| *x);
+    let region_paramd = tcx.region_paramd_items.find(&trait_id).map_move(|x| *x);
     match tcx.items.get_copy(&trait_id) {
         ast_map::node_item(@ast::item {
             node: ast::item_trait(ref generics, _, ref ms),
@@ -817,7 +817,7 @@ pub fn ensure_no_ty_param_bounds(ccx: &CrateCtxt,
 
 pub fn convert(ccx: &CrateCtxt, it: &ast::item) {
     let tcx = ccx.tcx;
-    let rp = tcx.region_paramd_items.find(&it.id).map_consume(|x| *x);
+    let rp = tcx.region_paramd_items.find(&it.id).map_move(|x| *x);
     debug!("convert: item %s with id %d rp %?",
            tcx.sess.str_of(it.ident), it.id, rp);
     match it.node {
@@ -1020,7 +1020,7 @@ pub fn trait_def_of_item(ccx: &CrateCtxt, it: &ast::item) -> @ty::TraitDef {
       Some(&def) => return def,
       _ => {}
     }
-    let rp = tcx.region_paramd_items.find(&it.id).map_consume(|x| *x);
+    let rp = tcx.region_paramd_items.find(&it.id).map_move(|x| *x);
     match it.node {
         ast::item_trait(ref generics, _, _) => {
             let self_ty = ty::mk_self(tcx, def_id);
@@ -1049,7 +1049,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::item)
       Some(&tpt) => return tpt,
       _ => {}
     }
-    let rp = tcx.region_paramd_items.find(&it.id).map_consume(|x| *x);
+    let rp = tcx.region_paramd_items.find(&it.id).map_move(|x| *x);
     match it.node {
       ast::item_static(ref t, _, _) => {
         let typ = ccx.to_ty(&empty_rscope, t);
@@ -1086,7 +1086,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::item)
           None => { }
         }
 
-        let rp = tcx.region_paramd_items.find(&it.id).map_consume(|x| *x);
+        let rp = tcx.region_paramd_items.find(&it.id).map_move(|x| *x);
         let region_parameterization =
             RegionParameterization::from_variance_and_generics(rp, generics);
         let tpt = {
index 854ee835cc7dce534006f1787ea4eb07d52ce212..7fa7daf614901006d54b2cc334c962752007d925 100644 (file)
@@ -716,12 +716,13 @@ pub fn type_error_message_str_with_expected(@mut self,
                                                 err: Option<&ty::type_err>) {
         debug!("hi! expected_ty = %?, actual_ty = %s", expected_ty, actual_ty);
 
-        let error_str = err.map_default(~"", |t_err|
-                         fmt!(" (%s)",
-                              ty::type_err_to_str(self.tcx, *t_err)));
-        let resolved_expected = expected_ty.map(|&e_ty|
-                                                { self.resolve_type_vars_if_possible(e_ty) });
-        if !resolved_expected.map_default(false, |&e| { ty::type_is_error(e) }) {
+        let error_str = do err.map_move_default(~"") |t_err| {
+            fmt!(" (%s)", ty::type_err_to_str(self.tcx, t_err))
+        };
+        let resolved_expected = do expected_ty.map_move |e_ty| {
+            self.resolve_type_vars_if_possible(e_ty)
+        };
+        if !resolved_expected.map_move_default(false, |e| { ty::type_is_error(e) }) {
             match resolved_expected {
                 None => self.tcx.sess.span_err(sp,
                             fmt!("%s%s", mk_msg(None, actual_ty), error_str)),
index 46414a7a5e23e0cc13e0e886d94db7c872a2c20c..1dfca0ba0e89cf85fe6b42b44ecb80fb1fc31ba3 100644 (file)
@@ -249,13 +249,12 @@ pub fn run_compiler(args: &~[~str], demitter: diagnostic::Emitter) {
 
     let sopts = build_session_options(binary, matches, demitter);
     let sess = build_session(sopts, demitter);
-    let odir = getopts::opt_maybe_str(matches, "out-dir");
-    let odir = odir.map(|o| Path(*o));
-    let ofile = getopts::opt_maybe_str(matches, "o");
-    let ofile = ofile.map(|o| Path(*o));
+    let odir = getopts::opt_maybe_str(matches, "out-dir").map_move(|o| Path(o));
+    let ofile = getopts::opt_maybe_str(matches, "o").map_move(|o| Path(o));
     let cfg = build_configuration(sess, binary, &input);
-    let pretty = getopts::opt_default(matches, "pretty", "normal").map(
-                    |a| parse_pretty(sess, *a));
+    let pretty = do getopts::opt_default(matches, "pretty", "normal").map_move |a| {
+        parse_pretty(sess, a)
+    };
     match pretty {
       Some::<pp_mode>(ppm) => {
         pretty_print_input(sess, cfg, &input, ppm);
@@ -299,10 +298,18 @@ pub enum monitor_msg {
 */
 pub fn monitor(f: ~fn(diagnostic::Emitter)) {
     use std::comm::*;
+
+    // XXX: This is a hack for newsched since it doesn't support split stacks.
+    // rustc needs a lot of stack!
+    static STACK_SIZE: uint = 4000000;
+
     let (p, ch) = stream();
     let ch = SharedChan::new(ch);
     let ch_capture = ch.clone();
-    match do task::try || {
+    let mut task_builder = task::task();
+    task_builder.supervised();
+    task_builder.opts.stack_size = Some(STACK_SIZE);
+    match do task_builder.try {
         let ch = ch_capture.clone();
         let ch_capture = ch.clone();
         // The 'diagnostics emitter'. Every error, warning, etc. should
index d387bbea592d36374231a4e59a4572d00d177fef..3598eb7c0fb9b217d8af908ae888c112567382b1 100644 (file)
@@ -140,7 +140,7 @@ fn config_from_opts(
     let result = result::Ok(config);
     let result = do result.chain |config| {
         let output_dir = getopts::opt_maybe_str(matches, opt_output_dir());
-        let output_dir = output_dir.map(|s| Path(*s));
+        let output_dir = output_dir.map_move(|s| Path(s));
         result::Ok(Config {
             output_dir: output_dir.unwrap_or_default(config.output_dir.clone()),
             .. config
@@ -148,8 +148,8 @@ fn config_from_opts(
     };
     let result = do result.chain |config| {
         let output_format = getopts::opt_maybe_str(matches, opt_output_format());
-        do output_format.map_default(result::Ok(config.clone())) |output_format| {
-            do parse_output_format(*output_format).chain |output_format| {
+        do output_format.map_move_default(result::Ok(config.clone())) |output_format| {
+            do parse_output_format(output_format).chain |output_format| {
                 result::Ok(Config {
                     output_format: output_format,
                     .. config.clone()
@@ -160,8 +160,8 @@ fn config_from_opts(
     let result = do result.chain |config| {
         let output_style =
             getopts::opt_maybe_str(matches, opt_output_style());
-        do output_style.map_default(result::Ok(config.clone())) |output_style| {
-            do parse_output_style(*output_style).chain |output_style| {
+        do output_style.map_move_default(result::Ok(config.clone())) |output_style| {
+            do parse_output_style(output_style).chain |output_style| {
                 result::Ok(Config {
                     output_style: output_style,
                     .. config.clone()
index 85c360a9e0dfdd8153fa103791365235687276f3..f05c59083f40f49f5288e1348b6a2a126c4a366e 100644 (file)
@@ -637,7 +637,7 @@ fn should_request_new_writer_for_each_page() {
         let doc = (page_pass::mk_pass(config::DocPerMod).f)(srv, doc);
         write_markdown(doc, writer_factory);
         // We expect two pages to have been written
-        do 2.times {
+        for _ in range(0, 2u) {
             po.recv();
         }
     }
@@ -649,7 +649,7 @@ fn should_write_title_for_each_page() {
             ~"#[link(name = \"core\")]; mod a { }");
         let doc = (page_pass::mk_pass(config::DocPerMod).f)(srv, doc);
         write_markdown(doc, writer_factory);
-        do 2.times {
+        for _ in range(0, 2u) {
             let (page, markdown) = po.recv();
             match page {
                 doc::CratePage(_) => {
index 684b4e9d198d4d1551e05418143f33b469485ce5..0d7ec34243da410e0c16f364bcdfbe6426f040a3 100644 (file)
@@ -260,9 +260,9 @@ fn fold_impl(
                 }, _) => {
                     let bounds = pprust::generics_to_str(generics, extract::interner());
                     let bounds = if bounds.is_empty() { None } else { Some(bounds) };
-                    let trait_types = opt_trait_type.map_default(~[], |p| {
+                    let trait_types = do opt_trait_type.map_default(~[]) |p| {
                         ~[pprust::path_to_str(&p.path, extract::interner())]
-                    });
+                    };
                     (bounds,
                      trait_types,
                      Some(pprust::ty_to_str(
index 86290ea65b5646f939eed20204ae3a07b79c6bc4..bb863df33481211c354b5519fb223be17cd2fe06 100644 (file)
@@ -203,7 +203,7 @@ fn run(mut program: ~Program, binary: ~str, lib_search_paths: ~[~str],
                 }
             }
         }
-        result = do blk.expr.map_consume |e| {
+        result = do blk.expr.map_move |e| {
             do with_pp(intr) |pp, _| { pprust::print_expr(pp, e); }
         };
     }
@@ -565,7 +565,10 @@ fn repl() -> Repl {
         }
     }
 
-    #[cfg(not(target_word_size = "32"))]
+    // FIXME: #7220 rusti on 32bit mac doesn't work.
+    // FIXME: #7641 rusti on 32bit linux cross compile doesn't work
+    // FIXME: #7115 re-enable once LLVM has been upgraded
+    #[cfg(thiswillneverbeacfgflag)]
     fn run_program(prog: &str) {
         let mut r = repl();
         for cmd in prog.split_iter('\n') {
@@ -574,35 +577,37 @@ fn run_program(prog: &str) {
                     "the command '%s' failed", cmd);
         }
     }
-    // FIXME: #7220 rusti on 32bit mac doesn't work
-    // FIXME: #7641 rusti on 32bit linux cross compile doesn't work
-    #[cfg(target_word_size = "32")]
     fn run_program(_: &str) {}
 
+    #[ignore]
     #[test]
     fn super_basic() {
         run_program("");
     }
 
+    #[ignore]
     #[test]
     fn regression_5937() {
         run_program("use std::hashmap;");
     }
 
+    #[ignore]
     #[test]
     fn regression_5784() {
         run_program("let a = 3;");
     }
 
-    #[test]
+    #[test] #[ignore]
     fn new_tasks() {
+        // XXX: can't spawn new tasks because the JIT code is cleaned up
+        //      after the main function is done.
         run_program("
-            use std::task::try;
-            try( || println(\"Please don't segfault\") );
-            do try { println(\"Please?\"); }
+            spawn( || println(\"Please don't segfault\") );
+            do spawn { println(\"Please?\"); }
         ");
     }
 
+    #[ignore]
     #[test]
     fn inferred_integers_usable() {
         run_program("let a = 2;\n()\n");
@@ -613,6 +618,7 @@ fn inferred_integers_usable() {
         ");
     }
 
+    #[ignore]
     #[test]
     fn local_variables_allow_shadowing() {
         run_program("
@@ -622,6 +628,7 @@ fn local_variables_allow_shadowing() {
         ");
     }
 
+    #[ignore]
     #[test]
     fn string_usable() {
         run_program("
@@ -633,6 +640,7 @@ fn string_usable() {
         ");
     }
 
+    #[ignore]
     #[test]
     fn vectors_usable() {
         run_program("
@@ -645,6 +653,7 @@ fn vectors_usable() {
         ");
     }
 
+    #[ignore]
     #[test]
     fn structs_usable() {
         run_program("
@@ -654,6 +663,7 @@ struct A{ a: int }
         ");
     }
 
+    #[ignore]
     #[test]
     fn mutable_variables_work() {
         run_program("
@@ -666,6 +676,7 @@ fn mutable_variables_work() {
         ");
     }
 
+    #[ignore]
     #[test]
     fn functions_saved() {
         run_program("
@@ -676,6 +687,7 @@ fn fib(x: int) -> int { if x < 2 {x} else { fib(x - 1) + fib(x - 2) } }
         ");
     }
 
+    #[ignore]
     #[test]
     fn modules_saved() {
         run_program("
@@ -684,6 +696,7 @@ mod b { pub fn foo() -> uint { 3 } }
         ");
     }
 
+    #[ignore]
     #[test]
     fn multiple_functions() {
         run_program("
@@ -693,6 +706,7 @@ fn f() {}
         ");
     }
 
+    #[ignore]
     #[test]
     fn multiple_items_same_name() {
         run_program("
@@ -705,6 +719,7 @@ fn f() {}
         ");
     }
 
+    #[ignore]
     #[test]
     fn simultaneous_definition_and_expression() {
         run_program("
@@ -712,6 +727,7 @@ fn simultaneous_definition_and_expression() {
         ");
     }
 
+    #[ignore]
     #[test]
     fn exit_quits() {
         let mut r = repl();
index 828be5dce12788c0495e010b1d784f15f5127ed0..9fea866212975c02335ead93f4121c9fb039d5ee 100644 (file)
@@ -998,6 +998,7 @@ fn test_rustpkg_test() {
 }
 
 #[test]
+#[ignore(reason = "test not yet implemented")]
 fn test_uninstall() {
     let workspace = create_local_package(&PkgId::new("foo", &os::getcwd()));
     let _output = command_line_test([~"info", ~"foo"], &workspace);
index 9e3a3a28fe8cef39aa0b1020d8f548ca37e8cfdb..6c3d4c5f1fbeab4d82dec81c1543d7e4eeb74939 100644 (file)
@@ -58,3 +58,15 @@ fn gt(&self, other: & &'self T) -> bool {
         *(*self) > *(*other)
     }
 }
+
+#[cfg(not(test))]
+impl<'self, T: TotalOrd> TotalOrd for &'self T {
+    #[inline]
+    fn cmp(&self, other: & &'self T) -> Ordering { (**self).cmp(*other) }
+}
+
+#[cfg(not(test))]
+impl<'self, T: TotalEq> TotalEq for &'self T {
+    #[inline]
+    fn equals(&self, other: & &'self T) -> bool { (**self).equals(*other) }
+}
index 43a632562b2b71b5db5697bf28a051c62df185e5..b66f89e83415e1b22ad0a575f950f1855057460f 100644 (file)
@@ -153,7 +153,6 @@ pub fn cmp2<A:TotalOrd,B:TotalOrd>(
 Return `o1` if it is not `Equal`, otherwise `o2`. Simulates the
 lexical ordering on a type `(int, int)`.
 */
-// used in deriving code in libsyntax
 #[inline]
 pub fn lexical_ordering(o1: Ordering, o2: Ordering) -> Ordering {
     match o1 {
index fbc471c0ae05d4b289235134ec8366d040459437..3484a5e7d6e8b084180c78feca838646a932bb81 100644 (file)
@@ -238,7 +238,7 @@ fn pop_internal(&mut self, hash: uint, k: &K) -> Option<V> {
         let len_buckets = self.buckets.len();
         let bucket = self.buckets[idx].take();
 
-        let value = do bucket.map_consume |bucket| {
+        let value = do bucket.map_move |bucket| {
             bucket.value
         };
 
@@ -479,7 +479,7 @@ pub fn consume(self) -> HashMapConsumeIterator<K, V> {
 impl<K: Hash + Eq, V: Clone> HashMap<K, V> {
     /// Like `find`, but returns a copy of the value.
     pub fn find_copy(&self, k: &K) -> Option<V> {
-        self.find(k).map_consume(|v| (*v).clone())
+        self.find(k).map_move(|v| (*v).clone())
     }
 
     /// Like `get`, but returns a copy of the value.
index 56a0dca56679ccf3a34d89038944614d0c497263..29f54bd10fba152bffdd3805c9d5aa6936400eb0 100644 (file)
@@ -18,7 +18,7 @@
 */
 
 use cmp;
-use num::{Zero, One};
+use num::{Zero, One, Saturating};
 use option::{Option, Some, None};
 use ops::{Add, Mul};
 use cmp::Ord;
@@ -313,7 +313,7 @@ fn scan<'r, St, B>(self, initial_state: St, f: &'r fn(&mut St, A) -> Option<B>)
     /// ~~~ {.rust}
     /// let xs = [2u, 3];
     /// let ys = [0u, 1, 0, 1, 2];
-    /// let mut it = xs.iter().flat_map_(|&x| Counter::new(0u, 1).take_(x));
+    /// let mut it = xs.iter().flat_map_(|&x| count(0u, 1).take_(x));
     /// // Check that `it` has the same elements as `ys`
     /// let mut i = 0;
     /// for x: uint in it {
@@ -351,7 +351,7 @@ fn flat_map_<'r, B, U: Iterator<B>>(self, f: &'r fn(A) -> U)
     /// ~~~ {.rust}
     /// use std::iterator::Counter;
     ///
-    /// for i in Counter::new(0, 10) {
+    /// for i in count(0, 10) {
     ///     printfln!("%d", i);
     /// }
     /// ~~~
@@ -674,7 +674,7 @@ fn max_by<B: Ord>(&mut self, f: &fn(&A) -> B) -> Option<A> {
                     Some((y, y_val))
                 }
             }
-        }).map_consume(|(x, _)| x)
+        }).map_move(|(x, _)| x)
     }
 
     #[inline]
@@ -689,7 +689,7 @@ fn min_by<B: Ord>(&mut self, f: &fn(&A) -> B) -> Option<A> {
                     Some((y, y_val))
                 }
             }
-        }).map_consume(|(x, _)| x)
+        }).map_move(|(x, _)| x)
     }
 }
 
@@ -723,7 +723,7 @@ pub trait MultiplicativeIterator<A> {
     /// use std::iterator::Counter;
     ///
     /// fn factorial(n: uint) -> uint {
-    ///     Counter::new(1u, 1).take_while(|&i| i <= n).product()
+    ///     count(1u, 1).take_while(|&i| i <= n).product()
     /// }
     /// assert!(factorial(0) == 1);
     /// assert!(factorial(1) == 1);
@@ -790,7 +790,7 @@ pub trait ClonableIterator {
     /// # Example
     ///
     /// ~~~ {.rust}
-    /// let a = Counter::new(1,1).take_(1);
+    /// let a = count(1,1).take_(1);
     /// let mut cy = a.cycle();
     /// assert_eq!(cy.next(), Some(1));
     /// assert_eq!(cy.next(), Some(1));
@@ -884,15 +884,10 @@ fn size_hint(&self) -> (uint, Option<uint>) {
         let (a_lower, a_upper) = self.a.size_hint();
         let (b_lower, b_upper) = self.b.size_hint();
 
-        let lower = if uint::max_value - a_lower < b_lower {
-            uint::max_value
-        } else {
-            a_lower + b_lower
-        };
+        let lower = a_lower.saturating_add(b_lower);
 
         let upper = match (a_upper, b_upper) {
-            (Some(x), Some(y)) if uint::max_value - x < y => Some(uint::max_value),
-            (Some(x), Some(y)) => Some(x + y),
+            (Some(x), Some(y)) => Some(x.saturating_add(y)),
             _ => None
         };
 
@@ -916,12 +911,7 @@ impl<A, T: RandomAccessIterator<A>, U: RandomAccessIterator<A>> RandomAccessIter
     #[inline]
     fn indexable(&self) -> uint {
         let (a, b) = (self.a.indexable(), self.b.indexable());
-        let total = a + b;
-        if total < a || total < b {
-            uint::max_value
-        } else {
-            total
-        }
+        a.saturating_add(b)
     }
 
     #[inline]
@@ -1273,11 +1263,10 @@ fn next(&mut self) -> Option<A> {
     fn size_hint(&self) -> (uint, Option<uint>) {
         let (lower, upper) = self.iter.size_hint();
 
-        let lower = if lower >= self.n { lower - self.n } else { 0 };
+        let lower = lower.saturating_sub(self.n);
 
         let upper = match upper {
-            Some(x) if x >= self.n => Some(x - self.n),
-            Some(_) => Some(0),
+            Some(x) => Some(x.saturating_sub(self.n)),
             None => None
         };
 
@@ -1288,12 +1277,7 @@ fn size_hint(&self) -> (uint, Option<uint>) {
 impl<A, T: RandomAccessIterator<A>> RandomAccessIterator<A> for Skip<T> {
     #[inline]
     fn indexable(&self) -> uint {
-        let N = self.iter.indexable();
-        if N < self.n {
-            0
-        } else {
-            N - self.n
-        }
+        self.iter.indexable().saturating_sub(self.n)
     }
 
     #[inline]
@@ -1316,10 +1300,9 @@ pub struct Take<T> {
 impl<A, T: Iterator<A>> Iterator<A> for Take<T> {
     #[inline]
     fn next(&mut self) -> Option<A> {
-        let next = self.iter.next();
         if self.n != 0 {
             self.n -= 1;
-            next
+            self.iter.next()
         } else {
             None
         }
@@ -1399,7 +1382,7 @@ fn next(&mut self) -> Option<B> {
                     return Some(x)
                 }
             }
-            match self.iter.next().map_consume(|x| (self.f)(x)) {
+            match self.iter.next().map_move(|x| (self.f)(x)) {
                 None => return self.backiter.chain_mut_ref(|it| it.next()),
                 next => self.frontiter = next,
             }
@@ -1410,9 +1393,10 @@ fn next(&mut self) -> Option<B> {
     fn size_hint(&self) -> (uint, Option<uint>) {
         let (flo, fhi) = self.frontiter.map_default((0, Some(0)), |it| it.size_hint());
         let (blo, bhi) = self.backiter.map_default((0, Some(0)), |it| it.size_hint());
+        let lo = flo.saturating_add(blo);
         match (self.iter.size_hint(), fhi, bhi) {
-            ((0, Some(0)), Some(a), Some(b)) => (flo + blo, Some(a + b)),
-            _ => (flo + blo, None)
+            ((0, Some(0)), Some(a), Some(b)) => (lo, Some(a.saturating_add(b))),
+            _ => (lo, None)
         }
     }
 }
@@ -1430,7 +1414,7 @@ fn next_back(&mut self) -> Option<B> {
                     y => return y
                 }
             }
-            match self.iter.next_back().map_consume(|x| (self.f)(x)) {
+            match self.iter.next_back().map_move(|x| (self.f)(x)) {
                 None => return self.frontiter.chain_mut_ref(|it| it.next_back()),
                 next => self.backiter = next,
             }
@@ -1527,12 +1511,10 @@ pub struct Counter<A> {
     step: A
 }
 
-impl<A> Counter<A> {
-    /// Creates a new counter with the specified start/step
-    #[inline]
-    pub fn new(start: A, step: A) -> Counter<A> {
-        Counter{state: start, step: step}
-    }
+/// Creates a new counter with the specified start/step
+#[inline]
+pub fn count<A>(start: A, step: A) -> Counter<A> {
+    Counter{state: start, step: step}
 }
 
 /// A range of numbers from [0, N)
@@ -1619,7 +1601,7 @@ mod tests {
 
     #[test]
     fn test_counter_from_iter() {
-        let mut it = Counter::new(0, 5).take_(10);
+        let mut it = count(0, 5).take_(10);
         let xs: ~[int] = FromIterator::from_iterator(&mut it);
         assert_eq!(xs, ~[0, 5, 10, 15, 20, 25, 30, 35, 40, 45]);
     }
@@ -1637,7 +1619,7 @@ fn test_iterator_chain() {
         }
         assert_eq!(i, expected.len());
 
-        let ys = Counter::new(30u, 10).take_(4);
+        let ys = count(30u, 10).take_(4);
         let mut it = xs.iter().transform(|&x| x).chain_(ys);
         let mut i = 0;
         for x in it {
@@ -1649,7 +1631,7 @@ fn test_iterator_chain() {
 
     #[test]
     fn test_filter_map() {
-        let mut it = Counter::new(0u, 1u).take_(10)
+        let mut it = count(0u, 1u).take_(10)
             .filter_map(|x| if x.is_even() { Some(x*x) } else { None });
         assert_eq!(it.collect::<~[uint]>(), ~[0*0, 2*2, 4*4, 6*6, 8*8]);
     }
@@ -1738,7 +1720,7 @@ fn add(old: &mut int, new: &uint) -> Option<float> {
     fn test_iterator_flat_map() {
         let xs = [0u, 3, 6];
         let ys = [0u, 1, 2, 3, 4, 5, 6, 7, 8];
-        let mut it = xs.iter().flat_map_(|&x| Counter::new(x, 1).take_(3));
+        let mut it = xs.iter().flat_map_(|&x| count(x, 1).take_(3));
         let mut i = 0;
         for x in it {
             assert_eq!(x, ys[i]);
@@ -1785,13 +1767,13 @@ fn count(st: &mut uint) -> Option<uint> {
     #[test]
     fn test_cycle() {
         let cycle_len = 3;
-        let it = Counter::new(0u, 1).take_(cycle_len).cycle();
+        let it = count(0u, 1).take_(cycle_len).cycle();
         assert_eq!(it.size_hint(), (uint::max_value, None));
         for (i, x) in it.take_(100).enumerate() {
             assert_eq!(i % cycle_len, x);
         }
 
-        let mut it = Counter::new(0u, 1).take_(0).cycle();
+        let mut it = count(0u, 1).take_(0).cycle();
         assert_eq!(it.size_hint(), (0, Some(0)));
         assert_eq!(it.next(), None);
     }
@@ -1853,7 +1835,7 @@ fn test_iterator_min() {
 
     #[test]
     fn test_iterator_size_hint() {
-        let c = Counter::new(0, 1);
+        let c = count(0, 1);
         let v = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
         let v2 = &[10, 11, 12];
         let vi = v.iter();
index c2a60e1c0e9c01891dd97a56a2abb09c80bf06d2..a73809d202c44c7eb64a47be72c228bc159f7e47 100644 (file)
@@ -110,16 +110,16 @@ fn test_tls_multitask() {
     set(my_key, @~"parent data");
     do task::spawn {
         // TLS shouldn't carry over.
-        assert!(get(my_key, |k| k.map(|&k| *k)).is_none());
+        assert!(get(my_key, |k| k.map_move(|k| *k)).is_none());
         set(my_key, @~"child data");
-        assert!(*(get(my_key, |k| k.map(|&k| *k)).unwrap()) ==
+        assert!(*(get(my_key, |k| k.map_move(|k| *k)).unwrap()) ==
                 ~"child data");
         // should be cleaned up for us
     }
     // Must work multiple times
-    assert!(*(get(my_key, |k| k.map(|&k| *k)).unwrap()) == ~"parent data");
-    assert!(*(get(my_key, |k| k.map(|&k| *k)).unwrap()) == ~"parent data");
-    assert!(*(get(my_key, |k| k.map(|&k| *k)).unwrap()) == ~"parent data");
+    assert!(*(get(my_key, |k| k.map_move(|k| *k)).unwrap()) == ~"parent data");
+    assert!(*(get(my_key, |k| k.map_move(|k| *k)).unwrap()) == ~"parent data");
+    assert!(*(get(my_key, |k| k.map_move(|k| *k)).unwrap()) == ~"parent data");
 }
 
 #[test]
@@ -127,7 +127,7 @@ fn test_tls_overwrite() {
     static my_key: Key<@~str> = &Key;
     set(my_key, @~"first data");
     set(my_key, @~"next data"); // Shouldn't leak.
-    assert!(*(get(my_key, |k| k.map(|&k| *k)).unwrap()) == ~"next data");
+    assert!(*(get(my_key, |k| k.map_move(|k| *k)).unwrap()) == ~"next data");
 }
 
 #[test]
index bd4dc69537cb10c9969e19c0b5dc942af3383197..57230b2fd247d4e86d9a844dc6bc39c798056378 100644 (file)
@@ -12,7 +12,7 @@
 
 use ptr::to_unsafe_ptr;
 
-#[cfg(not(test))] use cmp::{Eq, Ord};
+#[cfg(not(test))] use cmp::*;
 
 pub static RC_MANAGED_UNIQUE : uint = (-2) as uint;
 pub static RC_IMMORTAL : uint = 0x77777777;
@@ -71,6 +71,29 @@ fn ge(&self, other: &@mut T) -> bool { *(*self) >= *(*other) }
     fn gt(&self, other: &@mut T) -> bool { *(*self) > *(*other) }
 }
 
+#[cfg(not(test))]
+impl<T: TotalOrd> TotalOrd for @T {
+    #[inline]
+    fn cmp(&self, other: &@T) -> Ordering { (**self).cmp(*other) }
+}
+
+#[cfg(not(test))]
+impl<T: TotalOrd> TotalOrd for @mut T {
+    #[inline]
+    fn cmp(&self, other: &@mut T) -> Ordering { (**self).cmp(*other) }
+}
+
+#[cfg(not(test))]
+impl<T: TotalEq> TotalEq for @T {
+    #[inline]
+    fn equals(&self, other: &@T) -> bool { (**self).equals(*other) }
+}
+
+#[cfg(not(test))]
+impl<T: TotalEq> TotalEq for @mut T {
+    #[inline]
+    fn equals(&self, other: &@mut T) -> bool { (**self).equals(*other) }
+}
 #[test]
 fn test() {
     let x = @3;
index 8b61a8a8734b9fb8f8df49193bc51db5756c5e56..bbadf1caca2413c4570460ac9040d28cc1940554 100644 (file)
@@ -466,6 +466,56 @@ fn zero() -> ~T { ~Zero::zero() }
     fn is_zero(&self) -> bool { (**self).is_zero() }
 }
 
+/// Saturating math operations
+pub trait Saturating: Int {
+    /// Saturating addition operator.
+    /// Returns a+b, saturating at the numeric bounds instead of overflowing.
+    #[inline]
+    fn saturating_add(self, v: Self) -> Self {
+        let x = self + v;
+        if v >= Zero::zero() {
+            if x < self {
+                // overflow
+                Bounded::max_value::<Self>()
+            } else { x }
+        } else {
+            if x > self {
+                // underflow
+                Bounded::min_value::<Self>()
+            } else { x }
+        }
+    }
+
+    /// Saturating subtraction operator.
+    /// Returns a-b, saturating at the numeric bounds instead of overflowing.
+    #[inline]
+    fn saturating_sub(self, v: Self) -> Self {
+        let x = self - v;
+        if v >= Zero::zero() {
+            if x > self {
+                // underflow
+                Bounded::min_value::<Self>()
+            } else { x }
+        } else {
+            if x < self {
+                // overflow
+                Bounded::max_value::<Self>()
+            } else { x }
+        }
+    }
+}
+
+impl Saturating for int {}
+impl Saturating for i8 {}
+impl Saturating for i16 {}
+impl Saturating for i32 {}
+impl Saturating for i64 {}
+impl Saturating for uint {}
+impl Saturating for u8 {}
+impl Saturating for u16 {}
+impl Saturating for u32 {}
+impl Saturating for u64 {}
+
 /// Helper function for testing numeric operations
 #[cfg(test)]
 pub fn test_num<T:Num + NumCast>(ten: T, two: T) {
@@ -482,64 +532,111 @@ pub fn test_num<T:Num + NumCast>(ten: T, two: T) {
     assert_eq!(ten.rem(&two),  ten % two);
 }
 
-macro_rules! test_cast_20(
-    ($_20:expr) => ({
-        let _20 = $_20;
-
-        assert_eq!(20u,   _20.to_uint());
-        assert_eq!(20u8,  _20.to_u8());
-        assert_eq!(20u16, _20.to_u16());
-        assert_eq!(20u32, _20.to_u32());
-        assert_eq!(20u64, _20.to_u64());
-        assert_eq!(20i,   _20.to_int());
-        assert_eq!(20i8,  _20.to_i8());
-        assert_eq!(20i16, _20.to_i16());
-        assert_eq!(20i32, _20.to_i32());
-        assert_eq!(20i64, _20.to_i64());
-        assert_eq!(20f,   _20.to_float());
-        assert_eq!(20f32, _20.to_f32());
-        assert_eq!(20f64, _20.to_f64());
-
-        assert_eq!(_20, NumCast::from(20u));
-        assert_eq!(_20, NumCast::from(20u8));
-        assert_eq!(_20, NumCast::from(20u16));
-        assert_eq!(_20, NumCast::from(20u32));
-        assert_eq!(_20, NumCast::from(20u64));
-        assert_eq!(_20, NumCast::from(20i));
-        assert_eq!(_20, NumCast::from(20i8));
-        assert_eq!(_20, NumCast::from(20i16));
-        assert_eq!(_20, NumCast::from(20i32));
-        assert_eq!(_20, NumCast::from(20i64));
-        assert_eq!(_20, NumCast::from(20f));
-        assert_eq!(_20, NumCast::from(20f32));
-        assert_eq!(_20, NumCast::from(20f64));
-
-        assert_eq!(_20, cast(20u));
-        assert_eq!(_20, cast(20u8));
-        assert_eq!(_20, cast(20u16));
-        assert_eq!(_20, cast(20u32));
-        assert_eq!(_20, cast(20u64));
-        assert_eq!(_20, cast(20i));
-        assert_eq!(_20, cast(20i8));
-        assert_eq!(_20, cast(20i16));
-        assert_eq!(_20, cast(20i32));
-        assert_eq!(_20, cast(20i64));
-        assert_eq!(_20, cast(20f));
-        assert_eq!(_20, cast(20f32));
-        assert_eq!(_20, cast(20f64));
-    })
-)
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    macro_rules! test_cast_20(
+        ($_20:expr) => ({
+            let _20 = $_20;
+
+            assert_eq!(20u,   _20.to_uint());
+            assert_eq!(20u8,  _20.to_u8());
+            assert_eq!(20u16, _20.to_u16());
+            assert_eq!(20u32, _20.to_u32());
+            assert_eq!(20u64, _20.to_u64());
+            assert_eq!(20i,   _20.to_int());
+            assert_eq!(20i8,  _20.to_i8());
+            assert_eq!(20i16, _20.to_i16());
+            assert_eq!(20i32, _20.to_i32());
+            assert_eq!(20i64, _20.to_i64());
+            assert_eq!(20f,   _20.to_float());
+            assert_eq!(20f32, _20.to_f32());
+            assert_eq!(20f64, _20.to_f64());
+
+            assert_eq!(_20, NumCast::from(20u));
+            assert_eq!(_20, NumCast::from(20u8));
+            assert_eq!(_20, NumCast::from(20u16));
+            assert_eq!(_20, NumCast::from(20u32));
+            assert_eq!(_20, NumCast::from(20u64));
+            assert_eq!(_20, NumCast::from(20i));
+            assert_eq!(_20, NumCast::from(20i8));
+            assert_eq!(_20, NumCast::from(20i16));
+            assert_eq!(_20, NumCast::from(20i32));
+            assert_eq!(_20, NumCast::from(20i64));
+            assert_eq!(_20, NumCast::from(20f));
+            assert_eq!(_20, NumCast::from(20f32));
+            assert_eq!(_20, NumCast::from(20f64));
+
+            assert_eq!(_20, cast(20u));
+            assert_eq!(_20, cast(20u8));
+            assert_eq!(_20, cast(20u16));
+            assert_eq!(_20, cast(20u32));
+            assert_eq!(_20, cast(20u64));
+            assert_eq!(_20, cast(20i));
+            assert_eq!(_20, cast(20i8));
+            assert_eq!(_20, cast(20i16));
+            assert_eq!(_20, cast(20i32));
+            assert_eq!(_20, cast(20i64));
+            assert_eq!(_20, cast(20f));
+            assert_eq!(_20, cast(20f32));
+            assert_eq!(_20, cast(20f64));
+        })
+    )
+
+    #[test] fn test_u8_cast()    { test_cast_20!(20u8)  }
+    #[test] fn test_u16_cast()   { test_cast_20!(20u16) }
+    #[test] fn test_u32_cast()   { test_cast_20!(20u32) }
+    #[test] fn test_u64_cast()   { test_cast_20!(20u64) }
+    #[test] fn test_uint_cast()  { test_cast_20!(20u)   }
+    #[test] fn test_i8_cast()    { test_cast_20!(20i8)  }
+    #[test] fn test_i16_cast()   { test_cast_20!(20i16) }
+    #[test] fn test_i32_cast()   { test_cast_20!(20i32) }
+    #[test] fn test_i64_cast()   { test_cast_20!(20i64) }
+    #[test] fn test_int_cast()   { test_cast_20!(20i)   }
+    #[test] fn test_f32_cast()   { test_cast_20!(20f32) }
+    #[test] fn test_f64_cast()   { test_cast_20!(20f64) }
+    #[test] fn test_float_cast() { test_cast_20!(20f)   }
+
+    #[test]
+    fn test_saturating_add_uint() {
+        use uint::max_value;
+        assert_eq!(3u.saturating_add(5u), 8u);
+        assert_eq!(3u.saturating_add(max_value-1), max_value);
+        assert_eq!(max_value.saturating_add(max_value), max_value);
+        assert_eq!((max_value-2).saturating_add(1), max_value-1);
+    }
+
+    #[test]
+    fn test_saturating_sub_uint() {
+        use uint::max_value;
+        assert_eq!(5u.saturating_sub(3u), 2u);
+        assert_eq!(3u.saturating_sub(5u), 0u);
+        assert_eq!(0u.saturating_sub(1u), 0u);
+        assert_eq!((max_value-1).saturating_sub(max_value), 0);
+    }
 
-#[test] fn test_u8_cast()    { test_cast_20!(20u8)  }
-#[test] fn test_u16_cast()   { test_cast_20!(20u16) }
-#[test] fn test_u32_cast()   { test_cast_20!(20u32) }
-#[test] fn test_u64_cast()   { test_cast_20!(20u64) }
-#[test] fn test_uint_cast()  { test_cast_20!(20u)   }
-#[test] fn test_i8_cast()    { test_cast_20!(20i8)  }
-#[test] fn test_i16_cast()   { test_cast_20!(20i16) }
-#[test] fn test_i32_cast()   { test_cast_20!(20i32) }
-#[test] fn test_i64_cast()   { test_cast_20!(20i64) }
-#[test] fn test_int_cast()   { test_cast_20!(20i)   }
-#[test] fn test_f32_cast()   { test_cast_20!(20f32) }
-#[test] fn test_f64_cast()   { test_cast_20!(20f64) }
-#[test] fn test_float_cast() { test_cast_20!(20f)   }
+    #[test]
+    fn test_saturating_add_int() {
+        use int::{min_value,max_value};
+        assert_eq!(3i.saturating_add(5i), 8i);
+        assert_eq!(3i.saturating_add(max_value-1), max_value);
+        assert_eq!(max_value.saturating_add(max_value), max_value);
+        assert_eq!((max_value-2).saturating_add(1), max_value-1);
+        assert_eq!(3i.saturating_add(-5i), -2i);
+        assert_eq!(min_value.saturating_add(-1i), min_value);
+        assert_eq!((-2i).saturating_add(-max_value), min_value);
+    }
+
+    #[test]
+    fn test_saturating_sub_int() {
+        use int::{min_value,max_value};
+        assert_eq!(3i.saturating_sub(5i), -2i);
+        assert_eq!(min_value.saturating_sub(1i), min_value);
+        assert_eq!((-2i).saturating_sub(max_value), min_value);
+        assert_eq!(3i.saturating_sub(-5i), 8i);
+        assert_eq!(3i.saturating_sub(-(max_value-1)), max_value);
+        assert_eq!(max_value.saturating_sub(-max_value), max_value);
+        assert_eq!((max_value-2).saturating_sub(-1), max_value-1);
+    }
+}
index ea1bddcdb4b9d60aba0138494219519e120d5317..66b30d8dd031c288eb2200fd4f35d69553f5a35b 100644 (file)
@@ -208,6 +208,12 @@ pub fn map_mut<'a, U>(&'a mut self, f: &fn(&'a mut T) -> U) -> Option<U> {
         match *self { Some(ref mut x) => Some(f(x)), None => None }
     }
 
+    /// Applies a function to the contained value or returns a default
+    #[inline]
+    pub fn map_default<'a, U>(&'a self, def: U, f: &fn(&'a T) -> U) -> U {
+        match *self { None => def, Some(ref t) => f(t) }
+    }
+
     /// Maps a `Some` value from one type to another by a mutable reference,
     /// or returns a default value.
     #[inline]
@@ -218,21 +224,15 @@ pub fn map_mut_default<'a, U>(&'a mut self, def: U, f: &fn(&'a mut T) -> U) -> U
     /// As `map`, but consumes the option and gives `f` ownership to avoid
     /// copying.
     #[inline]
-    pub fn map_consume<U>(self, f: &fn(v: T) -> U) -> Option<U> {
-        match self { None => None, Some(v) => Some(f(v)) }
-    }
-
-    /// Applies a function to the contained value or returns a default
-    #[inline]
-    pub fn map_default<'a, U>(&'a self, def: U, f: &fn(&'a T) -> U) -> U {
-        match *self { None => def, Some(ref t) => f(t) }
+    pub fn map_move<U>(self, f: &fn(T) -> U) -> Option<U> {
+        match self { Some(x) => Some(f(x)), None => None }
     }
 
     /// As `map_default`, but consumes the option and gives `f`
     /// ownership to avoid copying.
     #[inline]
-    pub fn map_consume_default<U>(self, def: U, f: &fn(v: T) -> U) -> U {
-        match self { None => def, Some(v) => f(v) }
+    pub fn map_move_default<U>(self, def: U, f: &fn(T) -> U) -> U {
+        match self { None => def, Some(t) => f(t) }
     }
 
     /// Take the value out of the option, leaving a `None` in its place.
@@ -241,20 +241,6 @@ pub fn take(&mut self) -> Option<T> {
         util::replace(self, None)
     }
 
-    /// As `map_consume`, but swaps a None into the original option rather
-    /// than consuming it by-value.
-    #[inline]
-    pub fn take_map<U>(&mut self, blk: &fn(T) -> U) -> Option<U> {
-        self.take().map_consume(blk)
-    }
-
-    /// As `map_consume_default`, but swaps a None into the original option
-    /// rather than consuming it by-value.
-    #[inline]
-    pub fn take_map_default<U> (&mut self, def: U, blk: &fn(T) -> U) -> U {
-        self.take().map_consume_default(def, blk)
-    }
-
     /// Apply a function to the contained value or do nothing.
     /// Returns true if the contained value was mutated.
     pub fn mutate(&mut self, f: &fn(T) -> T) -> bool {
index b0e1f35b4a018a6c8237b29b7ca4b06c15741306..f246a61a4d580d8308aaa93e0885a37a6842a7f5 100644 (file)
@@ -498,9 +498,7 @@ fn load_self() -> Option<~str> {
         }
     }
 
-    do load_self().map |pth| {
-        Path(*pth).dir_path()
-    }
+    load_self().map_move(|path| Path(path).dir_path())
 }
 
 
index e7a6e38fdb08874d5474806d66f346a9167e75ca..424c4fd6b2f44d0e4f4102e04e1827a62f667670 100644 (file)
@@ -10,7 +10,7 @@
 
 //! Operations on unique pointer types
 
-#[cfg(not(test))] use cmp::{Eq, Ord};
+#[cfg(not(test))] use cmp::*;
 
 #[cfg(not(test))]
 impl<T:Eq> Eq for ~T {
@@ -31,3 +31,15 @@ fn ge(&self, other: &~T) -> bool { *(*self) >= *(*other) }
     #[inline]
     fn gt(&self, other: &~T) -> bool { *(*self) > *(*other) }
 }
+
+#[cfg(not(test))]
+impl<T: TotalOrd> TotalOrd for ~T {
+    #[inline]
+    fn cmp(&self, other: &~T) -> Ordering { (**self).cmp(*other) }
+}
+
+#[cfg(not(test))]
+impl<T: TotalEq> TotalEq for ~T {
+    #[inline]
+    fn equals(&self, other: &~T) -> bool { (**self).equals(*other) }
+}
index 517bc4a441a68df454edf042fe1209404c434abd..65db55297b3b70e673146e74b19f2c58d3121d52 100644 (file)
@@ -49,6 +49,7 @@
 pub use container::{Container, Mutable, Map, MutableMap, Set, MutableSet};
 pub use hash::Hash;
 pub use iter::Times;
+pub use iterator::Extendable;
 pub use iterator::{Iterator, IteratorUtil, DoubleEndedIterator, DoubleEndedIteratorUtil};
 pub use iterator::{ClonableIterator, OrdIterator};
 pub use num::{Num, NumCast};
@@ -64,7 +65,7 @@
 pub use ptr::RawPtr;
 pub use ascii::{Ascii, AsciiCast, OwnedAsciiCast, AsciiStr, ToBytesConsume};
 pub use str::{Str, StrVector, StrSlice, OwnedStr, NullTerminatedStr};
-pub use from_str::{FromStr};
+pub use from_str::FromStr;
 pub use to_bytes::IterBytes;
 pub use to_str::{ToStr, ToStrConsume};
 pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps};
index dfd11f9227d413e5b37725b91a34e54d024f3eea..5a2bd0c4de9cea8e88cd256c87100c1eb42650d0 100644 (file)
@@ -272,6 +272,7 @@ pub trait RawPtr<T> {
     fn is_not_null(&self) -> bool;
     unsafe fn to_option(&self) -> Option<&T>;
     fn offset(&self, count: int) -> Self;
+    unsafe fn offset_inbounds(self, count: int) -> Self;
 }
 
 /// Extension methods for immutable pointers
@@ -304,6 +305,22 @@ unsafe fn to_option(&self) -> Option<&T> {
     /// Calculates the offset from a pointer.
     #[inline]
     fn offset(&self, count: int) -> *T { offset(*self, count) }
+
+    /// Calculates the offset from a pointer. The offset *must* be in-bounds of
+    /// the object, or one-byte-past-the-end.
+    #[inline]
+    #[cfg(stage0)]
+    unsafe fn offset_inbounds(self, count: int) -> *T {
+        intrinsics::offset(self, count)
+    }
+
+    /// Calculates the offset from a pointer. The offset *must* be in-bounds of
+    /// the object, or one-byte-past-the-end.
+    #[inline]
+    #[cfg(not(stage0))]
+    unsafe fn offset_inbounds(self, count: int) -> *T {
+        intrinsics::offset_inbounds(self, count)
+    }
 }
 
 /// Extension methods for mutable pointers
@@ -336,6 +353,30 @@ unsafe fn to_option(&self) -> Option<&T> {
     /// Calculates the offset from a mutable pointer.
     #[inline]
     fn offset(&self, count: int) -> *mut T { mut_offset(*self, count) }
+
+    /// Calculates the offset from a pointer. The offset *must* be in-bounds of
+    /// the object, or one-byte-past-the-end. An arithmetic overflow is also
+    /// undefined behaviour.
+    ///
+    /// This method should be preferred over `offset` when the guarantee can be
+    /// satisfied, to enable better optimization.
+    #[inline]
+    #[cfg(stage0)]
+    unsafe fn offset_inbounds(self, count: int) -> *mut T {
+        intrinsics::offset(self as *T, count) as *mut T
+    }
+
+    /// Calculates the offset from a pointer. The offset *must* be in-bounds of
+    /// the object, or one-byte-past-the-end. An arithmetic overflow is also
+    /// undefined behaviour.
+    ///
+    /// This method should be preferred over `offset` when the guarantee can be
+    /// satisfied, to enable better optimization.
+    #[inline]
+    #[cfg(not(stage0))]
+    unsafe fn offset_inbounds(self, count: int) -> *mut T {
+        intrinsics::offset_inbounds(self as *T, count) as *mut T
+    }
 }
 
 // Equality for pointers
index 91f42edf0aecd46e33efafc41fa7fccf43032be4..3e429c6116d4c60d2c7aa191170405433b158593 100644 (file)
@@ -149,6 +149,40 @@ pub fn expect_err(self, reason: &str) -> E {
         }
     }
 
+    /// Call a method based on a previous result
+    ///
+    /// If `self` is `Ok` then the value is extracted and passed to `op`
+    /// whereupon `op`s result is wrapped in `Ok` and returned. if `self` is
+    /// `Err` then it is immediately returned.  This function can be used to
+    /// compose the results of two functions.
+    ///
+    /// Example:
+    ///
+    ///     let res = do read_file(file).map_move |buf| {
+    ///         parse_bytes(buf)
+    ///     }
+    #[inline]
+    pub fn map_move<U>(self, op: &fn(T) -> U) -> Result<U,E> {
+        match self {
+          Ok(t) => Ok(op(t)),
+          Err(e) => Err(e)
+        }
+    }
+
+    /// Call a method based on a previous result
+    ///
+    /// If `self` is `Err` then the value is extracted and passed to `op`
+    /// whereupon `op`s result is wrapped in an `Err` and returned. if `self` is
+    /// `Ok` then it is immediately returned.  This function can be used to pass
+    /// through a successful result while handling an error.
+    #[inline]
+    pub fn map_err_move<F>(self, op: &fn(E) -> F) -> Result<T,F> {
+        match self {
+          Ok(t) => Ok(t),
+          Err(e) => Err(op(e))
+        }
+    }
+
     /// Call a method based on a previous result
     ///
     /// If `self` is `Ok` then the value is extracted and passed to `op`
@@ -312,7 +346,9 @@ pub fn iter_vec2<S, T, U: ToStr>(ss: &[S], ts: &[T],
 #[cfg(test)]
 mod tests {
     use super::*;
+
     use either;
+    use str::OwnedStr;
 
     pub fn op1() -> Result<int, ~str> { Ok(666) }
 
@@ -359,14 +395,26 @@ pub fn test_impl_iter_err() {
 
     #[test]
     pub fn test_impl_map() {
-        assert_eq!(Ok::<~str, ~str>(~"a").map(|_x| ~"b"), Ok(~"b"));
-        assert_eq!(Err::<~str, ~str>(~"a").map(|_x| ~"b"), Err(~"a"));
+        assert_eq!(Ok::<~str, ~str>(~"a").map(|x| (~"b").append(*x)), Ok(~"ba"));
+        assert_eq!(Err::<~str, ~str>(~"a").map(|x| (~"b").append(*x)), Err(~"a"));
     }
 
     #[test]
     pub fn test_impl_map_err() {
-        assert_eq!(Ok::<~str, ~str>(~"a").map_err(|_x| ~"b"), Ok(~"a"));
-        assert_eq!(Err::<~str, ~str>(~"a").map_err(|_x| ~"b"), Err(~"b"));
+        assert_eq!(Ok::<~str, ~str>(~"a").map_err(|x| (~"b").append(*x)), Ok(~"a"));
+        assert_eq!(Err::<~str, ~str>(~"a").map_err(|x| (~"b").append(*x)), Err(~"ba"));
+    }
+
+    #[test]
+    pub fn test_impl_map_move() {
+        assert_eq!(Ok::<~str, ~str>(~"a").map_move(|x| x + "b"), Ok(~"ab"));
+        assert_eq!(Err::<~str, ~str>(~"a").map_move(|x| x + "b"), Err(~"a"));
+    }
+
+    #[test]
+    pub fn test_impl_map_err_move() {
+        assert_eq!(Ok::<~str, ~str>(~"a").map_err_move(|x| x + "b"), Ok(~"a"));
+        assert_eq!(Err::<~str, ~str>(~"a").map_err_move(|x| x + "b"), Err(~"ab"));
     }
 
     #[test]
index a060059f5fc9339b9ba2af58288d8a5a461c6358..0cf223f3029134cee4d535498d78352cb7edbe1e 100644 (file)
@@ -159,7 +159,7 @@ fn try_send_inner(self, val: T, do_resched: bool) -> bool {
                     // Port is blocked. Wake it up.
                     let recvr = BlockedTask::cast_from_uint(task_as_state);
                     if do_resched {
-                        do recvr.wake().map_consume |woken_task| {
+                        do recvr.wake().map_move |woken_task| {
                             Scheduler::run_task(woken_task);
                         };
                     } else {
@@ -381,7 +381,7 @@ fn drop(&self) {
                     // The port is blocked waiting for a message we will never send. Wake it.
                     assert!((*this.packet()).payload.is_none());
                     let recvr = BlockedTask::cast_from_uint(task_as_state);
-                    do recvr.wake().map_consume |woken_task| {
+                    do recvr.wake().map_move |woken_task| {
                         Scheduler::run_task(woken_task);
                     };
                 }
index 1d7ff17314901bf50093e8cdeecef254c22a3017..6e671742fb6fdfa7fd8c8c71b8ed58fcbd34faca 100644 (file)
 
 //! Runtime environment settings
 
+use from_str::FromStr;
 use libc::{size_t, c_char, c_int};
+use option::{Some, None};
+use os;
+
+// OLD RT stuff
 
 pub struct Environment {
     /// The number of threads to use by default
@@ -47,3 +52,26 @@ pub fn get() -> &Environment {
 extern {
     fn rust_get_rt_env() -> &Environment;
 }
+
+// NEW RT stuff
+
+// Note that these are all accessed without any synchronization.
+// They are expected to be initialized once then left alone.
+
+static mut MIN_STACK: uint = 2000000;
+
+pub fn init() {
+    unsafe {
+        match os::getenv("RUST_MIN_STACK") {
+            Some(s) => match FromStr::from_str(s) {
+                Some(i) => MIN_STACK = i,
+                None => ()
+            },
+            None => ()
+        }
+    }
+}
+
+pub fn min_stack() -> uint {
+    unsafe { MIN_STACK }
+}
index 3372c13b87703a72cdef5af13fa5b651cc2379fc..fbc9d1d2445af997b58d612857de884fe07dd507 100644 (file)
@@ -402,10 +402,10 @@ pub fn reparent_children_to(self, parent: &mut KillHandle) {
                     || {
                         // Prefer to check tombstones that were there first,
                         // being "more fair" at the expense of tail-recursion.
-                        others.take().map_consume_default(true, |f| f()) && {
+                        others.take().map_move_default(true, |f| f()) && {
                             let mut inner = this.take().unwrap();
                             (!inner.any_child_failed) &&
-                                inner.child_tombstones.take_map_default(true, |f| f())
+                                inner.child_tombstones.take().map_move_default(true, |f| f())
                         }
                     }
                 }
@@ -424,7 +424,7 @@ pub fn reparent_children_to(self, parent: &mut KillHandle) {
                     let others = Cell::new(other_tombstones); // :(
                     || {
                         // Prefer fairness to tail-recursion, as in above case.
-                        others.take().map_consume_default(true, |f| f()) &&
+                        others.take().map_move_default(true, |f| f()) &&
                             f.take()()
                     }
                 }
@@ -493,7 +493,7 @@ pub fn collect_failure(&mut self, mut success: bool, group: Option<Taskgroup>) {
         { use util; util::ignore(group); }
 
         // Step 1. Decide if we need to collect child failures synchronously.
-        do self.on_exit.take_map |on_exit| {
+        do self.on_exit.take().map_move |on_exit| {
             if success {
                 // We succeeded, but our children might not. Need to wait for them.
                 let mut inner = self.kill_handle.take_unwrap().unwrap();
@@ -501,7 +501,7 @@ pub fn collect_failure(&mut self, mut success: bool, group: Option<Taskgroup>) {
                     success = false;
                 } else {
                     // Lockless access to tombstones protected by unwrap barrier.
-                    success = inner.child_tombstones.take_map_default(true, |f| f());
+                    success = inner.child_tombstones.take().map_move_default(true, |f| f());
                 }
             }
             on_exit(success);
@@ -510,12 +510,12 @@ pub fn collect_failure(&mut self, mut success: bool, group: Option<Taskgroup>) {
         // Step 2. Possibly alert possibly-watching parent to failure status.
         // Note that as soon as parent_handle goes out of scope, the parent
         // can successfully unwrap its handle and collect our reported status.
-        do self.watching_parent.take_map |mut parent_handle| {
+        do self.watching_parent.take().map_move |mut parent_handle| {
             if success {
                 // Our handle might be None if we had an exit callback, and
                 // already unwrapped it. But 'success' being true means no
                 // child failed, so there's nothing to do (see below case).
-                do self.kill_handle.take_map |own_handle| {
+                do self.kill_handle.take().map_move |own_handle| {
                     own_handle.reparent_children_to(&mut parent_handle);
                 };
             } else {
@@ -614,6 +614,7 @@ mod test {
     // Test cases don't care about the spare killed flag.
     fn make_kill_handle() -> KillHandle { let (h,_) = KillHandle::new(); h }
 
+    #[ignore(reason = "linked failure")]
     #[test]
     fn no_tombstone_success() {
         do run_in_newsched_task {
@@ -819,6 +820,7 @@ fn block_and_wake() {
         }
     }
 
+    #[ignore(reason = "linked failure")]
     #[test]
     fn block_and_get_killed() {
         do with_test_task |mut task| {
@@ -830,6 +832,7 @@ fn block_and_get_killed() {
         }
     }
 
+    #[ignore(reason = "linked failure")]
     #[test]
     fn block_already_killed() {
         do with_test_task |mut task| {
@@ -839,6 +842,7 @@ fn block_already_killed() {
         }
     }
 
+    #[ignore(reason = "linked failure")]
     #[test]
     fn block_unkillably_and_get_killed() {
         do with_test_task |mut task| {
@@ -856,6 +860,7 @@ fn block_unkillably_and_get_killed() {
         }
     }
 
+    #[ignore(reason = "linked failure")]
     #[test]
     fn block_on_pipe() {
         // Tests the "killable" path of casting to/from uint.
@@ -869,6 +874,7 @@ fn block_on_pipe() {
         }
     }
 
+    #[ignore(reason = "linked failure")]
     #[test]
     fn block_unkillably_on_pipe() {
         // Tests the "indestructible" path of casting to/from uint.
index 131507196b1f2558e61d6d7276ba1ca613f827c3..7154066e7b748f4e6196567301986c766755e2bd 100644 (file)
@@ -126,6 +126,7 @@ unsafe fn try_unsafe_borrow() -> Option<*mut IoFactoryObject> { rtabort!("unimpl
 
 #[cfg(test)]
 mod test {
+    use option::None;
     use unstable::run_in_bare_thread;
     use rt::test::*;
     use super::*;
@@ -137,7 +138,7 @@ fn thread_local_task_smoke_test() {
         do run_in_bare_thread {
             local_ptr::init_tls_key();
             let mut sched = ~new_test_uv_sched();
-            let task = ~Task::new_root(&mut sched.stack_pool, || {});
+            let task = ~Task::new_root(&mut sched.stack_pool, None, || {});
             Local::put(task);
             let task: ~Task = Local::take();
             cleanup_task(task);
@@ -149,11 +150,11 @@ fn thread_local_task_two_instances() {
         do run_in_bare_thread {
             local_ptr::init_tls_key();
             let mut sched = ~new_test_uv_sched();
-            let task = ~Task::new_root(&mut sched.stack_pool, || {});
+            let task = ~Task::new_root(&mut sched.stack_pool, None, || {});
             Local::put(task);
             let task: ~Task = Local::take();
             cleanup_task(task);
-            let task = ~Task::new_root(&mut sched.stack_pool, || {});
+            let task = ~Task::new_root(&mut sched.stack_pool, None, || {});
             Local::put(task);
             let task: ~Task = Local::take();
             cleanup_task(task);
@@ -166,7 +167,7 @@ fn borrow_smoke_test() {
         do run_in_bare_thread {
             local_ptr::init_tls_key();
             let mut sched = ~new_test_uv_sched();
-            let task = ~Task::new_root(&mut sched.stack_pool, || {});
+            let task = ~Task::new_root(&mut sched.stack_pool, None, || {});
             Local::put(task);
 
             unsafe {
@@ -182,7 +183,7 @@ fn borrow_with_return() {
         do run_in_bare_thread {
             local_ptr::init_tls_key();
             let mut sched = ~new_test_uv_sched();
-            let task = ~Task::new_root(&mut sched.stack_pool, || {});
+            let task = ~Task::new_root(&mut sched.stack_pool, None, || {});
             Local::put(task);
 
             let res = do Local::borrow::<Task,bool> |_task| {
index 760ca8a9adadcbae741cce4423728ffd6ea3e75e..147c75e5c41ef1bc47fdc7a358799c9588acb3bf 100644 (file)
@@ -212,6 +212,7 @@ pub fn init(argc: int, argv: **u8, crate_map: *u8) {
     // Need to propagate the unsafety to `start`.
     unsafe {
         args::init(argc, argv);
+        env::init();
         logging::init(crate_map);
         rust_update_gc_metadata(crate_map);
     }
@@ -330,8 +331,7 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int {
         // In the case where we do not use a main_thread scheduler we
         // run the main task in one of our threads.
 
-        let mut main_task = ~Task::new_root(&mut scheds[0].stack_pool,
-                                            main.take());
+        let mut main_task = ~Task::new_root(&mut scheds[0].stack_pool, None, main.take());
         main_task.death.on_exit = Some(on_exit.take());
         let main_task_cell = Cell::new(main_task);
 
@@ -351,7 +351,7 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int {
         let sched_cell = Cell::new(sched);
         let thread = do Thread::start {
             let mut sched = sched_cell.take();
-            let bootstrap_task = ~do Task::new_root(&mut sched.stack_pool) || {
+            let bootstrap_task = ~do Task::new_root(&mut sched.stack_pool, None) || {
                 rtdebug!("boostraping a non-primary scheduler");
             };
             sched.bootstrap(bootstrap_task);
@@ -368,7 +368,7 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int {
         let mut main_sched = main_sched.unwrap();
 
         let home = Sched(main_sched.make_handle());
-        let mut main_task = ~Task::new_root_homed(&mut main_sched.stack_pool,
+        let mut main_task = ~Task::new_root_homed(&mut main_sched.stack_pool, None,
                                                   home, main.take());
         main_task.death.on_exit = Some(on_exit.take());
         rtdebug!("boostrapping main_task");
index 1a75f2569b59ea073303e18ca98451ac2cae0004..990e1a4a3de9915cb65355119d555b7a9e55fe3f 100644 (file)
@@ -325,7 +325,7 @@ pub fn enqueue_task(&mut self, task: ~Task) {
     /// As enqueue_task, but with the possibility for the blocked task to
     /// already have been killed.
     pub fn enqueue_blocked_task(&mut self, blocked_task: BlockedTask) {
-        do blocked_task.wake().map_consume |task| {
+        do blocked_task.wake().map_move |task| {
             self.enqueue_task(task);
         };
     }
@@ -533,7 +533,7 @@ pub fn run_task(task: ~Task) {
                 sched.enqueue_blocked_task(last_task);
             }
         };
-        opt.map_consume(Local::put);
+        opt.map_move(Local::put);
     }
 
     // The primary function for changing contexts. In the current
@@ -833,7 +833,7 @@ fn test_home_sched() {
             let mut sched = ~new_test_uv_sched();
             let sched_handle = sched.make_handle();
 
-            let mut task = ~do Task::new_root_homed(&mut sched.stack_pool,
+            let mut task = ~do Task::new_root_homed(&mut sched.stack_pool, None,
                                                 Sched(sched_handle)) {
                 unsafe { *task_ran_ptr = true };
                 assert!(Task::on_appropriate_sched());
@@ -893,21 +893,21 @@ fn test_schedule_home_states() {
             //   3) task not homed, sched requeues
             //   4) task not home, send home
 
-            let task1 = ~do Task::new_root_homed(&mut special_sched.stack_pool,
+            let task1 = ~do Task::new_root_homed(&mut special_sched.stack_pool, None,
                                                  Sched(t1_handle)) || {
                 rtassert!(Task::on_appropriate_sched());
             };
             rtdebug!("task1 id: **%u**", borrow::to_uint(task1));
 
-            let task2 = ~do Task::new_root(&mut normal_sched.stack_pool) {
+            let task2 = ~do Task::new_root(&mut normal_sched.stack_pool, None) {
                 rtassert!(Task::on_appropriate_sched());
             };
 
-            let task3 = ~do Task::new_root(&mut normal_sched.stack_pool) {
+            let task3 = ~do Task::new_root(&mut normal_sched.stack_pool, None) {
                 rtassert!(Task::on_appropriate_sched());
             };
 
-            let task4 = ~do Task::new_root_homed(&mut special_sched.stack_pool,
+            let task4 = ~do Task::new_root_homed(&mut special_sched.stack_pool, None,
                                                  Sched(t4_handle)) {
                 rtassert!(Task::on_appropriate_sched());
             };
@@ -923,7 +923,7 @@ fn test_schedule_home_states() {
             let port = Cell::new(port);
             let chan = Cell::new(chan);
 
-            let normal_task = ~do Task::new_root(&mut normal_sched.stack_pool) {
+            let normal_task = ~do Task::new_root(&mut normal_sched.stack_pool, None) {
                 rtdebug!("*about to submit task2*");
                 Scheduler::run_task(task2.take());
                 rtdebug!("*about to submit task4*");
@@ -938,7 +938,7 @@ fn test_schedule_home_states() {
 
             rtdebug!("normal task: %u", borrow::to_uint(normal_task));
 
-            let special_task = ~do Task::new_root(&mut special_sched.stack_pool) {
+            let special_task = ~do Task::new_root(&mut special_sched.stack_pool, None) {
                 rtdebug!("*about to submit task1*");
                 Scheduler::run_task(task1.take());
                 rtdebug!("*about to submit task3*");
index 4c5e4bdc3c1d9b8b984642686428527ec1f40d38..364439a452601e490e5f2580d629f21c6caeb40f 100644 (file)
@@ -20,6 +20,7 @@
 use ptr;
 use prelude::*;
 use option::{Option, Some, None};
+use rt::env;
 use rt::kill::Death;
 use rt::local::Local;
 use rt::logging::StdErrLogger;
@@ -85,12 +86,13 @@ impl Task {
 
     // A helper to build a new task using the dynamically found
     // scheduler and task. Only works in GreenTask context.
-    pub fn build_homed_child(f: ~fn(), home: SchedHome) -> ~Task {
+    pub fn build_homed_child(stack_size: Option<uint>, f: ~fn(), home: SchedHome) -> ~Task {
         let f = Cell::new(f);
         let home = Cell::new(home);
         do Local::borrow::<Task, ~Task> |running_task| {
             let mut sched = running_task.sched.take_unwrap();
             let new_task = ~running_task.new_child_homed(&mut sched.stack_pool,
+                                                         stack_size,
                                                          home.take(),
                                                          f.take());
             running_task.sched = Some(sched);
@@ -98,25 +100,26 @@ pub fn build_homed_child(f: ~fn(), home: SchedHome) -> ~Task {
         }
     }
 
-    pub fn build_child(f: ~fn()) -> ~Task {
-        Task::build_homed_child(f, AnySched)
+    pub fn build_child(stack_size: Option<uint>, f: ~fn()) -> ~Task {
+        Task::build_homed_child(stack_size, f, AnySched)
     }
 
-    pub fn build_homed_root(f: ~fn(), home: SchedHome) -> ~Task {
+    pub fn build_homed_root(stack_size: Option<uint>, f: ~fn(), home: SchedHome) -> ~Task {
         let f = Cell::new(f);
         let home = Cell::new(home);
         do Local::borrow::<Task, ~Task> |running_task| {
             let mut sched = running_task.sched.take_unwrap();
             let new_task = ~Task::new_root_homed(&mut sched.stack_pool,
-                                                    home.take(),
-                                                    f.take());
+                                                 stack_size,
+                                                 home.take(),
+                                                 f.take());
             running_task.sched = Some(sched);
             new_task
         }
     }
 
-    pub fn build_root(f: ~fn()) -> ~Task {
-        Task::build_homed_root(f, AnySched)
+    pub fn build_root(stack_size: Option<uint>, f: ~fn()) -> ~Task {
+        Task::build_homed_root(stack_size, f, AnySched)
     }
 
     pub fn new_sched_task() -> Task {
@@ -137,17 +140,20 @@ pub fn new_sched_task() -> Task {
     }
 
     pub fn new_root(stack_pool: &mut StackPool,
+                    stack_size: Option<uint>,
                     start: ~fn()) -> Task {
-        Task::new_root_homed(stack_pool, AnySched, start)
+        Task::new_root_homed(stack_pool, stack_size, AnySched, start)
     }
 
     pub fn new_child(&mut self,
                      stack_pool: &mut StackPool,
+                     stack_size: Option<uint>,
                      start: ~fn()) -> Task {
-        self.new_child_homed(stack_pool, AnySched, start)
+        self.new_child_homed(stack_pool, stack_size, AnySched, start)
     }
 
     pub fn new_root_homed(stack_pool: &mut StackPool,
+                          stack_size: Option<uint>,
                           home: SchedHome,
                           start: ~fn()) -> Task {
         Task {
@@ -160,7 +166,7 @@ pub fn new_root_homed(stack_pool: &mut StackPool,
             death: Death::new(),
             destroyed: false,
             name: None,
-            coroutine: Some(Coroutine::new(stack_pool, start)),
+            coroutine: Some(Coroutine::new(stack_pool, stack_size, start)),
             sched: None,
             task_type: GreenTask(Some(~home))
         }
@@ -168,6 +174,7 @@ pub fn new_root_homed(stack_pool: &mut StackPool,
 
     pub fn new_child_homed(&mut self,
                            stack_pool: &mut StackPool,
+                           stack_size: Option<uint>,
                            home: SchedHome,
                            start: ~fn()) -> Task {
         Task {
@@ -181,7 +188,7 @@ pub fn new_child_homed(&mut self,
             death: self.death.new_child(),
             destroyed: false,
             name: None,
-            coroutine: Some(Coroutine::new(stack_pool, start)),
+            coroutine: Some(Coroutine::new(stack_pool, stack_size, start)),
             sched: None,
             task_type: GreenTask(Some(~home))
         }
@@ -325,11 +332,13 @@ fn drop(&self) {
 
 impl Coroutine {
 
-    pub fn new(stack_pool: &mut StackPool, start: ~fn()) -> Coroutine {
-        static MIN_STACK_SIZE: uint = 3000000; // XXX: Too much stack
-
+    pub fn new(stack_pool: &mut StackPool, stack_size: Option<uint>, start: ~fn()) -> Coroutine {
+        let stack_size = match stack_size {
+            Some(size) => size,
+            None => env::min_stack()
+        };
         let start = Coroutine::build_start_wrapper(start);
-        let mut stack = stack_pool.take_segment(MIN_STACK_SIZE);
+        let mut stack = stack_pool.take_segment(stack_size);
         let initial_context = Context::new(start, &mut stack);
         Coroutine {
             current_stack_segment: stack,
@@ -465,10 +474,10 @@ fn tls() {
         do run_in_newsched_task() {
             static key: local_data::Key<@~str> = &local_data::Key;
             local_data::set(key, @~"data");
-            assert!(*local_data::get(key, |k| k.map(|&k| *k)).unwrap() == ~"data");
+            assert!(*local_data::get(key, |k| k.map_move(|k| *k)).unwrap() == ~"data");
             static key2: local_data::Key<@~str> = &local_data::Key;
             local_data::set(key2, @~"data");
-            assert!(*local_data::get(key2, |k| k.map(|&k| *k)).unwrap() == ~"data");
+            assert!(*local_data::get(key2, |k| k.map_move(|k| *k)).unwrap() == ~"data");
         }
     }
 
index 8b5215ae9694aedc4d0549b1c8f184e14d00edb5..792ea5eb33f5acfa138be4692e53222858c34c2a 100644 (file)
@@ -57,7 +57,7 @@ pub fn run_in_newsched_task_core(f: ~fn()) {
         exit_handle.take().send(Shutdown);
         rtassert!(exit_status);
     };
-    let mut task = ~Task::new_root(&mut sched.stack_pool, f);
+    let mut task = ~Task::new_root(&mut sched.stack_pool, None, f);
     task.death.on_exit = Some(on_exit);
 
     sched.bootstrap(task);
@@ -190,8 +190,7 @@ pub fn run_in_mt_newsched_task(f: ~fn()) {
 
             rtassert!(exit_status);
         };
-        let mut main_task = ~Task::new_root(&mut scheds[0].stack_pool,
-                                        f.take());
+        let mut main_task = ~Task::new_root(&mut scheds[0].stack_pool, None, f.take());
         main_task.death.on_exit = Some(on_exit);
 
         let mut threads = ~[];
@@ -209,7 +208,7 @@ pub fn run_in_mt_newsched_task(f: ~fn()) {
 
         while !scheds.is_empty() {
             let mut sched = scheds.pop();
-            let bootstrap_task = ~do Task::new_root(&mut sched.stack_pool) || {
+            let bootstrap_task = ~do Task::new_root(&mut sched.stack_pool, None) || {
                 rtdebug!("bootstrapping non-primary scheduler");
             };
             let bootstrap_task_cell = Cell::new(bootstrap_task);
@@ -232,12 +231,12 @@ pub fn run_in_mt_newsched_task(f: ~fn()) {
 
 /// Test tasks will abort on failure instead of unwinding
 pub fn spawntask(f: ~fn()) {
-    Scheduler::run_task(Task::build_child(f));
+    Scheduler::run_task(Task::build_child(None, f));
 }
 
 /// Create a new task and run it right now. Aborts on failure
 pub fn spawntask_later(f: ~fn()) {
-    Scheduler::run_task_later(Task::build_child(f));
+    Scheduler::run_task_later(Task::build_child(None, f));
 }
 
 pub fn spawntask_random(f: ~fn()) {
@@ -259,7 +258,7 @@ pub fn spawntask_try(f: ~fn()) -> Result<(),()> {
     let chan = Cell::new(chan);
     let on_exit: ~fn(bool) = |exit_status| chan.take().send(exit_status);
 
-    let mut new_task = Task::build_root(f);
+    let mut new_task = Task::build_root(None, f);
     new_task.death.on_exit = Some(on_exit);
 
     Scheduler::run_task(new_task);
@@ -285,7 +284,7 @@ pub fn spawntask_thread(f: ~fn()) -> Thread {
 pub fn with_test_task(blk: ~fn(~Task) -> ~Task) {
     do run_in_bare_thread {
         let mut sched = ~new_test_uv_sched();
-        let task = blk(~Task::new_root(&mut sched.stack_pool, ||{}));
+        let task = blk(~Task::new_root(&mut sched.stack_pool, None, ||{}));
         cleanup_task(task);
     }
 }
index b4057b85cbfef5cbfae74b54555c359c3e9f5376..c4bd2c5435a28a6193304b9bffbe945d5d8b7695 100644 (file)
@@ -1849,7 +1849,7 @@ fn find_str(&self, needle: &str) -> Option<uint> {
         } else {
             self.matches_index_iter(needle)
                 .next()
-                .map_consume(|(start, _end)| start)
+                .map_move(|(start, _end)| start)
         }
     }
 
@@ -3304,19 +3304,22 @@ fn test_char_range_at_reverse_underflow() {
     fn test_add() {
         #[allow(unnecessary_allocation)];
         macro_rules! t (
-            ($s1:expr, $s2:expr, $e:expr) => {
-                assert_eq!($s1 + $s2, $e);
-                assert_eq!($s1.to_owned() + $s2, $e);
-                assert_eq!($s1.to_managed() + $s2, $e);
-            }
+            ($s1:expr, $s2:expr, $e:expr) => { {
+                let s1 = $s1;
+                let s2 = $s2;
+                let e = $e;
+                assert_eq!(s1 + s2, e.to_owned());
+                assert_eq!(s1.to_owned() + s2, e.to_owned());
+                assert_eq!(s1.to_managed() + s2, e.to_owned());
+            } }
         );
 
-        t!("foo",  "bar", ~"foobar");
-        t!("foo", @"bar", ~"foobar");
-        t!("foo", ~"bar", ~"foobar");
-        t!("ศไทย中",  "华Việt Nam", ~"ศไทย中华Việt Nam");
-        t!("ศไทย中", @"华Việt Nam", ~"ศไทย中华Việt Nam");
-        t!("ศไทย中", ~"华Việt Nam", ~"ศไทย中华Việt Nam");
+        t!("foo",  "bar", "foobar");
+        t!("foo", @"bar", "foobar");
+        t!("foo", ~"bar", "foobar");
+        t!("ศไทย中",  "华Việt Nam", "ศไทย中华Việt Nam");
+        t!("ศไทย中", @"华Việt Nam", "ศไทย中华Việt Nam");
+        t!("ศไทย中", ~"华Việt Nam", "ศไทย中华Việt Nam");
     }
 
     #[test]
index 225a4b8cfd294eacb0fddb4ad2b5058b5dd0edab..2e0c9c1d1ad1e01bf3b75f18e48ebee8c6820d1d 100644 (file)
@@ -142,7 +142,8 @@ pub struct TaskOpts {
     indestructible: bool,
     notify_chan: Option<Chan<TaskResult>>,
     name: Option<~str>,
-    sched: SchedOpts
+    sched: SchedOpts,
+    stack_size: Option<uint>
 }
 
 /**
@@ -197,7 +198,8 @@ fn consume(&mut self) -> TaskBuilder {
                 indestructible: self.opts.indestructible,
                 notify_chan: notify_chan,
                 name: name,
-                sched: self.opts.sched
+                sched: self.opts.sched,
+                stack_size: self.opts.stack_size
             },
             gen_body: gen_body,
             can_not_copy: None,
@@ -351,7 +353,8 @@ pub fn spawn(&mut self, f: ~fn()) {
             indestructible: x.opts.indestructible,
             notify_chan: notify_chan,
             name: name,
-            sched: x.opts.sched
+            sched: x.opts.sched,
+            stack_size: x.opts.stack_size
         };
         let f = match gen_body {
             Some(gen) => {
@@ -422,7 +425,8 @@ pub fn default_task_opts() -> TaskOpts {
         name: None,
         sched: SchedOpts {
             mode: DefaultScheduler,
-        }
+        },
+        stack_size: None
     }
 }
 
@@ -655,6 +659,7 @@ pub unsafe fn rekillable<U>(f: &fn() -> U) -> U {
     }
 }
 
+#[ignore(reason = "linked failure")]
 #[test] #[ignore(cfg(windows))]
 fn test_kill_unkillable_task() {
     use rt::test::*;
@@ -675,6 +680,7 @@ fn test_kill_unkillable_task() {
     }
 }
 
+#[ignore(reason = "linked failure")]
 #[test] #[ignore(cfg(windows))]
 fn test_kill_rekillable_task() {
     use rt::test::*;
@@ -716,6 +722,7 @@ fn test_cant_dup_task_builder() {
 #[cfg(test)]
 fn block_forever() { let (po, _ch) = stream::<()>(); po.recv(); }
 
+#[ignore(reason = "linked failure")]
 #[test] #[ignore(cfg(windows))]
 fn test_spawn_unlinked_unsup_no_fail_down() { // grandchild sends on a port
     use rt::test::run_in_newsched_task;
@@ -734,6 +741,7 @@ fn test_spawn_unlinked_unsup_no_fail_down() { // grandchild sends on a port
         po.recv();
     }
 }
+#[ignore(reason = "linked failure")]
 #[test] #[ignore(cfg(windows))]
 fn test_spawn_unlinked_unsup_no_fail_up() { // child unlinked fails
     use rt::test::run_in_newsched_task;
@@ -741,6 +749,7 @@ fn test_spawn_unlinked_unsup_no_fail_up() { // child unlinked fails
         do spawn_unlinked { fail!(); }
     }
 }
+#[ignore(reason = "linked failure")]
 #[test] #[ignore(cfg(windows))]
 fn test_spawn_unlinked_sup_no_fail_up() { // child unlinked fails
     use rt::test::run_in_newsched_task;
@@ -750,6 +759,7 @@ fn test_spawn_unlinked_sup_no_fail_up() { // child unlinked fails
         do 16.times { task::yield(); }
     }
 }
+#[ignore(reason = "linked failure")]
 #[test] #[ignore(cfg(windows))]
 fn test_spawn_unlinked_sup_fail_down() {
     use rt::test::run_in_newsched_task;
@@ -762,6 +772,7 @@ fn test_spawn_unlinked_sup_fail_down() {
     }
 }
 
+#[ignore(reason = "linked failure")]
 #[test] #[ignore(cfg(windows))]
 fn test_spawn_linked_sup_fail_up() { // child fails; parent fails
     use rt::test::run_in_newsched_task;
@@ -782,6 +793,7 @@ fn test_spawn_unlinked_sup_fail_down() {
         assert!(result.is_err());
     }
 }
+#[ignore(reason = "linked failure")]
 #[test] #[ignore(cfg(windows))]
 fn test_spawn_linked_sup_fail_down() { // parent fails; child fails
     use rt::test::run_in_newsched_task;
@@ -798,6 +810,7 @@ fn test_spawn_unlinked_sup_fail_down() {
         assert!(result.is_err());
     }
 }
+#[ignore(reason = "linked failure")]
 #[test] #[ignore(cfg(windows))]
 fn test_spawn_linked_unsup_fail_up() { // child fails; parent fails
     use rt::test::run_in_newsched_task;
@@ -810,6 +823,7 @@ fn test_spawn_unlinked_sup_fail_down() {
         assert!(result.is_err());
     }
 }
+#[ignore(reason = "linked failure")]
 #[test] #[ignore(cfg(windows))]
 fn test_spawn_linked_unsup_fail_down() { // parent fails; child fails
     use rt::test::run_in_newsched_task;
@@ -822,6 +836,7 @@ fn test_spawn_unlinked_sup_fail_down() {
         assert!(result.is_err());
     }
 }
+#[ignore(reason = "linked failure")]
 #[test] #[ignore(cfg(windows))]
 fn test_spawn_linked_unsup_default_opts() { // parent fails; child fails
     use rt::test::run_in_newsched_task;
@@ -840,6 +855,7 @@ fn test_spawn_unlinked_sup_fail_down() {
 // A couple bonus linked failure tests - testing for failure propagation even
 // when the middle task exits successfully early before kill signals are sent.
 
+#[ignore(reason = "linked failure")]
 #[test] #[ignore(cfg(windows))]
 fn test_spawn_failure_propagate_grandchild() {
     use rt::test::run_in_newsched_task;
@@ -856,6 +872,7 @@ fn test_spawn_failure_propagate_grandchild() {
     }
 }
 
+#[ignore(reason = "linked failure")]
 #[test] #[ignore(cfg(windows))]
 fn test_spawn_failure_propagate_secondborn() {
     use rt::test::run_in_newsched_task;
@@ -872,6 +889,7 @@ fn test_spawn_failure_propagate_secondborn() {
     }
 }
 
+#[ignore(reason = "linked failure")]
 #[test] #[ignore(cfg(windows))]
 fn test_spawn_failure_propagate_nephew_or_niece() {
     use rt::test::run_in_newsched_task;
@@ -888,6 +906,7 @@ fn test_spawn_failure_propagate_nephew_or_niece() {
     }
 }
 
+#[ignore(reason = "linked failure")]
 #[test] #[ignore(cfg(windows))]
 fn test_spawn_linked_sup_propagate_sibling() {
     use rt::test::run_in_newsched_task;
@@ -1191,6 +1210,7 @@ fn test_avoid_copying_the_body_unlinked() {
     }
 }
 
+#[ignore(reason = "linked failure")]
 #[test]
 #[ignore(cfg(windows))]
 #[should_fail]
@@ -1226,6 +1246,7 @@ fn test_unkillable() {
     po.recv();
 }
 
+#[ignore(reason = "linked failure")]
 #[test]
 #[ignore(cfg(windows))]
 #[should_fail]
@@ -1292,6 +1313,7 @@ fn test_simple_newsched_spawn() {
     }
 }
 
+#[ignore(reason = "linked failure")]
 #[test] #[ignore(cfg(windows))]
 fn test_spawn_watched() {
     use rt::test::run_in_newsched_task;
@@ -1314,6 +1336,7 @@ fn test_spawn_watched() {
     }
 }
 
+#[ignore(reason = "linked failure")]
 #[test] #[ignore(cfg(windows))]
 fn test_indestructible() {
     use rt::test::run_in_newsched_task;
index 527b20b0e9027312afc5d66244365fa54b5cb28f..2d0a2d98e9fc0780f0c090289b6c47512e4539fd 100644 (file)
@@ -500,7 +500,7 @@ unsafe fn kill_task(task: TaskHandle) {
             OldTask(ptr) => rt::rust_task_kill_other(ptr),
             NewTask(handle) => {
                 let mut handle = handle;
-                do handle.kill().map_consume |killed_task| {
+                do handle.kill().map_move |killed_task| {
                     let killed_task = Cell::new(killed_task);
                     do Local::borrow::<Scheduler, ()> |sched| {
                         sched.enqueue_task(killed_task.take());
@@ -682,7 +682,7 @@ fn spawn_raw_newsched(mut opts: TaskOpts, f: ~fn()) {
         // Child task runs this code.
 
         // If child data is 'None', the enlist is vacuously successful.
-        let enlist_success = do child_data.take().map_consume_default(true) |child_data| {
+        let enlist_success = do child_data.take().map_move_default(true) |child_data| {
             let child_data = Cell::new(child_data); // :(
             do Local::borrow::<Task, bool> |me| {
                 let (child_tg, ancestors, is_main) = child_data.take();
@@ -713,9 +713,9 @@ fn spawn_raw_newsched(mut opts: TaskOpts, f: ~fn()) {
     let mut task = unsafe {
         if opts.sched.mode != SingleThreaded {
             if opts.watched {
-                Task::build_child(child_wrapper)
+                Task::build_child(opts.stack_size, child_wrapper)
             } else {
-                Task::build_root(child_wrapper)
+                Task::build_root(opts.stack_size, child_wrapper)
             }
         } else {
             // Creating a 1:1 task:thread ...
@@ -736,16 +736,16 @@ fn spawn_raw_newsched(mut opts: TaskOpts, f: ~fn()) {
 
             // Pin the new task to the new scheduler
             let new_task = if opts.watched {
-                Task::build_homed_child(child_wrapper, Sched(new_sched_handle))
+                Task::build_homed_child(opts.stack_size, child_wrapper, Sched(new_sched_handle))
             } else {
-                Task::build_homed_root(child_wrapper, Sched(new_sched_handle))
+                Task::build_homed_root(opts.stack_size, child_wrapper, Sched(new_sched_handle))
             };
 
             // Create a task that will later be used to join with the new scheduler
             // thread when it is ready to terminate
             let (thread_port, thread_chan) = oneshot();
             let thread_port_cell = Cell::new(thread_port);
-            let join_task = do Task::build_child() {
+            let join_task = do Task::build_child(None) {
                 rtdebug!("running join task");
                 let thread_port = thread_port_cell.take();
                 let thread: Thread = thread_port.recv();
@@ -762,8 +762,8 @@ fn spawn_raw_newsched(mut opts: TaskOpts, f: ~fn()) {
                 let mut orig_sched_handle = orig_sched_handle_cell.take();
                 let join_task = join_task_cell.take();
 
-                let bootstrap_task = ~do Task::new_root(&mut new_sched.stack_pool) || {
-                    rtdebug!("bootstrapping a 1:1 scheduler");
+                let bootstrap_task = ~do Task::new_root(&mut new_sched.stack_pool, None) || {
+                    rtdebug!("boostrapping a 1:1 scheduler");
                 };
                 new_sched.bootstrap(bootstrap_task);
 
@@ -854,7 +854,7 @@ fn make_child_wrapper(child: *rust_task, child_arc: TaskGroupArc,
             // Even if the below code fails to kick the child off, we must
             // send Something on the notify channel.
 
-            let notifier = notify_chan.map_consume(|c| AutoNotify(c));
+            let notifier = notify_chan.map_move(|c| AutoNotify(c));
 
             if enlist_many(OldTask(child), &child_arc, &mut ancestors) {
                 let group = @@mut Taskgroup(child_arc, ancestors, is_main, notifier);
index 1270a80c354990aeee037520b1fe4f1221faf192..c60edad3dbd5683e6ec69cae281376a950089a6c 100644 (file)
@@ -317,12 +317,21 @@ fn visit_leave_fn(&self, purity: uint, proto: uint,
     /// Get the address of the `__morestack` stack growth function.
     pub fn morestack_addr() -> *();
 
-    /// Adjust a pointer by an offset.
+    /// Calculates the offset from a pointer.
     ///
     /// This is implemented as an intrinsic to avoid converting to and from an
     /// integer, since the conversion would throw away aliasing information.
     pub fn offset<T>(dst: *T, offset: int) -> *T;
 
+    /// Calculates the offset from a pointer. The offset *must* be in-bounds of
+    /// the object, or one-byte-past-the-end. An arithmetic overflow is also
+    /// undefined behaviour.
+    ///
+    /// This intrinsic should be preferred over `offset` when the guarantee can
+    /// be satisfied, to enable better optimization.
+    #[cfg(not(stage0))]
+    pub fn offset_inbounds<T>(dst: *T, offset: int) -> *T;
+
     /// Equivalent to the `llvm.memcpy.p0i8.0i8.i32` intrinsic, with a size of
     /// `count` * `size_of::<T>()` and an alignment of `min_align_of::<T>()`
     pub fn memcpy32<T>(dst: *mut T, src: *T, count: u32);
index e0c4950b38eaa8a0cb1d4cc742838b3493486bc2..98c0fe254b697643325efbe9dff7fb6a9f514991 100644 (file)
@@ -135,7 +135,7 @@ pub fn start(main: *u8, argc: int, argv: **c_char,
     use os;
 
     unsafe {
-        let use_old_rt = os::getenv("RUST_NEWRT").is_none();
+        let use_old_rt = os::getenv("RUST_OLDRT").is_some();
         if use_old_rt {
             return rust_start(main as *c_void, argc as c_int, argv,
                               crate_map as *c_void) as int;
index 0259b547ab3f06040f812deaa55144fbb5bded3e..36201dc5e82665ab4a6c2abc2b03306cb594147a 100644 (file)
@@ -849,10 +849,15 @@ fn slice_to(&self, end: uint) -> &'self [T] {
     fn iter(self) -> VecIterator<'self, T> {
         unsafe {
             let p = vec::raw::to_ptr(self);
-            VecIterator{ptr: p,
-                        end: (p as uint + self.len() *
-                              sys::nonzero_size_of::<T>()) as *T,
-                        lifetime: cast::transmute(p)}
+            if sys::size_of::<T>() == 0 {
+                VecIterator{ptr: p,
+                            end: (p as uint + self.len()) as *T,
+                            lifetime: cast::transmute(p)}
+            } else {
+                VecIterator{ptr: p,
+                            end: p.offset_inbounds(self.len() as int),
+                            lifetime: cast::transmute(p)}
+            }
         }
     }
 
@@ -1826,10 +1831,15 @@ fn mut_split(self, mid: uint) -> (&'self mut [T], &'self mut [T]) {
     fn mut_iter(self) -> VecMutIterator<'self, T> {
         unsafe {
             let p = vec::raw::to_mut_ptr(self);
-            VecMutIterator{ptr: p,
-                           end: (p as uint + self.len() *
-                                 sys::nonzero_size_of::<T>()) as *mut T,
-                           lifetime: cast::transmute(p)}
+            if sys::size_of::<T>() == 0 {
+                VecMutIterator{ptr: p,
+                               end: (p as uint + self.len()) as *mut T,
+                               lifetime: cast::transmute(p)}
+            } else {
+                VecMutIterator{ptr: p,
+                               end: p.offset_inbounds(self.len() as int),
+                               lifetime: cast::transmute(p)}
+            }
         }
     }
 
@@ -2183,7 +2193,7 @@ fn next(&mut self) -> Option<$elem> {
                             // same pointer.
                             cast::transmute(self.ptr as uint + 1)
                         } else {
-                            self.ptr.offset(1)
+                            self.ptr.offset_inbounds(1)
                         };
 
                         Some(cast::transmute(old))
@@ -2215,7 +2225,7 @@ fn next_back(&mut self) -> Option<$elem> {
                             // See above for why 'ptr.offset' isn't used
                             cast::transmute(self.end as uint - 1)
                         } else {
-                            self.end.offset(-1)
+                            self.end.offset_inbounds(-1)
                         };
                         Some(cast::transmute(self.end))
                     }
index 84e6544f78092b56ca51416548ae9b03c1c47947..ba167fe67148ef5df984fbdf00e50495fb7f6f39 100644 (file)
@@ -888,7 +888,7 @@ pub fn new_sctable_internal() -> SCTable {
 // fetch the SCTable from TLS, create one if it doesn't yet exist.
 pub fn get_sctable() -> @mut SCTable {
     static sctable_key: local_data::Key<@@mut SCTable> = &local_data::Key;
-    match local_data::get(sctable_key, |k| k.map(|&k| *k)) {
+    match local_data::get(sctable_key, |k| k.map_move(|k| *k)) {
         None => {
             let new_table = @@mut new_sctable_internal();
             local_data::set(sctable_key,new_table);
index d39cb2f507ca957ae57d1ec7d45332487ddcfd88..9edd41152f7f288ef090b2b94f555fabf4edf0b7 100644 (file)
@@ -83,7 +83,7 @@ fn meta_item_list<'a>(&'a self) -> Option<&'a [@MetaItem]> {
     }
 
     pub fn name_str_pair(&self) -> Option<(@str, @str)> {
-        self.value_str().map_consume(|s| (self.name(), s))
+        self.value_str().map_move(|s| (self.name(), s))
     }
 }
 
index 8b5014366413527ef93381f22b4b7f02e6c98880..2b6cb91a5df1759771fb7e4567c270f8806a0535 100644 (file)
@@ -192,7 +192,7 @@ fn print_maybe_styled(msg: &str, color: term::attr::Attr) {
     let stderr = io::stderr();
 
     if stderr.get_type() == io::Screen {
-        let t = match local_data::get(tls_terminal, |v| v.map_consume(|&k|k)) {
+        let t = match local_data::get(tls_terminal, |v| v.map_move(|k| *k)) {
             None => {
                 let t = term::Terminal::new(stderr);
                 let tls = @match t {
index 99f74543e79782e3e907ab1073774e5515292e34..dc20994b49facbb70d3d7ed0dd87d981c99985b4 100644 (file)
@@ -481,7 +481,7 @@ fn find_in_topmost_frame(&self, key: &K) -> Option<@V> {
             ConsMapChain(ref map,_) => map
         };
         // strip one layer of indirection off the pointer.
-        map.find(key).map(|r| {**r})
+        map.find(key).map_move(|r| {*r})
     }
 
     // insert the binding into the top-level map
index c373a3894884e50bc2286db265bf254a739e2577..d81dca005b0a41dc99bdef621159eea0face4e9a 100644 (file)
@@ -591,7 +591,7 @@ fn expr_match(&self, span: span, arg: @ast::expr, arms: ~[ast::arm]) -> @expr {
 
     fn expr_if(&self, span: span,
                cond: @ast::expr, then: @ast::expr, els: Option<@ast::expr>) -> @ast::expr {
-        let els = els.map(|x| self.expr_block(self.block_expr(*x)));
+        let els = els.map_move(|x| self.expr_block(self.block_expr(x)));
         self.expr(span, ast::expr_if(cond, self.block_expr(then), els))
     }
 
index 01dacdfe453ee7cec2a5b186698b48468ba9442a..001e92355282f9d5f095dfab787c3afa9dd779d4 100644 (file)
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+use ast;
 use ast::{MetaItem, item, expr};
 use codemap::span;
 use ext::base::ExtCtxt;
@@ -40,40 +41,70 @@ pub fn expand_deriving_totalord(cx: @ExtCtxt,
 }
 
 
-pub fn ordering_const(cx: @ExtCtxt, span: span, cnst: Ordering) -> @expr {
+pub fn ordering_const(cx: @ExtCtxt, span: span, cnst: Ordering) -> ast::Path {
     let cnst = match cnst {
         Less => "Less",
         Equal => "Equal",
         Greater => "Greater"
     };
-    cx.expr_path(
-        cx.path_global(span,
-                       ~[cx.ident_of("std"),
-                         cx.ident_of("cmp"),
-                         cx.ident_of(cnst)]))
+    cx.path_global(span,
+                   ~[cx.ident_of("std"),
+                     cx.ident_of("cmp"),
+                     cx.ident_of(cnst)])
 }
 
 pub fn cs_cmp(cx: @ExtCtxt, span: span,
               substr: &Substructure) -> @expr {
+    let test_id = cx.ident_of("__test");
+    let equals_path = ordering_const(cx, span, Equal);
 
+    /*
+    Builds:
+
+    let __test = self_field1.cmp(&other_field2);
+    if other == ::std::cmp::Equal {
+        let __test = self_field2.cmp(&other_field2);
+        if __test == ::std::cmp::Equal {
+            ...
+        } else {
+            __test
+        }
+    } else {
+        __test
+    }
+
+    FIXME #6449: These `if`s could/should be `match`es.
+    */
     cs_same_method_fold(
-        // foldr (possibly) nests the matches in lexical_ordering better
+        // foldr nests the if-elses correctly, leaving the first field
+        // as the outermost one, and the last as the innermost.
         false,
         |cx, span, old, new| {
-            cx.expr_call_global(span,
-                                ~[cx.ident_of("std"),
-                                  cx.ident_of("cmp"),
-                                  cx.ident_of("lexical_ordering")],
-                                ~[old, new])
+            // let __test = new;
+            // if __test == ::std::cmp::Equal {
+            //    old
+            // } else {
+            //    __test
+            // }
+
+            let assign = cx.stmt_let(span, false, test_id, new);
+
+            let cond = cx.expr_binary(span, ast::eq,
+                                      cx.expr_ident(span, test_id),
+                                      cx.expr_path(equals_path.clone()));
+            let if_ = cx.expr_if(span,
+                                 cond,
+                                 old, Some(cx.expr_ident(span, test_id)));
+            cx.expr_block(cx.block(span, ~[assign], Some(if_)))
         },
-        ordering_const(cx, span, Equal),
+        cx.expr_path(equals_path.clone()),
         |cx, span, list, _| {
             match list {
                 // an earlier nonmatching variant is Less than a
-                // later one
+                // later one.
                 [(self_var, _, _),
-                 (other_var, _, _)] => ordering_const(cx, span,
-                                                      self_var.cmp(&other_var)),
+                 (other_var, _, _)] => cx.expr_path(ordering_const(cx, span,
+                                                                   self_var.cmp(&other_var))),
                 _ => cx.span_bug(span, "Not exactly 2 arguments in `deriving(TotalOrd)`")
             }
         },
index 7ffed13940e8a6f144c3a9a92c7ce9efe0f6c28a..0a5bc00072034a052bd9a2d865d81aabfbb4f5a5 100644 (file)
@@ -417,7 +417,7 @@ fn noop_fold_stmt(s: &stmt_, fld: @ast_fold) -> Option<stmt_> {
 fn noop_fold_arm(a: &arm, fld: @ast_fold) -> arm {
     arm {
         pats: a.pats.map(|x| fld.fold_pat(*x)),
-        guard: a.guard.map(|x| fld.fold_expr(*x)),
+        guard: a.guard.map_move(|x| fld.fold_expr(x)),
         body: fld.fold_block(&a.body),
     }
 }
@@ -429,7 +429,7 @@ pub fn noop_fold_pat(p: &pat_, fld: @ast_fold) -> pat_ {
             pat_ident(
                 binding_mode,
                 fld.fold_path(pth),
-                sub.map(|x| fld.fold_pat(*x))
+                sub.map_move(|x| fld.fold_pat(x))
             )
         }
         pat_lit(e) => pat_lit(fld.fold_expr(e)),
@@ -459,7 +459,7 @@ pub fn noop_fold_pat(p: &pat_, fld: @ast_fold) -> pat_ {
         pat_vec(ref before, ref slice, ref after) => {
             pat_vec(
                 before.map(|x| fld.fold_pat(*x)),
-                slice.map(|x| fld.fold_pat(*x)),
+                slice.map_move(|x| fld.fold_pat(x)),
                 after.map(|x| fld.fold_pat(*x))
             )
         }
@@ -551,7 +551,7 @@ fn fold_field_(field: Field, fld: @ast_fold) -> Field {
             expr_if(
                 fld.fold_expr(cond),
                 fld.fold_block(tr),
-                fl.map(|x| fld.fold_expr(*x))
+                fl.map_move(|x| fld.fold_expr(x))
             )
         }
         expr_while(cond, ref body) => {
@@ -565,7 +565,7 @@ fn fold_field_(field: Field, fld: @ast_fold) -> Field {
         expr_loop(ref body, opt_ident) => {
             expr_loop(
                 fld.fold_block(body),
-                opt_ident.map(|x| fld.fold_ident(*x))
+                opt_ident.map_move(|x| fld.fold_ident(x))
             )
         }
         expr_match(expr, ref arms) => {
@@ -608,13 +608,13 @@ fn fold_field_(field: Field, fld: @ast_fold) -> Field {
         expr_path(ref pth) => expr_path(fld.fold_path(pth)),
         expr_self => expr_self,
         expr_break(ref opt_ident) => {
-            expr_break(opt_ident.map(|x| fld.fold_ident(*x)))
+            expr_break(opt_ident.map_move(|x| fld.fold_ident(x)))
         }
         expr_again(ref opt_ident) => {
-            expr_again(opt_ident.map(|x| fld.fold_ident(*x)))
+            expr_again(opt_ident.map_move(|x| fld.fold_ident(x)))
         }
         expr_ret(ref e) => {
-            expr_ret(e.map(|x| fld.fold_expr(*x)))
+            expr_ret(e.map_move(|x| fld.fold_expr(x)))
         }
         expr_log(lv, e) => {
             expr_log(
@@ -634,7 +634,7 @@ fn fold_field_(field: Field, fld: @ast_fold) -> Field {
             expr_struct(
                 fld.fold_path(path),
                 fields.map(|x| fold_field(*x)),
-                maybe_expr.map(|x| fld.fold_expr(*x))
+                maybe_expr.map_move(|x| fld.fold_expr(x))
             )
         },
         expr_paren(ex) => expr_paren(fld.fold_expr(ex))
@@ -731,7 +731,7 @@ fn fold_variant_arg_(va: variant_arg, fld: @ast_fold) -> variant_arg {
                 fold_variant_arg(/*bad*/ (*x).clone())
             })
         }
-        struct_variant_kind(struct_def) => {
+        struct_variant_kind(ref struct_def) => {
             kind = struct_variant_kind(@ast::struct_def {
                 fields: struct_def.fields.iter()
                     .transform(|f| fld.fold_struct_field(*f)).collect(),
@@ -776,7 +776,7 @@ fn noop_fold_local(l: @Local, fld: @ast_fold) -> @Local {
         is_mutbl: l.is_mutbl,
         ty: fld.fold_ty(&l.ty),
         pat: fld.fold_pat(l.pat),
-        init: l.init.map(|e| fld.fold_expr(*e)),
+        init: l.init.map_move(|e| fld.fold_expr(e)),
         id: fld.new_id(l.id),
         span: fld.new_span(l.span),
     }
index a0932729930e3c7fcc3da3da356b6b23251b3efd..4902c4587ac39f8a02b3b06a09d62d45eeafb003 100644 (file)
@@ -1313,7 +1313,7 @@ pub fn parse_bounded_path_with_tps(&self, colons: bool,
 
         // If the path might have bounds on it, they should be parsed before
         // the parameters, e.g. module::TraitName:B1+B2<T>
-        before_tps.map_consume(|callback| callback());
+        before_tps.map_move(|callback| callback());
 
         // Parse the (obsolete) trailing region parameter, if any, which will
         // be written "foo/&x"
index 39668e5c8b29b22613e30ab034fd5fcbd5b7e198..fd491c1e890a0d8f140d56d06bd2a29e5ea34791 100644 (file)
@@ -486,7 +486,7 @@ fn mk_fresh_ident_interner() -> @ident_interner {
 pub fn get_ident_interner() -> @ident_interner {
     static key: local_data::Key<@@::parse::token::ident_interner> =
         &local_data::Key;
-    match local_data::get(key, |k| k.map(|&k| *k)) {
+    match local_data::get(key, |k| k.map_move(|k| *k)) {
         Some(interner) => *interner,
         None => {
             let interner = mk_fresh_ident_interner();
index 4fbe00622aa26fdded3c4d32bf8a6d4b7f0824e3..70fe6f706f79a763683fdc6556f09c765e2a86f0 100644 (file)
@@ -59,7 +59,7 @@ pub fn bench_int<T:MutableSet<uint>,
         {
             let mut set = f();
             do timed(&mut self.random_ints) {
-                do num_keys.times {
+                for _ in range(0, num_keys) {
                     set.insert((rng.next() as uint) % rand_cap);
                 }
             }
@@ -103,7 +103,7 @@ pub fn bench_str<T:MutableSet<~str>,
         {
             let mut set = f();
             do timed(&mut self.random_strings) {
-                do num_keys.times {
+                for _ in range(0, num_keys) {
                     let s = uint::to_str(rng.next() as uint);
                     set.insert(s);
                 }
index 19380feea6df4beca237cfa16e6033ea27cecb39..8503b188b2f25a27dd7d21bc6d01e5d991373abd 100644 (file)
@@ -105,7 +105,7 @@ fn main() {
     let symbols = [" ", "░", "▒", "▓", "█", "█"];
     let mut pixels = [0f32, ..256*256];
     let n2d = ~Noise2DContext::new();
-    do 100.times {
+    for _ in range(0, 100u) {
         for y in range(0, 256) {
             for x in range(0, 256) {
                 let v = n2d.get(
index 190ad62d6e17ff771ecb81900a8cdd2767479a3b..2b177ccb98fcc194a0dbf743619ac82764b6a447 100644 (file)
@@ -169,7 +169,7 @@ fn rendezvous(nn: uint, set: ~[color]) {
     let mut creatures_met = 0;
 
     // set up meetings...
-    do nn.times {
+    for _ in range(0, nn) {
         let fst_creature: CreatureInfo = from_creatures.recv();
         let snd_creature: CreatureInfo = from_creatures.recv();
 
index 9d4d31b8969205a3b0b7a911dd9648897c3d8214..48372c6d03b2fc3410b7ec34aaac3237d1883ece 100644 (file)
@@ -1,3 +1,5 @@
+// xfail-test reading from os::args()[1] - bogus!
+
 use std::from_str::FromStr;
 use std::os;
 use std::vec::MutableVector;
index 579b88a7e0e72c0231fb22f17a8c7a407cbfb83b..1f1ce86404b69347896cee3050b49d0be120a2e2 100644 (file)
@@ -1,3 +1,5 @@
+// xfail-test reading from os::args()[1] - bogus!
+
 use std::cast::transmute;
 use std::from_str::FromStr;
 use std::libc::{FILE, STDOUT_FILENO, c_int, fdopen, fputc, fputs, fwrite, size_t};
@@ -164,7 +166,7 @@ fn make(&mut self, n: uint) {
             let chars_left = n % LINE_LEN;
             let mut buf = [0, ..LINE_LEN + 1];
 
-            do lines.times {
+            for _ in range(0, lines) {
                 for i in range(0u, LINE_LEN) {
                     buf[i] = self.nextc();
                 }
index 96fd4d7e604e7888c803b6b0a1285b1757fa8026..2b5b4ded94774690913cd7136db00954f26a387d 100644 (file)
@@ -54,7 +54,7 @@ fn pack(string: &str) -> Code {
     fn unpack(&self, frame: i32) -> ~str {
         let mut key = **self;
         let mut result = ~[];
-        do (frame as uint).times {
+        for _ in range(0, frame) {
             result.push(unpack_symbol((key as u8) & 3));
             key >>= 2;
         }
@@ -251,7 +251,7 @@ fn generate_frequencies(frequencies: &mut Table,
     let mut code = Code(0);
 
     // Pull first frame.
-    do (frame as uint).times {
+    for _ in range(0, frame) {
         code = code.push_char(input[0]);
         input = next_char(input);
     }
index cf43f470e7177d55e2fcf77b0c57061fc03d02a7..72007d2b50a98029c4260233407733ebbe4bee7a 100644 (file)
@@ -1,3 +1,5 @@
+// xfail-test reading from os::args()[1] - bogus!
+
 use std::cast::transmute;
 use std::from_str::FromStr;
 use std::libc::{STDOUT_FILENO, c_int, fdopen, fputc};
index 115607d0a992c14896d3d227799dee2dbc611bbf..0f43d5027a9133e6a331146ece4cafb105d6874b 100644 (file)
@@ -1,3 +1,5 @@
+// xfail-test reading from os::args()[1] - bogus!
+
 use std::from_str::FromStr;
 use std::os;
 
@@ -79,7 +81,7 @@ struct Planet {
 
 fn advance(bodies: &mut [Planet, ..N_BODIES], dt: f64, steps: i32) {
     let mut d = [ 0.0, ..3 ];
-    do (steps as uint).times {
+    for _ in range(0, steps) {
         for i in range(0u, N_BODIES) {
             for j in range(i + 1, N_BODIES) {
                 d[0] = bodies[i].x[0] - bodies[j].x[0];
index aef22bc2b8426f056a4047abb81092e288f9ece6..d7f5e5781e0ebc6659000b389d15c79bc2d27c59 100644 (file)
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// xfail-test reading from os::args()[1] - bogus!
+
 use std::from_str::FromStr;
 use std::os;
 use std::vec;
@@ -56,7 +58,7 @@ fn main() {
     let mut u = vec::from_elem(n, 1f64);
     let mut v = u.clone();
     let mut tmp = u.clone();
-    do 8.times {
+    for _ in range(0, 8u) {
         mult_AtAv(u, v, tmp);
         mult_AtAv(v, u, tmp);
     }
index ca539d712fdefb726cc41082f7524fe2a4d53d89..114c7e997a24f67cd22b4195ae6d4221c126d776 100644 (file)
@@ -32,7 +32,7 @@ fn main() {
 }
 
 fn run(repeat: int, depth: int) {
-    do (repeat as uint).times {
+    for _ in range(0, repeat) {
         info!("starting %.4f", precise_time_s());
         do task::try {
             recurse_or_fail(depth, None)
index 95dd803af8183221f00bbc21ee6a2c56bbabd3e9..7788005775f7897e20fbede324d5fb0318432326 100644 (file)
@@ -32,16 +32,19 @@ fn grandchild_group(num_tasks: uint) {
     let (po, ch) = stream();
     let ch = SharedChan::new(ch);
 
-    do num_tasks.times {
+    for _ in range(0, num_tasks) {
         let ch = ch.clone();
-        do task::spawn { // linked
+        let mut t = task::task();
+        t.linked();
+        t.unwatched();
+        do t.spawn { // linked
             ch.send(());
             let (p, _c) = stream::<()>();
             p.recv(); // block forever
         }
     }
     error!("Grandchild group getting started");
-    do num_tasks.times {
+    for _ in range(0, num_tasks) {
         // Make sure all above children are fully spawned; i.e., enlisted in
         // their ancestor groups.
         po.recv();
index 6d3b157d63e802136c322e4c08cf55b9dd444c1e..3bf3507faba779d02ca9d63b3db56832d7846158 100644 (file)
@@ -9,6 +9,7 @@
 // except according to those terms.
 
 // xfail-win32 Broken because of LLVM bug: http://llvm.org/bugs/show_bug.cgi?id=16249
+// xfail-test broken in newrt?
 
 // compile-flags:-Z extra-debug-info
 // debugger:break zzz
index a281e9863649eb4455ea30c7496262dab4d02753..a65db3ee51543db658e8db9dc155658e0a491f1c 100644 (file)
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// xfail-test linked failure
 // error-pattern:explicit failure
 // Testing that runtime failure doesn't cause callbacks to abort abnormally.
 // Instead the failure will be delivered after the callbacks return.
index 41a9d7ddcea1fc47445b0ee846783ac6e3488ebb..52dfb8aef13d56b484623c22b4250146ed8452c3 100644 (file)
@@ -10,6 +10,7 @@
 // except according to those terms.
 
 
+// xfail-test linked failure
 // error-pattern:1 == 2
 extern mod extra;
 
index 0269e3959868d9d899a1683ac45a30ebb9f5c43e..d4049f6753ee89204fd75c57be84b2dc9eac15c5 100644 (file)
@@ -10,6 +10,7 @@
 // except according to those terms.
 
 
+// xfail-test linked failure
 // error-pattern:fail
 
 use std::comm;
index 1203f74322febe0e0e5b6c9796916f15a69c0d9a..f40eae20bc0bc386b6e7276e009e22345914c2f0 100644 (file)
@@ -10,6 +10,7 @@
 // except according to those terms.
 
 
+// xfail-test linked failure
 // error-pattern:fail
 
 use std::comm;
index 766b43f211f46c52372376fed0b9c251cf8ad95c..94e41f1ae682565703aeb17bf725573209866b76 100644 (file)
@@ -9,6 +9,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// xfail-test linked failure
 // error-pattern:1 == 2
 
 use std::comm;
index de085a6f3addbc925639d524de97784e861b7788..12dab8e25b780755829b5d325667241f69600f0b 100644 (file)
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// xfail-test linked failure
 // xfail-win32
 // error-pattern:explicit
 extern mod extra;
index 8302b96ca3ef7395e09cf41e099724a891d5192d..bd51ce38ec0e47bc03d38444eebc5d5437d1ec6a 100644 (file)
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// xfail-test linked failure
 // error-pattern:goodfail
 
 use std::comm;
diff --git a/src/test/run-pass/class-impl-parameterized-trait.rs b/src/test/run-pass/class-impl-parameterized-trait.rs
deleted file mode 100644 (file)
index 93e9eac..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// xfail-test FIXME #7307
-// xfail-fast
-
-extern mod extra;
-use extra::oldmap::*;
-
-class cat : map<int, bool> {
-  priv {
-    // Yes, you can have negative meows
-    let mut meows : int;
-    fn meow() {
-      self.meows += 1;
-      error!("Meow %d", self.meows);
-      if self.meows % 5 == 0 {
-          self.how_hungry += 1;
-      }
-    }
-  }
-
-  let mut how_hungry : int;
-  let name : str;
-
-  new(in_x : int, in_y : int, in_name: str)
-    { self.meows = in_x; self.how_hungry = in_y; self.name = in_name; }
-
-  fn speak() { self.meow(); }
-
-  fn eat() -> bool {
-    if self.how_hungry > 0 {
-        error!("OM NOM NOM");
-        self.how_hungry -= 2;
-        return true;
-    }
-    else {
-        error!("Not hungry!");
-        return false;
-    }
-  }
-
-  fn size() -> uint { self.meows as uint }
-  fn insert(+k: int, +v: bool) -> bool {
-    if v { self.meows += k; } else { self.meows -= k; };
-    true
-  }
-  fn contains_key(&&k: int) -> bool { k <= self.meows }
-  fn get(&&k:int) -> bool { k <= self.meows }
-  fn [](&&k:int) -> bool { k <= self.meows }
-  fn find(&&k:int) -> Option<bool> { Some(self.get(k)) }
-  fn remove(&&k:int) -> Option<bool> { self.meows -= k; Some(true) }
-  fn each(f: &fn(&&int, &&bool) -> bool) {
-    let mut n = num::abs(self.meows);
-    while n > 0 {
-        if !f(n, true) { break; }
-        n -= 1;
-    }
-  }
-  fn each_key(&&f: &fn(&&int) -> bool) {
-    for self.each |k, _v| { if !f(k) { break; } again;};
-  }
-  fn each_value(&&f: &fn(&&bool) -> bool) {
-    for self.each |_k, v| { if !f(v) { break; } again;};
-  }
-  fn clear() { }
-}
-
-pub fn main() {
-  let nyan : cat = cat(0, 2, "nyan");
-  for _ in range(1u, 5u) { nyan.speak(); }
-  // cat returns true if uint input is greater than
-  // the number of meows so far
-  assert!((nyan.get(1)));
-  assert!((!nyan.get(10)));
-}
diff --git a/src/test/run-pass/class-implements-multiple-traits.rs b/src/test/run-pass/class-implements-multiple-traits.rs
deleted file mode 100644 (file)
index 4fccc45..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// xfail-test FIXME #7305
-
-extern mod extra;
-use extra::oldmap::*;
-use vec::*;
-use dvec::{dvec, extensions};
-
-enum furniture { chair, couch, bed }
-enum body_part { finger, toe, nose, ear }
-
-trait noisy {
-  fn speak() -> int;
-}
-
-trait scratchy {
-  fn scratch() -> Option<furniture>;
-}
-
-trait bitey {
-  fn bite() -> body_part;
-}
-
-fn vec_includes<T>(xs: ~[T], x: T) -> bool {
-  for each(xs) |y| { if y == x { return true; }}
-  return false;
-}
-
-// vtables other than the 1st one don't seem to work
-class cat : noisy, scratchy, bitey {
-  priv {
-    let meows : @mut uint;
-    let scratched : dvec<furniture>;
-    let bite_counts : hashmap<body_part, uint>;
-
-    fn meow() -> uint {
-      info!("Meow: %u", *self.meows);
-      *self.meows += 1u;
-      if *self.meows % 5u == 0u {
-          *self.how_hungry += 1;
-      }
-      *self.meows
-    }
-  }
-
-  let how_hungry : @mut int;
-  let name : str;
-
-  new(in_x : uint, in_y : int, in_name: str)
-    { self.meows = @mut in_x; self.how_hungry = @mut in_y;
-      self.name = in_name; self.scratched = dvec();
-      let hsher: hashfn<body_part> = |p| int::hash(p as int);
-      let eqer : eqfn<body_part> = |p, q| p == q;
-      let t : hashmap<body_part, uint> =
-        hashmap::<body_part, uint>(hsher, eqer);
-      self.bite_counts = t;
-     do iter(~[finger, toe, nose, ear]) |p| {
-          self.bite_counts.insert(p, 0u);
-      };
-    }
-
-  fn speak() -> int { self.meow() as int }
-  fn meow_count() -> uint { *self.meows }
-  fn scratch() -> Option<furniture> {
-    let all = ~[chair, couch, bed];
-    log(error, self.scratched);
-    let mut rslt = None;
-    for each(all) |thing| { if !self.scratched.contains(thing) {
-          self.scratched.push(thing);
-          return Some(thing); }}
-    rslt
-  }
-  fn bite() -> body_part {
-    error!("In bite()");
-    let all = ~[toe, nose, ear];
-    let mut min = finger;
-    do iter(all) |next| {
-      info!("min = %?", min);
-        if self.bite_counts.get(next) < self.bite_counts.get(min) {
-            min = next;
-          }};
-    self.bite_counts.insert(min, self.bite_counts.get(min) + 1u);
-    info!("Bit %?", min);
-    min
-  }
-}
-
-fn annoy_neighbors<T:noisy>(critter: T) {
-  for i in range(0u, 10u) {
-      let what = critter.speak();
-      info!("%u %d", i, what);
-  }
-}
-
-fn bite_everything<T:bitey>(critter: T) -> bool {
-  let mut left : ~[body_part] = ~[finger, toe, nose, ear];
-  while left.len() > 0u {
-    let part = critter.bite();
-    info!("%? %?", left, part);
-    if vec_includes(left, part) {
-        left = vec::filter(left, |p| p != part );
-    }
-    else {
-      return false;
-    }
-  }
-  true
-}
-
-fn scratched_something<T:scratchy>(critter: T) -> bool {
-  option::is_some(critter.scratch())
-}
-
-pub fn main() {
-  let nyan : cat  = cat(0u, 2, "nyan");
-  annoy_neighbors(nyan as noisy);
-  assert_eq!(nyan.meow_count(), 10u);
-  assert!((bite_everything(nyan as bitey)));
-  assert!((scratched_something(nyan as scratchy)));
-}
index 7fb01006844af5a7ee43b7e0c33b4865da993c51..b31f0eab2e2239494bef52c7d1464ecfd0a982ad 100644 (file)
@@ -12,10 +12,4 @@ fn sum_imm(y: &[int]) -> int {
     sum(y)
 }
 
-/* FIXME #7304
-fn sum_const(y: &const [int]) -> int {
-    sum(y)
-}
-*/
-
 pub fn main() {}
index 590cd8250208a7fbb221d477c589b4de5cc49644..8a271a4d65f3c06f5ac728c3c24464bf00cef97b 100644 (file)
@@ -1,9 +1,3 @@
-/* FIXME #7302
-fn foo(v: &const [uint]) -> ~[uint] {
-    v.to_owned()
-}
-*/
-
 fn bar(v: &mut [uint]) -> ~[uint] {
     v.to_owned()
 }
@@ -14,7 +8,6 @@ fn bip(v: &[uint]) -> ~[uint] {
 
 pub fn main() {
     let mut the_vec = ~[1u, 2, 3, 100];
-//    assert_eq!(the_vec.clone(), foo(the_vec));
     assert_eq!(the_vec.clone(), bar(the_vec));
     assert_eq!(the_vec.clone(), bip(the_vec));
 }
diff --git a/src/test/run-pass/deriving-cmp-shortcircuit.rs b/src/test/run-pass/deriving-cmp-shortcircuit.rs
new file mode 100644 (file)
index 0000000..7f5c78c
--- /dev/null
@@ -0,0 +1,46 @@
+// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// check that the derived impls for the comparison traits shortcircuit
+// where possible, by having a type that fails when compared as the
+// second element, so this passes iff the instances shortcircuit.
+
+pub struct FailCmp;
+impl Eq for FailCmp {
+    fn eq(&self, _: &FailCmp) -> bool { fail!("eq") }
+}
+
+impl Ord for FailCmp {
+    fn lt(&self, _: &FailCmp) -> bool { fail!("lt") }
+}
+
+impl TotalEq for FailCmp {
+    fn equals(&self, _: &FailCmp) -> bool { fail!("equals") }
+}
+
+impl TotalOrd for FailCmp {
+    fn cmp(&self, _: &FailCmp) -> Ordering { fail!("cmp") }
+}
+
+#[deriving(Eq,Ord,TotalEq,TotalOrd)]
+struct ShortCircuit {
+    x: int,
+    y: FailCmp
+}
+
+fn main() {
+    let a = ShortCircuit { x: 1, y: FailCmp };
+    let b = ShortCircuit { x: 2, y: FailCmp };
+
+    assert!(a != b);
+    assert!(a < b);
+    assert!(!a.equals(&b));
+    assert_eq!(a.cmp(&b), ::std::cmp::Less);
+}
index 609849bffb4887b354af242e4fe0a3468d852d36..f4e2a9f36a072b5e34f6cdec6f0faeaa2e3dfb36 100644 (file)
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// xfail-test linked failure
 // xfail-fast
 // xfail-win32 #7999
 
index cec0a7a756c9fee8bfc77db20ba8a9cd3369fbab..13296131236ab25080245cf119baaa2f06e22461 100644 (file)
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// xfail-test linked failure
 // xfail-win32 leaks
 extern mod extra;
 
index 28396119596b0d94fbe1ee8cf2a5901019fda8e3..46819027dad649719e9ab9da908260a5800ab863 100644 (file)
@@ -12,7 +12,9 @@ trait get {
     fn get(self) -> int;
 }
 
-// FIXME #7302: Note: impl on a slice
+// Note: impl on a slice; we're checking that the pointers below
+// correctly get borrowed to `&`. (similar to impling for `int`, with
+// `&self` instead of `self`.)
 impl<'self> get for &'self int {
     fn get(self) -> int {
         return *self;
@@ -34,11 +36,6 @@ pub fn main() {
     info!("y=%d", y);
     assert_eq!(y, 6);
 
-    let x = ~6;
-    let y = x.get();
-    info!("y=%d", y);
-    assert_eq!(y, 6);
-
     let x = &6;
     let y = x.get();
     info!("y=%d", y);
index e27f35d1851d52c743dab38ba5d78240113a62fb..a647e5849a8ee4036ab9eb63f7dda69904271b22 100644 (file)
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// xfail-test linked failure
 // xfail-win32
 extern mod extra;
 
index c811e548f3fb18f0226b94baba937a32634ea43e..b8a1aa433a30a3e6492d7876dac1162a60168919 100644 (file)
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// xfail-test linked failure
 // xfail-win32
 
 // A port of task-killjoin to use a class with a dtor to manage
index c94e00251d28a64f03b0936a0734fecf47fcfde5..5382ac77671392787232a58d60b1c4d8d1973f22 100644 (file)
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// xfail-test linked failure
 // xfail-win32
 
 // Create a task that is supervised by another task, join the supervised task