Skip to content

Commit 20fad0f

Browse files
committed
auto merge of #8257 : mozilla/rust/rollup, r=thestinger
1f9c392 r=brson 54e685d r=graydon 1992765 r=thestinger 75155cd r=bblum def8891 r=graydon
2 parents deddb00 + def8891 commit 20fad0f

16 files changed

+120
-53
lines changed

src/libextra/arc.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,14 @@ impl<T:Freeze+Send> Arc<T> {
140140
}
141141
}
142142

143-
/**
144-
* Duplicate an atomically reference counted wrapper.
145-
*
146-
* The resulting two `arc` objects will point to the same underlying data
147-
* object. However, one of the `arc` objects can be sent to another task,
148-
* allowing them to share the underlying data.
149-
*/
150143
impl<T:Freeze + Send> Clone for Arc<T> {
144+
/**
145+
* Duplicate an atomically reference counted wrapper.
146+
*
147+
* The resulting two `arc` objects will point to the same underlying data
148+
* object. However, one of the `arc` objects can be sent to another task,
149+
* allowing them to share the underlying data.
150+
*/
151151
fn clone(&self) -> Arc<T> {
152152
Arc { x: self.x.clone() }
153153
}
@@ -164,7 +164,7 @@ struct MutexArc<T> { priv x: UnsafeAtomicRcBox<MutexArcInner<T>> }
164164

165165

166166
impl<T:Send> Clone for MutexArc<T> {
167-
/// Duplicate a mutex-protected Arc, as arc::clone.
167+
/// Duplicate a mutex-protected Arc. See arc::clone for more details.
168168
fn clone(&self) -> MutexArc<T> {
169169
// NB: Cloning the underlying mutex is not necessary. Its reference
170170
// count would be exactly the same as the shared state's.
@@ -312,12 +312,10 @@ struct RWArc<T> {
312312
priv x: UnsafeAtomicRcBox<RWArcInner<T>>,
313313
}
314314
315-
impl<T:Freeze + Send> RWArc<T> {
316-
/// Duplicate a rwlock-protected Arc, as arc::clone.
317-
pub fn clone(&self) -> RWArc<T> {
318-
RWArc {
319-
x: self.x.clone(),
320-
}
315+
impl<T:Freeze + Send> Clone for RWArc<T> {
316+
/// Duplicate a rwlock-protected Arc. See arc::clone for more details.
317+
fn clone(&self) -> RWArc<T> {
318+
RWArc { x: self.x.clone() }
321319
}
322320
323321
}

src/libextra/bitv.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1638,9 +1638,9 @@ mod tests {
16381638
fn bench_btv_small_iter(b: &mut BenchHarness) {
16391639
let bitv = Bitv::new(uint::bits, false);
16401640
do b.iter {
1641-
let mut sum = 0;
1641+
let mut _sum = 0;
16421642
foreach pres in bitv.iter() {
1643-
sum += pres as uint;
1643+
_sum += pres as uint;
16441644
}
16451645
}
16461646
}
@@ -1649,9 +1649,9 @@ mod tests {
16491649
fn bench_bitv_big_iter(b: &mut BenchHarness) {
16501650
let bitv = Bitv::new(BENCH_BITS, false);
16511651
do b.iter {
1652-
let mut sum = 0;
1652+
let mut _sum = 0;
16531653
foreach pres in bitv.iter() {
1654-
sum += pres as uint;
1654+
_sum += pres as uint;
16551655
}
16561656
}
16571657
}
@@ -1661,9 +1661,9 @@ mod tests {
16611661
let bitv = BitvSet::from_bitv(from_fn(BENCH_BITS,
16621662
|idx| {idx % 3 == 0}));
16631663
do b.iter {
1664-
let mut sum = 0;
1664+
let mut _sum = 0;
16651665
foreach idx in bitv.iter() {
1666-
sum += idx;
1666+
_sum += idx;
16671667
}
16681668
}
16691669
}

src/libextra/flatpipes.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -633,16 +633,12 @@ pub mod bytepipes {
633633
#[cfg(test)]
634634
mod test {
635635

636-
use flatpipes::{Flattener, Unflattener};
637-
use flatpipes::bytepipes::*;
636+
use flatpipes::BytePort;
638637
use flatpipes::pod;
639638
use flatpipes::serial;
640639
use io_util::BufReader;
641-
use flatpipes::{BytePort, FlatChan, FlatPort};
642640

643-
use std::comm;
644641
use std::io::BytesWriter;
645-
use std::result;
646642
use std::task;
647643

648644
#[test]
@@ -727,7 +723,11 @@ mod test {
727723

728724
// FIXME #2064: Networking doesn't work on x86
729725
// XXX Broken until networking support is added back
730-
/*#[test]
726+
/*
727+
use flatpipes::{Flattener, Unflattener, FlatChan, FlatPort};
728+
use flatpipes::bytepipes::*;
729+
730+
#[test]
731731
#[cfg(target_arch = "x86_64")]
732732
fn test_pod_tcp_stream() {
733733
fn reader_port(buf: TcpSocketBuf
@@ -767,6 +767,8 @@ mod test {
767767
port: uint) {
768768
769769
use std::cell::Cell;
770+
use std::comm;
771+
use std::result;
770772
use net::ip;
771773
use net::tcp;
772774
use uv;

src/librustc/middle/trans/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ fn store_non_ref_bindings(bcx: @mut Block,
11591159
add_clean_temp_mem(bcx, lldest, binding_info.ty);
11601160
temp_cleanups.push(lldest);
11611161
temp_cleanups
1162-
}
1162+
};
11631163
}
11641164
TrByRef => {}
11651165
}

src/librustc/middle/typeck/check/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -2750,13 +2750,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
27502750
}
27512751
ast::expr_vec(ref args, mutbl) => {
27522752
let t: ty::t = fcx.infcx().next_ty_var();
2753-
let mut arg_is_bot = false;
2754-
let mut arg_is_err = false;
27552753
foreach e in args.iter() {
27562754
check_expr_has_type(fcx, *e, t);
2757-
let arg_t = fcx.expr_ty(*e);
2758-
arg_is_bot |= ty::type_is_bot(arg_t);
2759-
arg_is_err |= ty::type_is_error(arg_t);
27602755
}
27612756
let typ = ty::mk_evec(tcx, ty::mt {ty: t, mutbl: mutbl},
27622757
ty::vstore_fixed(args.len()));

src/libstd/logging.rs

+10
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ pub fn log_type<T>(level: u32, object: &T) {
8585
fn newsched_log_str(msg: ~str) {
8686
use rt::task::Task;
8787
use rt::local::Local;
88+
use str::StrSlice;
89+
use container::Container;
90+
91+
// Truncate the string
92+
let buf_bytes = 256;
93+
let msg = if msg.len() > buf_bytes {
94+
msg.slice(0, buf_bytes) + "[...]"
95+
} else {
96+
msg
97+
};
8898

8999
unsafe {
90100
match Local::try_unsafe_borrow::<Task>() {

src/libstd/option.rs

+24-5
Original file line numberDiff line numberDiff line change
@@ -235,19 +235,24 @@ impl<T> Option<T> {
235235
self.take().map_consume_default(def, blk)
236236
}
237237

238-
/// Apply a function to the contained value or do nothing
239-
pub fn mutate(&mut self, f: &fn(T) -> T) {
238+
/// Apply a function to the contained value or do nothing.
239+
/// Returns true if the contained value was mutated.
240+
pub fn mutate(&mut self, f: &fn(T) -> T) -> bool {
240241
if self.is_some() {
241242
*self = Some(f(self.take_unwrap()));
242-
}
243+
true
244+
} else { false }
243245
}
244246

245-
/// Apply a function to the contained value or set it to a default
246-
pub fn mutate_default(&mut self, def: T, f: &fn(T) -> T) {
247+
/// Apply a function to the contained value or set it to a default.
248+
/// Returns true if the contained value was mutated, or false if set to the default.
249+
pub fn mutate_default(&mut self, def: T, f: &fn(T) -> T) -> bool {
247250
if self.is_some() {
248251
*self = Some(f(self.take_unwrap()));
252+
true
249253
} else {
250254
*self = Some(def);
255+
false
251256
}
252257
}
253258

@@ -575,4 +580,18 @@ mod tests {
575580
assert_eq!(it.size_hint(), (0, Some(0)));
576581
assert!(it.next().is_none());
577582
}
583+
584+
#[test]
585+
fn test_mutate() {
586+
let mut x = Some(3i);
587+
assert!(x.mutate(|i| i+1));
588+
assert_eq!(x, Some(4i));
589+
assert!(x.mutate_default(0, |i| i+1));
590+
assert_eq!(x, Some(5i));
591+
x = None;
592+
assert!(!x.mutate(|i| i+1));
593+
assert_eq!(x, None);
594+
assert!(!x.mutate_default(0i, |i| i+1));
595+
assert_eq!(x, Some(0i));
596+
}
578597
}

src/libstd/vec.rs

+51-8
Original file line numberDiff line numberDiff line change
@@ -2141,11 +2141,15 @@ macro_rules! iterator {
21412141
None
21422142
} else {
21432143
let old = self.ptr;
2144-
// purposefully don't use 'ptr.offset' because for
2145-
// vectors with 0-size elements this would return the
2146-
// same pointer.
2147-
self.ptr = cast::transmute(self.ptr as uint +
2148-
sys::nonzero_size_of::<T>());
2144+
self.ptr = if sys::size_of::<T>() == 0 {
2145+
// purposefully don't use 'ptr.offset' because for
2146+
// vectors with 0-size elements this would return the
2147+
// same pointer.
2148+
cast::transmute(self.ptr as uint + 1)
2149+
} else {
2150+
self.ptr.offset(1)
2151+
};
2152+
21492153
Some(cast::transmute(old))
21502154
}
21512155
}
@@ -2171,9 +2175,12 @@ macro_rules! double_ended_iterator {
21712175
if self.end == self.ptr {
21722176
None
21732177
} else {
2174-
// See above for why 'ptr.offset' isn't used
2175-
self.end = cast::transmute(self.end as uint -
2176-
sys::nonzero_size_of::<T>());
2178+
self.end = if sys::size_of::<T>() == 0 {
2179+
// See above for why 'ptr.offset' isn't used
2180+
cast::transmute(self.end as uint - 1)
2181+
} else {
2182+
self.end.offset(-1)
2183+
};
21772184
Some(cast::transmute(self.end))
21782185
}
21792186
}
@@ -3566,3 +3573,39 @@ mod tests {
35663573
assert!(cnt == 3);
35673574
}
35683575
}
3576+
3577+
#[cfg(test)]
3578+
mod bench {
3579+
use extra::test::BenchHarness;
3580+
use vec;
3581+
use option::*;
3582+
3583+
#[bench]
3584+
fn iterator(bh: &mut BenchHarness) {
3585+
// peculiar numbers to stop LLVM from optimising the summation
3586+
// out.
3587+
let v = vec::from_fn(100, |i| i ^ (i << 1) ^ (i >> 1));
3588+
3589+
do bh.iter {
3590+
let mut sum = 0;
3591+
foreach x in v.iter() {
3592+
sum += *x;
3593+
}
3594+
// sum == 11806, to stop dead code elimination.
3595+
if sum == 0 {fail!()}
3596+
}
3597+
}
3598+
3599+
#[bench]
3600+
fn mut_iterator(bh: &mut BenchHarness) {
3601+
let mut v = vec::from_elem(100, 0);
3602+
3603+
do bh.iter {
3604+
let mut i = 0;
3605+
foreach x in v.mut_iter() {
3606+
*x = i;
3607+
i += 1;
3608+
}
3609+
}
3610+
}
3611+
}

src/test/run-fail/assert-macro-explicit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:task failed at 'assertion failed: false'
11+
// error-pattern:failed at 'assertion failed: false'
1212

1313
fn main() {
1414
assert!(false);

src/test/run-fail/assert-macro-fmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:task failed at 'test-assert-fmt 42 rust'
11+
// error-pattern:failed at 'test-assert-fmt 42 rust'
1212

1313
fn main() {
1414
assert!(false, "test-assert-fmt %d %s", 42, "rust");

src/test/run-fail/assert-macro-owned.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:task failed at 'test-assert-owned'
11+
// error-pattern:failed at 'test-assert-owned'
1212

1313
fn main() {
1414
assert!(false, ~"test-assert-owned");

src/test/run-fail/assert-macro-static.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:task failed at 'test-assert-static'
11+
// error-pattern:failed at 'test-assert-static'
1212

1313
fn main() {
1414
assert!(false, "test-assert-static");

src/test/run-fail/fail-macro-explicit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:task failed at 'explicit failure'
11+
// error-pattern:failed at 'explicit failure'
1212

1313
fn main() {
1414
fail!();

src/test/run-fail/fail-macro-fmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:task failed at 'test-fail-fmt 42 rust'
11+
// error-pattern:failed at 'test-fail-fmt 42 rust'
1212

1313
fn main() {
1414
fail!("test-fail-fmt %d %s", 42, "rust");

src/test/run-fail/fail-macro-owned.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:task failed at 'test-fail-owned'
11+
// error-pattern:failed at 'test-fail-owned'
1212

1313
fn main() {
1414
fail!("test-fail-owned");

src/test/run-fail/fail-macro-static.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:task failed at 'test-fail-static'
11+
// error-pattern:failed at 'test-fail-static'
1212

1313
fn main() {
1414
fail!("test-fail-static");

0 commit comments

Comments
 (0)