diff options
| author | bors <bors@rust-lang.org> | 2015-01-01 04:01:02 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-01-01 04:01:02 +0000 |
| commit | 47b8479e73e40395f1b1b2d0c6281f28f80301e4 (patch) | |
| tree | a8ae69e94286da9d3b153e39300130271ad1f3f8 /src/libstd | |
| parent | 7d4f4876d65bddf101784230c0347adcb01e5c21 (diff) | |
| parent | 10bbf69488b4863378e4acd9d55bde36b4a20909 (diff) | |
| download | rust-47b8479e73e40395f1b1b2d0c6281f28f80301e4.tar.gz rust-47b8479e73e40395f1b1b2d0c6281f28f80301e4.zip | |
auto merge of #20363 : japaric/rust/moar-uc, r=nmatsakis
The the last argument of the `ItemDecorator::expand` method has changed to `Box<FnMut>`. Syntax extensions will break.
[breaking-change]
---
This PR removes pretty much all the remaining uses of boxed closures from the libraries. There are still boxed closures under the `test` directory, but I think those should be removed or replaced with unboxed closures at the same time we remove boxed closures from the language.
In a few places I had to do some contortions (see the first commit for an example) to work around issue #19596. I have marked those workarounds with FIXMEs. In the future when `&mut F where F: FnMut` implements the `FnMut` trait, we should be able to remove those workarounds. I've take care to avoid placing the workaround functions in the public API.
Since `let f = || {}` always gets type checked as a boxed closure, I have explictly annotated those closures (with e.g. `|&:| {}`) to force the compiler to type check them as unboxed closures.
Instead of removing the type aliases (like `GetCrateDataCb`), I could have replaced them with newtypes. But this seemed like overcomplicating things for little to no gain.
I think we should be able to remove the boxed closures from the languge after this PR lands. (I'm being optimistic here)
r? @alexcrichton or @aturon
cc @nikomatsakis
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/io/net/udp.rs | 2 | ||||
| -rw-r--r-- | src/libstd/io/stdio.rs | 2 | ||||
| -rw-r--r-- | src/libstd/num/strconv.rs | 4 | ||||
| -rw-r--r-- | src/libstd/rt/task.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/common/thread_info.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/unix/process.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/windows/os.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/windows/process.rs | 2 |
8 files changed, 12 insertions, 10 deletions
diff --git a/src/libstd/io/net/udp.rs b/src/libstd/io/net/udp.rs index 1431067d4c6..73bcdad34c3 100644 --- a/src/libstd/io/net/udp.rs +++ b/src/libstd/io/net/udp.rs @@ -344,7 +344,7 @@ mod test { let (tx2, rx2) = channel(); spawn(move|| { - let send_as = |ip, val: &[u8]| { + let send_as = |&: ip, val: &[u8]| { match UdpSocket::bind(ip) { Ok(client) => { let client = box client; diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 43d2e078035..b7d069eb19e 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -334,7 +334,7 @@ pub fn set_stderr(stderr: Box<Writer + Send>) -> Option<Box<Writer + Send>> { // // io1 aliases io2 // }) // }) -fn with_task_stdout(f: |&mut Writer| -> IoResult<()>) { +fn with_task_stdout<F>(f: F) where F: FnOnce(&mut Writer) -> IoResult<()> { let mut my_stdout = LOCAL_STDOUT.with(|slot| { slot.borrow_mut().take() }).unwrap_or_else(|| { diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index b1f4e5acb93..25af3bf2d53 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -321,10 +321,10 @@ pub fn float_to_str_bytes_common<T: Float>( // cut off the one extra digit, and depending on its value // round the remaining ones. if limit_digits && dig == digit_count { - let ascii2value = |chr: u8| { + let ascii2value = |&: chr: u8| { (chr as char).to_digit(radix).unwrap() }; - let value2ascii = |val: uint| { + let value2ascii = |&: val: uint| { char::from_digit(val, radix).unwrap() as u8 }; diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index 773322e4f57..41e91d1b6ef 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -174,7 +174,7 @@ impl Task { /// /// It is invalid to call this function with a thread that has been previously /// destroyed via a failed call to `run`. - pub fn run(mut self: Box<Task>, f: ||) -> Box<Task> { + pub fn run<F>(mut self: Box<Task>, f: F) -> Box<Task> where F: FnOnce() { assert!(!self.is_destroyed(), "cannot re-use a destroyed thread"); // First, make sure that no one else is in TLS. This does not allow diff --git a/src/libstd/sys/common/thread_info.rs b/src/libstd/sys/common/thread_info.rs index dc21feb17a8..8c76eb1504d 100644 --- a/src/libstd/sys/common/thread_info.rs +++ b/src/libstd/sys/common/thread_info.rs @@ -26,13 +26,13 @@ struct ThreadInfo { thread_local! { static THREAD_INFO: RefCell<Option<ThreadInfo>> = RefCell::new(None) } impl ThreadInfo { - fn with<R>(f: |&mut ThreadInfo| -> R) -> R { + fn with<R, F>(f: F) -> R where F: FnOnce(&mut ThreadInfo) -> R { if THREAD_INFO.destroyed() { panic!("Use of std::thread::Thread::current() is not possible after \ the thread's local data has been destroyed"); } - THREAD_INFO.with(|c| { + THREAD_INFO.with(move |c| { if c.borrow().is_none() { *c.borrow_mut() = Some(ThreadInfo { stack_bounds: (0, 0), diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index 835f4279d9b..615e3a21bd0 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -195,7 +195,7 @@ impl Process { // up /dev/null into that file descriptor. Otherwise, the first file // descriptor opened up in the child would be numbered as one of the // stdio file descriptors, which is likely to wreak havoc. - let setup = |src: Option<P>, dst: c_int| { + let setup = |&: src: Option<P>, dst: c_int| { let src = match src { None => { let flags = if dst == libc::STDIN_FILENO { diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index e7194df7ac3..0f26e36a80f 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -124,7 +124,9 @@ pub unsafe fn pipe() -> IoResult<(FileDesc, FileDesc)> { } } -pub fn fill_utf16_buf_and_decode(f: |*mut u16, DWORD| -> DWORD) -> Option<String> { +pub fn fill_utf16_buf_and_decode<F>(mut f: F) -> Option<String> where + F: FnMut(*mut u16, DWORD) -> DWORD, +{ unsafe { let mut n = TMPBUF_SZ as DWORD; let mut res = None; diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs index 0c2c76077dd..b03c62395d1 100644 --- a/src/libstd/sys/windows/process.rs +++ b/src/libstd/sys/windows/process.rs @@ -162,7 +162,7 @@ impl Process { // Similarly to unix, we don't actually leave holes for the stdio file // descriptors, but rather open up /dev/null equivalents. These // equivalents are drawn from libuv's windows process spawning. - let set_fd = |fd: &Option<P>, slot: &mut HANDLE, + let set_fd = |&: fd: &Option<P>, slot: &mut HANDLE, is_stdin: bool| { match *fd { None => { |
