diff --git a/src/libextra/arc.rs b/src/libextra/arc.rs index 3aa77577fb2e4..af69997f02e8d 100644 --- a/src/libextra/arc.rs +++ b/src/libextra/arc.rs @@ -140,14 +140,14 @@ impl Arc { } } -/** - * Duplicate an atomically reference counted wrapper. - * - * The resulting two `arc` objects will point to the same underlying data - * object. However, one of the `arc` objects can be sent to another task, - * allowing them to share the underlying data. - */ impl Clone for Arc { + /** + * Duplicate an atomically reference counted wrapper. + * + * The resulting two `arc` objects will point to the same underlying data + * object. However, one of the `arc` objects can be sent to another task, + * allowing them to share the underlying data. + */ fn clone(&self) -> Arc { Arc { x: self.x.clone() } } @@ -164,7 +164,7 @@ struct MutexArc { priv x: UnsafeAtomicRcBox> } impl Clone for MutexArc { - /// Duplicate a mutex-protected Arc, as arc::clone. + /// Duplicate a mutex-protected Arc. See arc::clone for more details. fn clone(&self) -> MutexArc { // NB: Cloning the underlying mutex is not necessary. Its reference // count would be exactly the same as the shared state's. @@ -312,12 +312,10 @@ struct RWArc { priv x: UnsafeAtomicRcBox>, } -impl RWArc { - /// Duplicate a rwlock-protected Arc, as arc::clone. - pub fn clone(&self) -> RWArc { - RWArc { - x: self.x.clone(), - } +impl Clone for RWArc { + /// Duplicate a rwlock-protected Arc. See arc::clone for more details. + fn clone(&self) -> RWArc { + RWArc { x: self.x.clone() } } } diff --git a/src/libextra/bitv.rs b/src/libextra/bitv.rs index 7a71d3f667f78..42f3fdc52798d 100644 --- a/src/libextra/bitv.rs +++ b/src/libextra/bitv.rs @@ -1638,9 +1638,9 @@ mod tests { fn bench_btv_small_iter(b: &mut BenchHarness) { let bitv = Bitv::new(uint::bits, false); do b.iter { - let mut sum = 0; + let mut _sum = 0; foreach pres in bitv.iter() { - sum += pres as uint; + _sum += pres as uint; } } } @@ -1649,9 +1649,9 @@ mod tests { fn bench_bitv_big_iter(b: &mut BenchHarness) { let bitv = Bitv::new(BENCH_BITS, false); do b.iter { - let mut sum = 0; + let mut _sum = 0; foreach pres in bitv.iter() { - sum += pres as uint; + _sum += pres as uint; } } } @@ -1661,9 +1661,9 @@ mod tests { let bitv = BitvSet::from_bitv(from_fn(BENCH_BITS, |idx| {idx % 3 == 0})); do b.iter { - let mut sum = 0; + let mut _sum = 0; foreach idx in bitv.iter() { - sum += idx; + _sum += idx; } } } diff --git a/src/libextra/flatpipes.rs b/src/libextra/flatpipes.rs index 9e7294df4b7eb..b43962dae40fe 100644 --- a/src/libextra/flatpipes.rs +++ b/src/libextra/flatpipes.rs @@ -633,16 +633,12 @@ pub mod bytepipes { #[cfg(test)] mod test { - use flatpipes::{Flattener, Unflattener}; - use flatpipes::bytepipes::*; + use flatpipes::BytePort; use flatpipes::pod; use flatpipes::serial; use io_util::BufReader; - use flatpipes::{BytePort, FlatChan, FlatPort}; - use std::comm; use std::io::BytesWriter; - use std::result; use std::task; #[test] @@ -727,7 +723,11 @@ mod test { // FIXME #2064: Networking doesn't work on x86 // XXX Broken until networking support is added back - /*#[test] + /* + use flatpipes::{Flattener, Unflattener, FlatChan, FlatPort}; + use flatpipes::bytepipes::*; + + #[test] #[cfg(target_arch = "x86_64")] fn test_pod_tcp_stream() { fn reader_port(buf: TcpSocketBuf @@ -767,6 +767,8 @@ mod test { port: uint) { use std::cell::Cell; + use std::comm; + use std::result; use net::ip; use net::tcp; use uv; diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 5f9351e4e12e7..9922106a66380 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -1159,7 +1159,7 @@ fn store_non_ref_bindings(bcx: @mut Block, add_clean_temp_mem(bcx, lldest, binding_info.ty); temp_cleanups.push(lldest); temp_cleanups - } + }; } TrByRef => {} } diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 0a72e907ae8ae..feecb82eaab90 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -2750,13 +2750,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, } ast::expr_vec(ref args, mutbl) => { let t: ty::t = fcx.infcx().next_ty_var(); - let mut arg_is_bot = false; - let mut arg_is_err = false; foreach e in args.iter() { check_expr_has_type(fcx, *e, t); - let arg_t = fcx.expr_ty(*e); - arg_is_bot |= ty::type_is_bot(arg_t); - arg_is_err |= ty::type_is_error(arg_t); } let typ = ty::mk_evec(tcx, ty::mt {ty: t, mutbl: mutbl}, ty::vstore_fixed(args.len())); diff --git a/src/libstd/logging.rs b/src/libstd/logging.rs index 6e11d14aea9a3..c662e5997afa6 100644 --- a/src/libstd/logging.rs +++ b/src/libstd/logging.rs @@ -85,6 +85,16 @@ pub fn log_type(level: u32, object: &T) { fn newsched_log_str(msg: ~str) { use rt::task::Task; use rt::local::Local; + use str::StrSlice; + use container::Container; + + // Truncate the string + let buf_bytes = 256; + let msg = if msg.len() > buf_bytes { + msg.slice(0, buf_bytes) + "[...]" + } else { + msg + }; unsafe { match Local::try_unsafe_borrow::() { diff --git a/src/libstd/option.rs b/src/libstd/option.rs index 7eca47743d6a6..547c453b02d1a 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -235,19 +235,24 @@ impl Option { self.take().map_consume_default(def, blk) } - /// Apply a function to the contained value or do nothing - pub fn mutate(&mut self, f: &fn(T) -> T) { + /// 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 { if self.is_some() { *self = Some(f(self.take_unwrap())); - } + true + } else { false } } - /// Apply a function to the contained value or set it to a default - pub fn mutate_default(&mut self, def: T, f: &fn(T) -> T) { + /// Apply a function to the contained value or set it to a default. + /// Returns true if the contained value was mutated, or false if set to the default. + pub fn mutate_default(&mut self, def: T, f: &fn(T) -> T) -> bool { if self.is_some() { *self = Some(f(self.take_unwrap())); + true } else { *self = Some(def); + false } } @@ -575,4 +580,18 @@ mod tests { assert_eq!(it.size_hint(), (0, Some(0))); assert!(it.next().is_none()); } + + #[test] + fn test_mutate() { + let mut x = Some(3i); + assert!(x.mutate(|i| i+1)); + assert_eq!(x, Some(4i)); + assert!(x.mutate_default(0, |i| i+1)); + assert_eq!(x, Some(5i)); + x = None; + assert!(!x.mutate(|i| i+1)); + assert_eq!(x, None); + assert!(!x.mutate_default(0i, |i| i+1)); + assert_eq!(x, Some(0i)); + } } diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index ad5ded2002a2d..1f6adaf040b7e 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -2141,11 +2141,15 @@ macro_rules! iterator { None } else { let old = self.ptr; - // purposefully don't use 'ptr.offset' because for - // vectors with 0-size elements this would return the - // same pointer. - self.ptr = cast::transmute(self.ptr as uint + - sys::nonzero_size_of::()); + self.ptr = if sys::size_of::() == 0 { + // purposefully don't use 'ptr.offset' because for + // vectors with 0-size elements this would return the + // same pointer. + cast::transmute(self.ptr as uint + 1) + } else { + self.ptr.offset(1) + }; + Some(cast::transmute(old)) } } @@ -2171,9 +2175,12 @@ macro_rules! double_ended_iterator { if self.end == self.ptr { None } else { - // See above for why 'ptr.offset' isn't used - self.end = cast::transmute(self.end as uint - - sys::nonzero_size_of::()); + self.end = if sys::size_of::() == 0 { + // See above for why 'ptr.offset' isn't used + cast::transmute(self.end as uint - 1) + } else { + self.end.offset(-1) + }; Some(cast::transmute(self.end)) } } @@ -3566,3 +3573,39 @@ mod tests { assert!(cnt == 3); } } + +#[cfg(test)] +mod bench { + use extra::test::BenchHarness; + use vec; + use option::*; + + #[bench] + fn iterator(bh: &mut BenchHarness) { + // peculiar numbers to stop LLVM from optimising the summation + // out. + let v = vec::from_fn(100, |i| i ^ (i << 1) ^ (i >> 1)); + + do bh.iter { + let mut sum = 0; + foreach x in v.iter() { + sum += *x; + } + // sum == 11806, to stop dead code elimination. + if sum == 0 {fail!()} + } + } + + #[bench] + fn mut_iterator(bh: &mut BenchHarness) { + let mut v = vec::from_elem(100, 0); + + do bh.iter { + let mut i = 0; + foreach x in v.mut_iter() { + *x = i; + i += 1; + } + } + } +} diff --git a/src/test/run-fail/assert-macro-explicit.rs b/src/test/run-fail/assert-macro-explicit.rs index 8c35c92ffb0ba..8e70c2c3561a2 100644 --- a/src/test/run-fail/assert-macro-explicit.rs +++ b/src/test/run-fail/assert-macro-explicit.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:task failed at 'assertion failed: false' +// error-pattern:failed at 'assertion failed: false' fn main() { assert!(false); diff --git a/src/test/run-fail/assert-macro-fmt.rs b/src/test/run-fail/assert-macro-fmt.rs index d239760537821..2159f68cc7170 100644 --- a/src/test/run-fail/assert-macro-fmt.rs +++ b/src/test/run-fail/assert-macro-fmt.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:task failed at 'test-assert-fmt 42 rust' +// error-pattern:failed at 'test-assert-fmt 42 rust' fn main() { assert!(false, "test-assert-fmt %d %s", 42, "rust"); diff --git a/src/test/run-fail/assert-macro-owned.rs b/src/test/run-fail/assert-macro-owned.rs index baa47dbbd356d..f45af290b3d3d 100644 --- a/src/test/run-fail/assert-macro-owned.rs +++ b/src/test/run-fail/assert-macro-owned.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:task failed at 'test-assert-owned' +// error-pattern:failed at 'test-assert-owned' fn main() { assert!(false, ~"test-assert-owned"); diff --git a/src/test/run-fail/assert-macro-static.rs b/src/test/run-fail/assert-macro-static.rs index d47455173d1b9..a35258462deaa 100644 --- a/src/test/run-fail/assert-macro-static.rs +++ b/src/test/run-fail/assert-macro-static.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:task failed at 'test-assert-static' +// error-pattern:failed at 'test-assert-static' fn main() { assert!(false, "test-assert-static"); diff --git a/src/test/run-fail/fail-macro-explicit.rs b/src/test/run-fail/fail-macro-explicit.rs index eac80db40b9d2..13e3a6a31a8fa 100644 --- a/src/test/run-fail/fail-macro-explicit.rs +++ b/src/test/run-fail/fail-macro-explicit.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:task failed at 'explicit failure' +// error-pattern:failed at 'explicit failure' fn main() { fail!(); diff --git a/src/test/run-fail/fail-macro-fmt.rs b/src/test/run-fail/fail-macro-fmt.rs index 363c572f3fe1e..5fc51ac674581 100644 --- a/src/test/run-fail/fail-macro-fmt.rs +++ b/src/test/run-fail/fail-macro-fmt.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:task failed at 'test-fail-fmt 42 rust' +// error-pattern:failed at 'test-fail-fmt 42 rust' fn main() { fail!("test-fail-fmt %d %s", 42, "rust"); diff --git a/src/test/run-fail/fail-macro-owned.rs b/src/test/run-fail/fail-macro-owned.rs index e424647569a9f..e59f5bdcaa179 100644 --- a/src/test/run-fail/fail-macro-owned.rs +++ b/src/test/run-fail/fail-macro-owned.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:task failed at 'test-fail-owned' +// error-pattern:failed at 'test-fail-owned' fn main() { fail!("test-fail-owned"); diff --git a/src/test/run-fail/fail-macro-static.rs b/src/test/run-fail/fail-macro-static.rs index 3235dc761a29d..688ca4ce7e572 100644 --- a/src/test/run-fail/fail-macro-static.rs +++ b/src/test/run-fail/fail-macro-static.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:task failed at 'test-fail-static' +// error-pattern:failed at 'test-fail-static' fn main() { fail!("test-fail-static");