1
Fork 0

libstd: Fix Win32 and other bustage.

This commit is contained in:
Patrick Walton 2013-11-22 14:15:32 -08:00
parent 749ee53c6d
commit 151b7ed52d
10 changed files with 41 additions and 39 deletions

View file

@ -30,14 +30,14 @@ This macro declares an inner module called `my_error` with one static variable,
parameters are used for, an example usage of this condition would be: parameters are used for, an example usage of this condition would be:
```rust ```rust
do my_error::cond.trap(|raised_int| { my_error::cond.trap(|raised_int| {
// the condition `my_error` was raised on, and the value it raised is stored // the condition `my_error` was raised on, and the value it raised is stored
// in `raised_int`. This closure must return a `~str` type (as specified in // in `raised_int`. This closure must return a `~str` type (as specified in
// the declaration of the condition // the declaration of the condition
if raised_int == 3 { ~"three" } else { ~"oh well" } if raised_int == 3 { ~"three" } else { ~"oh well" }
}).inside { }).inside(|| {
// The condition handler above is installed for the duration of this block. // The condition handler above is installed for the duration of this block.
// That handler will override any previous handler, but the previous handler // That handler will override any previous handler, but the previous handler
@ -50,7 +50,7 @@ do my_error::cond.trap(|raised_int| {
println(my_error::cond.raise(3)); // prints "three" println(my_error::cond.raise(3)); // prints "three"
println(my_error::cond.raise(4)); // prints "oh well" println(my_error::cond.raise(4)); // prints "oh well"
} })
``` ```
Condition handling is useful in cases where propagating errors is either to Condition handling is useful in cases where propagating errors is either to
@ -176,9 +176,9 @@ impl<'self, T, U> Trap<'self, T, U> {
/// ```rust /// ```rust
/// condition! { my_error: int -> int; } /// condition! { my_error: int -> int; }
/// ///
/// let result = do my_error::cond.trap(|error| error + 3).inside { /// let result = my_error::cond.trap(|error| error + 3).inside(|| {
/// my_error::cond.raise(4) /// my_error::cond.raise(4)
/// }; /// });
/// assert_eq!(result, 7); /// assert_eq!(result, 7);
/// ``` /// ```
pub fn inside<V>(&self, inner: 'self || -> V) -> V { pub fn inside<V>(&self, inner: 'self || -> V) -> V {

View file

@ -61,9 +61,9 @@ mod tests {
fn test_clone() { fn test_clone() {
let x = Gc::new(RefCell::new(5)); let x = Gc::new(RefCell::new(5));
let y = x.clone(); let y = x.clone();
do x.borrow().with_mut |inner| { x.borrow().with_mut(|inner| {
*inner = 20; *inner = 20;
} });
assert_eq!(y.borrow().with(|x| *x), 20); assert_eq!(y.borrow().with(|x| *x), 20);
} }
@ -71,9 +71,9 @@ mod tests {
fn test_deep_clone() { fn test_deep_clone() {
let x = Gc::new(RefCell::new(5)); let x = Gc::new(RefCell::new(5));
let y = x.deep_clone(); let y = x.deep_clone();
do x.borrow().with_mut |inner| { x.borrow().with_mut(|inner| {
*inner = 20; *inner = 20;
} });
assert_eq!(y.borrow().with(|x| *x), 5); assert_eq!(y.borrow().with(|x| *x), 5);
} }

View file

@ -576,7 +576,9 @@ pub fn unlink(p: &CString) -> IoResult<()> {
#[cfg(windows)] #[cfg(windows)]
fn os_unlink(p: &CString) -> IoResult<()> { fn os_unlink(p: &CString) -> IoResult<()> {
super::mkerr_winbool(unsafe { super::mkerr_winbool(unsafe {
as_utf16_p(p.as_str().unwrap(), |buf| libc::DeleteFileW(buf)); as_utf16_p(p.as_str().unwrap(), |buf| {
libc::DeleteFileW(buf)
})
}) })
} }

View file

@ -499,7 +499,7 @@ fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: |*mut c_void| -> T) -> T {
blk.push(0); blk.push(0);
blk.as_imm_buf(|p, _len| unsafe { cb(cast::transmute(p)) }); blk.as_imm_buf(|p, _len| unsafe { cb(cast::transmute(p)) })
} }
_ => cb(ptr::mut_null()) _ => cb(ptr::mut_null())
} }

View file

@ -104,7 +104,7 @@ pub trait Unsigned: Num {}
/// use num::Times; /// use num::Times;
/// let ten = 10 as uint; /// let ten = 10 as uint;
/// let mut accum = 0; /// let mut accum = 0;
/// do ten.times { accum += 1; } /// ten.times(|| { accum += 1; })
/// ``` /// ```
/// ///
pub trait Times { pub trait Times {

View file

@ -77,13 +77,13 @@ impl num::Times for uint {
#[inline] #[inline]
/// ///
/// A convenience form for basic repetition. Given a uint `x`, /// A convenience form for basic repetition. Given a uint `x`,
/// `do x.times { ... }` executes the given block x times. /// `x.times(|| { ... })` executes the given block x times.
/// ///
/// Equivalent to `for uint::range(0, x) |_| { ... }`. /// Equivalent to `for uint::range(0, x) |_| { ... }`.
/// ///
/// Not defined on all integer types to permit unambiguous /// Not defined on all integer types to permit unambiguous
/// use with integer literals of inferred integer-type as /// use with integer literals of inferred integer-type as
/// the self-value (eg. `do 100.times { ... }`). /// the self-value (eg. `100.times(|| { ... })`).
/// ///
fn times(&self, it: ||) { fn times(&self, it: ||) {
let mut i = *self; let mut i = *self;

View file

@ -481,8 +481,8 @@ mod bench {
#[bench] #[bench]
fn alloc_obj_with_dtor(bh: &mut BenchHarness) { fn alloc_obj_with_dtor(bh: &mut BenchHarness) {
do bh.iter { bh.iter(|| {
HasDtor { x : 10 }; HasDtor { x : 10 };
} })
} }
} }

View file

@ -111,9 +111,9 @@ impl Rng for OSRng {
pbBuffer: *mut BYTE); pbBuffer: *mut BYTE);
} }
do v.as_mut_buf |ptr, len| { v.as_mut_buf(|ptr, len| {
unsafe {rust_win32_rand_gen(self.hcryptprov, len as DWORD, ptr)} unsafe {rust_win32_rand_gen(self.hcryptprov, len as DWORD, ptr)}
} })
} }
} }

View file

@ -109,16 +109,16 @@ mod imp {
fn with_lock<T>(f: || -> T) -> T { fn with_lock<T>(f: || -> T) -> T {
static mut lock: Mutex = MUTEX_INIT; static mut lock: Mutex = MUTEX_INIT;
do (|| { (|| {
unsafe { unsafe {
lock.lock(); lock.lock();
f() f()
} }
}).finally { }).finally(|| {
unsafe { unsafe {
lock.unlock(); lock.unlock();
} }
} })
} }
fn get_global_ptr() -> *mut Option<~~[~str]> { fn get_global_ptr() -> *mut Option<~~[~str]> {
@ -127,9 +127,9 @@ mod imp {
// Copied from `os`. // Copied from `os`.
unsafe fn load_argc_and_argv(argc: int, argv: **u8) -> ~[~str] { unsafe fn load_argc_and_argv(argc: int, argv: **u8) -> ~[~str] {
do vec::from_fn(argc as uint) |i| { vec::from_fn(argc as uint, |i| {
str::raw::from_c_str(*(argv as **libc::c_char).offset(i as int)) str::raw::from_c_str(*(argv as **libc::c_char).offset(i as int))
} })
} }
#[cfg(test)] #[cfg(test)]

View file

@ -3894,25 +3894,25 @@ mod bench {
#[bench] #[bench]
fn push(bh: &mut BenchHarness) { fn push(bh: &mut BenchHarness) {
let mut vec: ~[uint] = ~[0u]; let mut vec: ~[uint] = ~[0u];
do bh.iter() { bh.iter(|| {
vec.push(0); vec.push(0);
} })
} }
#[bench] #[bench]
fn starts_with_same_vector(bh: &mut BenchHarness) { fn starts_with_same_vector(bh: &mut BenchHarness) {
let vec: ~[uint] = vec::from_fn(100, |i| i); let vec: ~[uint] = vec::from_fn(100, |i| i);
do bh.iter() { bh.iter(|| {
vec.starts_with(vec); vec.starts_with(vec);
} })
} }
#[bench] #[bench]
fn starts_with_single_element(bh: &mut BenchHarness) { fn starts_with_single_element(bh: &mut BenchHarness) {
let vec: ~[uint] = ~[0u]; let vec: ~[uint] = ~[0u];
do bh.iter() { bh.iter(|| {
vec.starts_with(vec); vec.starts_with(vec);
} })
} }
#[bench] #[bench]
@ -3920,25 +3920,25 @@ mod bench {
let vec: ~[uint] = vec::from_fn(100, |i| i); let vec: ~[uint] = vec::from_fn(100, |i| i);
let mut match_vec: ~[uint] = vec::from_fn(99, |i| i); let mut match_vec: ~[uint] = vec::from_fn(99, |i| i);
match_vec.push(0); match_vec.push(0);
do bh.iter() { bh.iter(|| {
vec.starts_with(match_vec); vec.starts_with(match_vec);
} })
} }
#[bench] #[bench]
fn ends_with_same_vector(bh: &mut BenchHarness) { fn ends_with_same_vector(bh: &mut BenchHarness) {
let vec: ~[uint] = vec::from_fn(100, |i| i); let vec: ~[uint] = vec::from_fn(100, |i| i);
do bh.iter() { bh.iter(|| {
vec.ends_with(vec); vec.ends_with(vec);
} })
} }
#[bench] #[bench]
fn ends_with_single_element(bh: &mut BenchHarness) { fn ends_with_single_element(bh: &mut BenchHarness) {
let vec: ~[uint] = ~[0u]; let vec: ~[uint] = ~[0u];
do bh.iter() { bh.iter(|| {
vec.ends_with(vec); vec.ends_with(vec);
} })
} }
#[bench] #[bench]
@ -3946,16 +3946,16 @@ mod bench {
let vec: ~[uint] = vec::from_fn(100, |i| i); let vec: ~[uint] = vec::from_fn(100, |i| i);
let mut match_vec: ~[uint] = vec::from_fn(100, |i| i); let mut match_vec: ~[uint] = vec::from_fn(100, |i| i);
match_vec[0] = 200; match_vec[0] = 200;
do bh.iter() { bh.iter(|| {
vec.starts_with(match_vec); vec.starts_with(match_vec);
} })
} }
#[bench] #[bench]
fn contains_last_element(bh: &mut BenchHarness) { fn contains_last_element(bh: &mut BenchHarness) {
let vec: ~[uint] = vec::from_fn(100, |i| i); let vec: ~[uint] = vec::from_fn(100, |i| i);
do bh.iter() { bh.iter(|| {
vec.contains(&99u); vec.contains(&99u);
} })
} }
} }