diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-08-11 17:27:05 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-08-12 14:55:17 -0700 |
| commit | 8d90d3f36871a00023cc1f313f91e351c287ca15 (patch) | |
| tree | 2d9b616a2468117aa3afe1f6b1f910ff3116776b /src/libstd | |
| parent | d07d465cf60033e35eba16b9e431471d54c712f4 (diff) | |
| download | rust-8d90d3f36871a00023cc1f313f91e351c287ca15.tar.gz rust-8d90d3f36871a00023cc1f313f91e351c287ca15.zip | |
Remove all unstable deprecated functionality
This commit removes all unstable and deprecated functions in the standard library. A release was recently cut (1.3) which makes this a good time for some spring cleaning of the deprecated functions.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/ascii.rs | 99 | ||||
| -rw-r--r-- | src/libstd/collections/hash/map.rs | 16 | ||||
| -rw-r--r-- | src/libstd/collections/mod.rs | 8 | ||||
| -rw-r--r-- | src/libstd/env.rs | 33 | ||||
| -rw-r--r-- | src/libstd/ffi/c_str.rs | 12 | ||||
| -rw-r--r-- | src/libstd/fs.rs | 55 | ||||
| -rw-r--r-- | src/libstd/io/buffered.rs | 149 | ||||
| -rw-r--r-- | src/libstd/io/mod.rs | 2 | ||||
| -rw-r--r-- | src/libstd/lib.rs | 2 | ||||
| -rw-r--r-- | src/libstd/net/tcp.rs | 20 | ||||
| -rw-r--r-- | src/libstd/net/udp.rs | 52 | ||||
| -rw-r--r-- | src/libstd/num/f32.rs | 2 | ||||
| -rw-r--r-- | src/libstd/num/f64.rs | 2 | ||||
| -rw-r--r-- | src/libstd/rt/mod.rs | 5 | ||||
| -rw-r--r-- | src/libstd/sync/future.rs | 231 | ||||
| -rw-r--r-- | src/libstd/sync/mod.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/common/net.rs | 95 | ||||
| -rw-r--r-- | src/libstd/sys/common/remutex.rs | 22 | ||||
| -rw-r--r-- | src/libstd/sys/unix/fs.rs | 7 | ||||
| -rw-r--r-- | src/libstd/sys/unix/mod.rs | 8 | ||||
| -rw-r--r-- | src/libstd/sys/windows/fs.rs | 13 | ||||
| -rw-r--r-- | src/libstd/sys/windows/mod.rs | 10 | ||||
| -rw-r--r-- | src/libstd/sys/windows/net.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/windows/os.rs | 9 | ||||
| -rw-r--r-- | src/libstd/thread/mod.rs | 110 | ||||
| -rw-r--r-- | src/libstd/thunk.rs | 21 | ||||
| -rw-r--r-- | src/libstd/time/duration.rs | 17 |
27 files changed, 46 insertions, 959 deletions
diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index ded572e82ff..82b5f60d65c 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -17,24 +17,6 @@ use prelude::v1::*; use mem; use ops::Range; -/// Extension methods for ASCII-subset only operations on owned strings -#[unstable(feature = "owned_ascii_ext", - reason = "would prefer to do this in a more general way")] -#[deprecated(since = "1.3.0", - reason = "hasn't yet proved essential to be in the standard library")] -#[allow(deprecated)] -pub trait OwnedAsciiExt { - /// Converts the string to ASCII upper case: - /// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z', - /// but non-ASCII letters are unchanged. - fn into_ascii_uppercase(self) -> Self; - - /// Converts the string to ASCII lower case: - /// ASCII letters 'A' to 'Z' are mapped to 'a' to 'z', - /// but non-ASCII letters are unchanged. - fn into_ascii_lowercase(self) -> Self; -} - /// Extension methods for ASCII-subset only operations on string slices. #[stable(feature = "rust1", since = "1.0.0")] pub trait AsciiExt { @@ -169,15 +151,19 @@ impl AsciiExt for str { } #[inline] - #[allow(deprecated)] fn to_ascii_uppercase(&self) -> String { - self.to_string().into_ascii_uppercase() + let mut bytes = self.as_bytes().to_vec(); + bytes.make_ascii_uppercase(); + // make_ascii_uppercase() preserves the UTF-8 invariant. + unsafe { String::from_utf8_unchecked(bytes) } } #[inline] - #[allow(deprecated)] fn to_ascii_lowercase(&self) -> String { - self.to_string().into_ascii_lowercase() + let mut bytes = self.as_bytes().to_vec(); + bytes.make_ascii_lowercase(); + // make_ascii_uppercase() preserves the UTF-8 invariant. + unsafe { String::from_utf8_unchecked(bytes) } } #[inline] @@ -196,21 +182,6 @@ impl AsciiExt for str { } } -#[allow(deprecated)] -impl OwnedAsciiExt for String { - #[inline] - fn into_ascii_uppercase(self) -> String { - // Vec<u8>::into_ascii_uppercase() preserves the UTF-8 invariant. - unsafe { String::from_utf8_unchecked(self.into_bytes().into_ascii_uppercase()) } - } - - #[inline] - fn into_ascii_lowercase(self) -> String { - // Vec<u8>::into_ascii_lowercase() preserves the UTF-8 invariant. - unsafe { String::from_utf8_unchecked(self.into_bytes().into_ascii_lowercase()) } - } -} - #[stable(feature = "rust1", since = "1.0.0")] impl AsciiExt for [u8] { type Owned = Vec<u8>; @@ -220,15 +191,17 @@ impl AsciiExt for [u8] { } #[inline] - #[allow(deprecated)] fn to_ascii_uppercase(&self) -> Vec<u8> { - self.to_vec().into_ascii_uppercase() + let mut me = self.to_vec(); + me.make_ascii_uppercase(); + return me } #[inline] - #[allow(deprecated)] fn to_ascii_lowercase(&self) -> Vec<u8> { - self.to_vec().into_ascii_lowercase() + let mut me = self.to_vec(); + me.make_ascii_lowercase(); + return me } #[inline] @@ -252,21 +225,6 @@ impl AsciiExt for [u8] { } } -#[allow(deprecated)] -impl OwnedAsciiExt for Vec<u8> { - #[inline] - fn into_ascii_uppercase(mut self) -> Vec<u8> { - self.make_ascii_uppercase(); - self - } - - #[inline] - fn into_ascii_lowercase(mut self) -> Vec<u8> { - self.make_ascii_lowercase(); - self - } -} - #[stable(feature = "rust1", since = "1.0.0")] impl AsciiExt for u8 { type Owned = u8; @@ -523,35 +481,6 @@ mod tests { } #[test] - fn test_into_ascii_uppercase() { - assert_eq!(("url()URL()uRl()ürl".to_string()).into_ascii_uppercase(), - "URL()URL()URL()üRL".to_string()); - assert_eq!(("hıKß".to_string()).into_ascii_uppercase(), "HıKß"); - - for i in 0..501 { - let upper = if 'a' as u32 <= i && i <= 'z' as u32 { i + 'A' as u32 - 'a' as u32 } - else { i }; - assert_eq!((from_u32(i).unwrap()).to_string().into_ascii_uppercase(), - (from_u32(upper).unwrap()).to_string()); - } - } - - #[test] - fn test_into_ascii_lowercase() { - assert_eq!(("url()URL()uRl()Ürl".to_string()).into_ascii_lowercase(), - "url()url()url()Ürl"); - // Dotted capital I, Kelvin sign, Sharp S. - assert_eq!(("HİKß".to_string()).into_ascii_lowercase(), "hİKß"); - - for i in 0..501 { - let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 } - else { i }; - assert_eq!((from_u32(i).unwrap()).to_string().into_ascii_lowercase(), - (from_u32(lower).unwrap()).to_string()); - } - } - - #[test] fn test_make_ascii_lower_case() { macro_rules! test { ($from: expr, $to: expr) => { diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 66f894fc31f..654b2eac4ba 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -24,7 +24,7 @@ use mem::{self, replace}; use ops::{Deref, FnMut, FnOnce, Index}; use option::Option::{self, Some, None}; use rand::{self, Rng}; -use result::Result::{self, Ok, Err}; +use result::Result; use super::table::{ self, @@ -1482,18 +1482,6 @@ impl<'a, K, V> ExactSizeIterator for Drain<'a, K, V> { } impl<'a, K, V> Entry<'a, K, V> { - #[unstable(feature = "entry", - reason = "will soon be replaced by or_insert")] - #[deprecated(since = "1.0", - reason = "replaced with more ergonomic `or_insert` and `or_insert_with`")] - /// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant - pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, K, V>> { - match self { - Occupied(entry) => Ok(entry.into_mut()), - Vacant(entry) => Err(entry), - } - } - #[stable(feature = "rust1", since = "1.0.0")] /// Ensures a value is in the entry by inserting the default if empty, and returns /// a mutable reference to the value in the entry. @@ -1610,7 +1598,7 @@ pub struct RandomState { impl RandomState { /// Constructs a new `RandomState` that is initialized with random keys. #[inline] - #[allow(deprecated)] + #[allow(deprecated)] // rand pub fn new() -> RandomState { let mut r = rand::thread_rng(); RandomState { k0: r.gen(), k1: r.gen() } diff --git a/src/libstd/collections/mod.rs b/src/libstd/collections/mod.rs index c91ebc91ef3..d59d08497d2 100644 --- a/src/libstd/collections/mod.rs +++ b/src/libstd/collections/mod.rs @@ -385,11 +385,11 @@ #![stable(feature = "rust1", since = "1.0.0")] pub use core_collections::Bound; -pub use core_collections::{BinaryHeap, BitVec, BitSet, BTreeMap, BTreeSet}; -pub use core_collections::{LinkedList, VecDeque, VecMap}; +pub use core_collections::{BinaryHeap, BTreeMap, BTreeSet}; +pub use core_collections::{LinkedList, VecDeque}; -pub use core_collections::{binary_heap, bit_vec, bit_set, btree_map, btree_set}; -pub use core_collections::{linked_list, vec_deque, vec_map}; +pub use core_collections::{binary_heap, btree_map, btree_set}; +pub use core_collections::{linked_list, vec_deque}; pub use self::hash_map::HashMap; pub use self::hash_set::HashSet; diff --git a/src/libstd/env.rs b/src/libstd/env.rs index d1a49da461e..d80a222d8d2 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -23,7 +23,6 @@ use ffi::{OsStr, OsString}; use fmt; use io; use path::{Path, PathBuf}; -use sync::atomic::{AtomicIsize, Ordering}; use sync::StaticMutex; use sys::os as os_imp; @@ -474,30 +473,6 @@ pub fn current_exe() -> io::Result<PathBuf> { os_imp::current_exe() } -static EXIT_STATUS: AtomicIsize = AtomicIsize::new(0); - -/// Sets the process exit code -/// -/// Sets the exit code returned by the process if all supervised threads -/// terminate successfully (without panicking). If the current root thread panics -/// and is supervised by the scheduler then any user-specified exit status is -/// ignored and the process exits with the default panic status. -/// -/// Note that this is not synchronized against modifications of other threads. -#[unstable(feature = "exit_status", reason = "managing the exit status may change")] -#[deprecated(since = "1.2.0", reason = "use process::exit instead")] -pub fn set_exit_status(code: i32) { - EXIT_STATUS.store(code as isize, Ordering::SeqCst) -} - -/// Fetches the process's current exit code. This defaults to 0 and can change -/// by calling `set_exit_status`. -#[unstable(feature = "exit_status", reason = "managing the exit status may change")] -#[deprecated(since = "1.2.0", reason = "use process::exit instead")] -pub fn get_exit_status() -> i32 { - EXIT_STATUS.load(Ordering::SeqCst) as i32 -} - /// An iterator over the arguments of a process, yielding a `String` value /// for each argument. /// @@ -588,14 +563,6 @@ impl ExactSizeIterator for ArgsOs { fn len(&self) -> usize { self.inner.len() } } -/// Returns the page size of the current architecture in bytes. -#[unstable(feature = "page_size", reason = "naming and/or location may change")] -#[deprecated(since = "1.3.0", - reason = "hasn't seen enough usage to justify inclusion")] -pub fn page_size() -> usize { - os_imp::page_size() -} - /// Constants associated with the current target #[stable(feature = "env", since = "1.0.0")] pub mod consts { diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 3e503074ab4..f99d3c14ed8 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -468,6 +468,7 @@ mod tests { use super::*; use libc; use borrow::Cow::{Borrowed, Owned}; + use hash::{SipHasher, Hash, Hasher}; #[test] fn c_to_rust() { @@ -545,15 +546,16 @@ mod tests { #[test] fn equal_hash() { - use hash; - let data = b"123\xE2\xFA\xA6\0"; let ptr = data.as_ptr() as *const libc::c_char; let cstr: &'static CStr = unsafe { CStr::from_ptr(ptr) }; - let cstr_hash = hash::hash::<_, hash::SipHasher>(&cstr); - let cstring_hash = - hash::hash::<_, hash::SipHasher>(&CString::new(&data[..data.len() - 1]).unwrap()); + let mut s = SipHasher::new_with_keys(0, 0); + cstr.hash(&mut s); + let cstr_hash = s.finish(); + let mut s = SipHasher::new_with_keys(0, 0); + CString::new(&data[..data.len() - 1]).unwrap().hash(&mut s); + let cstring_hash = s.finish(); assert_eq!(cstr_hash, cstring_hash); } diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index ba32ffc49d4..53caa0e78e2 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -1216,23 +1216,6 @@ impl PathExt for Path { } } -/// Changes the timestamps for a file's last modification and access time. -/// -/// The file at the path specified will have its last access time set to -/// `accessed` and its modification time set to `modified`. The times specified -/// should be in milliseconds. -#[unstable(feature = "fs_time", - reason = "the argument type of u64 is not quite appropriate for \ - this function and may change if the standard library \ - gains a type to represent a moment in time")] -#[deprecated(since = "1.3.0", - reason = "will never be stabilized as-is and its replacement will \ - likely have a totally new API")] -pub fn set_file_times<P: AsRef<Path>>(path: P, accessed: u64, - modified: u64) -> io::Result<()> { - fs_imp::utimes(path.as_ref(), accessed, modified) -} - /// Changes the permissions found on a file or a directory. /// /// # Examples @@ -2050,44 +2033,6 @@ mod tests { } #[test] - fn utime() { - let tmpdir = tmpdir(); - let path = tmpdir.join("a"); - check!(File::create(&path)); - // These numbers have to be bigger than the time in the day to account - // for timezones Windows in particular will fail in certain timezones - // with small enough values - check!(fs::set_file_times(&path, 100_000, 200_000)); - - check(&check!(path.metadata())); - - #[cfg(unix)] - fn check(metadata: &fs::Metadata) { - use os::unix::prelude::*; - assert_eq!(metadata.atime(), 100); - assert_eq!(metadata.atime_nsec(), 0); - assert_eq!(metadata.mtime(), 200); - assert_eq!(metadata.mtime_nsec(), 0); - } - #[cfg(windows)] - fn check(metadata: &fs::Metadata) { - use os::windows::prelude::*; - assert_eq!(metadata.last_access_time(), 100_000 * 10_000); - assert_eq!(metadata.last_write_time(), 200_000 * 10_000); - } - } - - #[test] - fn utime_noexist() { - let tmpdir = tmpdir(); - - match fs::set_file_times(&tmpdir.join("a"), 100, 200) { - Ok(..) => panic!(), - Err(..) => {} - } - } - - #[test] fn binary_file() { let mut bytes = [0; 1024]; StdRng::new().unwrap().fill_bytes(&mut bytes); diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index eca6ffc8ce3..90bcbe7fe86 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -785,129 +785,11 @@ impl<W: Read + Write> Read for InternalBufWriter<W> { } } -/// Wraps a Stream and buffers input and output to and from it. -/// -/// It can be excessively inefficient to work directly with a `Read+Write`. For -/// example, every call to `read` or `write` on `TcpStream` results in a system -/// call. A `BufStream` keeps in memory buffers of data, making large, -/// infrequent calls to `read` and `write` on the underlying `Read+Write`. -/// -/// The output buffer will be written out when this stream is dropped. -#[unstable(feature = "buf_stream", - reason = "unsure about semantics of buffering two directions, \ - leading to issues like #17136")] -#[deprecated(since = "1.2.0", - reason = "use the crates.io `bufstream` crate instead")] -pub struct BufStream<S: Write> { - inner: BufReader<InternalBufWriter<S>> -} - -#[unstable(feature = "buf_stream", - reason = "unsure about semantics of buffering two directions, \ - leading to issues like #17136")] -#[deprecated(since = "1.2.0", - reason = "use the crates.io `bufstream` crate instead")] -#[allow(deprecated)] -impl<S: Read + Write> BufStream<S> { - /// Creates a new buffered stream with explicitly listed capacities for the - /// reader/writer buffer. - pub fn with_capacities(reader_cap: usize, writer_cap: usize, inner: S) - -> BufStream<S> { - let writer = BufWriter::with_capacity(writer_cap, inner); - let internal_writer = InternalBufWriter(writer); - let reader = BufReader::with_capacity(reader_cap, internal_writer); - BufStream { inner: reader } - } - - /// Creates a new buffered stream with the default reader/writer buffer - /// capacities. - pub fn new(inner: S) -> BufStream<S> { - BufStream::with_capacities(DEFAULT_BUF_SIZE, DEFAULT_BUF_SIZE, inner) - } - - /// Gets a reference to the underlying stream. - pub fn get_ref(&self) -> &S { - let InternalBufWriter(ref w) = self.inner.inner; - w.get_ref() - } - - /// Gets a mutable reference to the underlying stream. - /// - /// It is inadvisable to read directly from or write directly to the - /// underlying stream. - pub fn get_mut(&mut self) -> &mut S { - let InternalBufWriter(ref mut w) = self.inner.inner; - w.get_mut() - } - - /// Unwraps this `BufStream`, returning the underlying stream. - /// - /// The internal write buffer is written out before returning the stream. - /// Any leftover data in the read buffer is lost. - pub fn into_inner(self) -> Result<S, IntoInnerError<BufStream<S>>> { - let BufReader { inner: InternalBufWriter(w), buf, pos, cap } = self.inner; - w.into_inner().map_err(|IntoInnerError(w, e)| { - IntoInnerError(BufStream { - inner: BufReader { inner: InternalBufWriter(w), buf: buf, pos: pos, cap: cap }, - }, e) - }) - } -} - -#[unstable(feature = "buf_stream", - reason = "unsure about semantics of buffering two directions, \ - leading to issues like #17136")] -#[allow(deprecated)] -impl<S: Read + Write> BufRead for BufStream<S> { - fn fill_buf(&mut self) -> io::Result<&[u8]> { self.inner.fill_buf() } - fn consume(&mut self, amt: usize) { self.inner.consume(amt) } -} - -#[unstable(feature = "buf_stream", - reason = "unsure about semantics of buffering two directions, \ - leading to issues like #17136")] -#[allow(deprecated)] -impl<S: Read + Write> Read for BufStream<S> { - fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { - self.inner.read(buf) - } -} - -#[unstable(feature = "buf_stream", - reason = "unsure about semantics of buffering two directions, \ - leading to issues like #17136")] -#[allow(deprecated)] -impl<S: Read + Write> Write for BufStream<S> { - fn write(&mut self, buf: &[u8]) -> io::Result<usize> { - self.inner.inner.get_mut().write(buf) - } - fn flush(&mut self) -> io::Result<()> { - self.inner.inner.get_mut().flush() - } -} - -#[unstable(feature = "buf_stream", - reason = "unsure about semantics of buffering two directions, \ - leading to issues like #17136")] -#[allow(deprecated)] -impl<S: Write> fmt::Debug for BufStream<S> where S: fmt::Debug { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - let reader = &self.inner; - let writer = &self.inner.inner.0; - fmt.debug_struct("BufStream") - .field("stream", &writer.inner) - .field("write_buffer", &format_args!("{}/{}", writer.buf.len(), writer.buf.capacity())) - .field("read_buffer", - &format_args!("{}/{}", reader.cap - reader.pos, reader.buf.len())) - .finish() - } -} - #[cfg(test)] mod tests { use prelude::v1::*; use io::prelude::*; - use io::{self, BufReader, BufWriter, BufStream, Cursor, LineWriter, SeekFrom}; + use io::{self, BufReader, BufWriter, Cursor, LineWriter, SeekFrom}; use test; /// A dummy reader intended at testing short-reads propagation. @@ -1078,27 +960,6 @@ mod tests { assert_eq!(&w.into_inner().unwrap().into_inner()[..], &[0, 1, 8, 9, 4, 5, 6, 7]); } - // This is just here to make sure that we don't infinite loop in the - // newtype struct autoderef weirdness - #[test] - fn test_buffered_stream() { - struct S; - - impl Write for S { - fn write(&mut self, b: &[u8]) -> io::Result<usize> { Ok(b.len()) } - fn flush(&mut self) -> io::Result<()> { Ok(()) } - } - - impl Read for S { - fn read(&mut self, _: &mut [u8]) -> io::Result<usize> { Ok(0) } - } - - let mut stream = BufStream::new(S); - assert_eq!(stream.read(&mut [0; 10]).unwrap(), 0); - stream.write(&[0; 10]).unwrap(); - stream.flush().unwrap(); - } - #[test] fn test_read_until() { let inner: &[u8] = &[0, 1, 2, 1, 0]; @@ -1230,12 +1091,4 @@ mod tests { BufWriter::new(io::sink()) }); } - - #[bench] - fn bench_buffered_stream(b: &mut test::Bencher) { - let mut buf = Cursor::new(Vec::new()); - b.iter(|| { - BufStream::new(&mut buf); - }); - } } diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 3d746aa450a..eda6e85ff7f 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -255,7 +255,7 @@ use string::String; use str; use vec::Vec; -pub use self::buffered::{BufReader, BufWriter, BufStream, LineWriter}; +pub use self::buffered::{BufReader, BufWriter, LineWriter}; pub use self::buffered::IntoInnerError; pub use self::cursor::Cursor; pub use self::error::{Result, Error, ErrorKind}; diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 6041c2d3d47..77c634e8090 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -360,8 +360,6 @@ mod uint_macros; pub mod ascii; -pub mod thunk; - /* Common traits */ pub mod num; diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index 84e05083b57..be224c15ff0 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -128,26 +128,6 @@ impl TcpStream { self.0.duplicate().map(TcpStream) } - /// Sets the nodelay flag on this connection to the boolean specified. - #[deprecated(since = "1.3.0", - reason = "available through the `net2` crate on crates.io")] - #[unstable(feature = "tcp_extras", reason = "available externally")] - pub fn set_nodelay(&self, nodelay: bool) -> io::Result<()> { - self.0.set_nodelay(nodelay) - } - - /// Sets the keepalive timeout to the timeout specified. - /// - /// If the value specified is `None`, then the keepalive flag is cleared on - /// this connection. Otherwise, the keepalive timeout will be set to the - /// specified time, in seconds. - #[unstable(feature = "tcp_extras", reason = "available externally")] - #[deprecated(since = "1.3.0", - reason = "available through the `net2` crate on crates.io")] - pub fn set_keepalive(&self, seconds: Option<u32>) -> io::Result<()> { - self.0.set_keepalive(seconds) - } - /// Sets the read timeout to the timeout specified. /// /// If the value specified is `None`, then `read` calls will block diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs index 1e1ffc19900..20ce344be4f 100644 --- a/src/libstd/net/udp.rs +++ b/src/libstd/net/udp.rs @@ -13,7 +13,7 @@ use fmt; use io::{self, Error, ErrorKind}; -use net::{ToSocketAddrs, SocketAddr, IpAddr}; +use net::{ToSocketAddrs, SocketAddr}; use sys_common::net as net_imp; use sys_common::{AsInner, FromInner, IntoInner}; use time::Duration; @@ -95,56 +95,6 @@ impl UdpSocket { self.0.duplicate().map(UdpSocket) } - /// Sets the broadcast flag on or off. - #[deprecated(since = "1.3.0", - reason = "available through the `net2` crate on crates.io")] - #[unstable(feature = "udp_extras", reason = "available externally")] - pub fn set_broadcast(&self, on: bool) -> io::Result<()> { - self.0.set_broadcast(on) - } - - /// Sets the multicast loop flag to the specified value. - /// - /// This lets multicast packets loop back to local sockets (if enabled) - #[deprecated(since = "1.3.0", - reason = "available through the `net2` crate on crates.io")] - #[unstable(feature = "udp_extras", reason = "available externally")] - pub fn set_multicast_loop(&self, on: bool) -> io::Result<()> { - self.0.set_multicast_loop(on) - } - - /// Joins a multicast IP address (becomes a member of it). - #[deprecated(since = "1.3.0", - reason = "available through the `net2` crate on crates.io")] - #[unstable(feature = "udp_extras", reason = "available externally")] - pub fn join_multicast(&self, multi: &IpAddr) -> io::Result<()> { - self.0.join_multicast(multi) - } - - /// Leaves a multicast IP address (drops membership from it). - #[deprecated(since = "1.3.0", - reason = "available through the `net2` crate on crates.io")] - #[unstable(feature = "udp_extras", reason = "available externally")] - pub fn leave_multicast(&self, multi: &IpAddr) -> io::Result<()> { - self.0.leave_multicast(multi) - } - - /// Sets the multicast TTL. - #[deprecated(since = "1.3.0", - reason = "available through the `net2` crate on crates.io")] - #[unstable(feature = "udp_extras", reason = "available externally")] - pub fn set_multicast_time_to_live(&self, ttl: i32) -> io::Result<()> { - self.0.multicast_time_to_live(ttl) - } - - /// Sets this socket's TTL. - #[deprecated(since = "1.3.0", - reason = "available through the `net2` crate on crates.io")] - #[unstable(feature = "udp_extras", reason = "available externally")] - pub fn set_time_to_live(&self, ttl: i32) -> io::Result<()> { - self.0.time_to_live(ttl) - } - /// Sets the read timeout to the timeout specified. /// /// If the value specified is `None`, then `read` calls will block diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index 6a8026a807e..2bc837a231c 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -1751,7 +1751,6 @@ mod tests { use super::consts; let pi: f32 = consts::PI; - let two_pi: f32 = consts::PI_2; let frac_pi_2: f32 = consts::FRAC_PI_2; let frac_pi_3: f32 = consts::FRAC_PI_3; let frac_pi_4: f32 = consts::FRAC_PI_4; @@ -1768,7 +1767,6 @@ mod tests { let ln_2: f32 = consts::LN_2; let ln_10: f32 = consts::LN_10; - assert_approx_eq!(two_pi, 2f32 * pi); assert_approx_eq!(frac_pi_2, pi / 2f32); assert_approx_eq!(frac_pi_3, pi / 3f32); assert_approx_eq!(frac_pi_4, pi / 4f32); diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index e757ff90fdd..c6e2d7380df 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -1651,7 +1651,6 @@ mod tests { fn test_real_consts() { use super::consts; let pi: f64 = consts::PI; - let two_pi: f64 = consts::PI_2; let frac_pi_2: f64 = consts::FRAC_PI_2; let frac_pi_3: f64 = consts::FRAC_PI_3; let frac_pi_4: f64 = consts::FRAC_PI_4; @@ -1668,7 +1667,6 @@ mod tests { let ln_2: f64 = consts::LN_2; let ln_10: f64 = consts::LN_10; - assert_approx_eq!(two_pi, 2.0 * pi); assert_approx_eq!(frac_pi_2, pi / 2f64); assert_approx_eq!(frac_pi_3, pi / 3f64); assert_approx_eq!(frac_pi_4, pi / 4f64); diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index 24a4575aa54..2ace6e4cf8d 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -59,7 +59,6 @@ fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize { use prelude::v1::*; use mem; - use env; use rt; use sys_common::thread_info::{self, NewThread}; use thread::Thread; @@ -105,9 +104,7 @@ fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize { if failed { rt::DEFAULT_ERROR_CODE } else { - #[allow(deprecated)] - fn exit_status() -> isize { env::get_exit_status() as isize } - exit_status() + 0 } } diff --git a/src/libstd/sync/future.rs b/src/libstd/sync/future.rs deleted file mode 100644 index 506b8260278..00000000000 --- a/src/libstd/sync/future.rs +++ /dev/null @@ -1,231 +0,0 @@ -// Copyright 2012-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. - -//! A type representing values that may be computed concurrently and operations -//! for working with them. -//! -//! # Examples -//! -//! ``` -//! #![feature(future)] -//! -//! use std::sync::Future; -//! -//! // a fake, for now -//! fn fib(n: u32) -> u32 { 42 }; -//! -//! let mut delayed_fib = Future::spawn(move || fib(5000)); -//! -//! // do stuff... -//! -//! println!("fib(5000) = {}", delayed_fib.get()) -//! ``` - -#![allow(missing_docs)] -#![unstable(feature = "future", - reason = "futures as-is have yet to be deeply reevaluated with recent \ - core changes to Rust's synchronization story, and will likely \ - become stable in the future but are unstable until that time")] -#![deprecated(since = "1.2.0", - reason = "implementation does not match the quality of the \ - standard library and this will likely be prototyped \ - outside in crates.io first")] -#![allow(deprecated)] - -use core::mem::replace; - -use boxed::Box; -use self::FutureState::*; -use sync::mpsc::{Receiver, channel}; -use thunk::Thunk; -use thread; - -/// A type encapsulating the result of a computation which may not be complete -pub struct Future<A> { - state: FutureState<A>, -} - -enum FutureState<A> { - Pending(Thunk<'static,(),A>), - Evaluating, - Forced(A) -} - -/// Methods on the `future` type -impl<A:Clone> Future<A> { - pub fn get(&mut self) -> A { - //! Get the value of the future. - (*(self.get_ref())).clone() - } -} - -impl<A> Future<A> { - /// Gets the value from this future, forcing evaluation. - pub fn into_inner(mut self) -> A { - self.get_ref(); - let state = replace(&mut self.state, Evaluating); - match state { - Forced(v) => v, - _ => panic!( "Logic error." ), - } - } - - pub fn get_ref<'a>(&'a mut self) -> &'a A { - /*! - * Executes the future's closure and then returns a reference - * to the result. The reference lasts as long as - * the future. - */ - match self.state { - Forced(ref v) => return v, - Evaluating => panic!("Recursive forcing of future!"), - Pending(_) => { - match replace(&mut self.state, Evaluating) { - Forced(_) | Evaluating => panic!("Logic error."), - Pending(f) => { - self.state = Forced(f()); - self.get_ref() - } - } - } - } - } - - pub fn from_value(val: A) -> Future<A> { - /*! - * Create a future from a value. - * - * The value is immediately available and calling `get` later will - * not block. - */ - - Future {state: Forced(val)} - } - - pub fn from_fn<F>(f: F) -> Future<A> - where F : FnOnce() -> A, F : Send + 'static - { - /*! - * Create a future from a function. - * - * The first time that the value is requested it will be retrieved by - * calling the function. Note that this function is a local - * function. It is not spawned into another task. - */ - - Future {state: Pending(Box::new(f))} - } -} - -impl<A:Send+'static> Future<A> { - pub fn from_receiver(rx: Receiver<A>) -> Future<A> { - /*! - * Create a future from a port - * - * The first time that the value is requested the task will block - * waiting for the result to be received on the port. - */ - - Future::from_fn(move || { - rx.recv().unwrap() - }) - } - - pub fn spawn<F>(blk: F) -> Future<A> - where F : FnOnce() -> A, F : Send + 'static - { - /*! - * Create a future from a unique closure. - * - * The closure will be run in a new task and its result used as the - * value of the future. - */ - - let (tx, rx) = channel(); - - thread::spawn(move || { - // Don't panic if the other end has hung up - let _ = tx.send(blk()); - }); - - Future::from_receiver(rx) - } -} - -#[cfg(test)] -mod tests { - use prelude::v1::*; - use sync::mpsc::channel; - use sync::Future; - use thread; - - #[test] - fn test_from_value() { - let mut f = Future::from_value("snail".to_string()); - assert_eq!(f.get(), "snail"); - } - - #[test] - fn test_from_receiver() { - let (tx, rx) = channel(); - tx.send("whale".to_string()).unwrap(); - let mut f = Future::from_receiver(rx); - assert_eq!(f.get(), "whale"); - } - - #[test] - fn test_from_fn() { - let mut f = Future::from_fn(move|| "brail".to_string()); - assert_eq!(f.get(), "brail"); - } - - #[test] - fn test_interface_get() { - let mut f = Future::from_value("fail".to_string()); - assert_eq!(f.get(), "fail"); - } - - #[test] - fn test_interface_unwrap() { - let f = Future::from_value("fail".to_string()); - assert_eq!(f.into_inner(), "fail"); - } - - #[test] - fn test_get_ref_method() { - let mut f = Future::from_value(22); - assert_eq!(*f.get_ref(), 22); - } - - #[test] - fn test_spawn() { - let mut f = Future::spawn(move|| "bale".to_string()); - assert_eq!(f.get(), "bale"); - } - - #[test] - #[should_panic] - fn test_future_panic() { - let mut f = Future::spawn(move|| panic!()); - let _x: String = f.get(); - } - - #[test] - fn test_sendable_future() { - let expected = "schlorf"; - let (tx, rx) = channel(); - let f = Future::spawn(move|| { expected }); - let _t = thread::spawn(move|| { - let mut f = f; - tx.send(f.get()).unwrap(); - }); - assert_eq!(rx.recv().unwrap(), expected); - } -} diff --git a/src/libstd/sync/mod.rs b/src/libstd/sync/mod.rs index ab8d4587cfd..28fab5a2c9d 100644 --- a/src/libstd/sync/mod.rs +++ b/src/libstd/sync/mod.rs @@ -30,14 +30,10 @@ pub use self::rwlock::{RwLockReadGuard, RwLockWriteGuard}; pub use self::rwlock::{RwLock, StaticRwLock, RW_LOCK_INIT}; pub use self::semaphore::{Semaphore, SemaphoreGuard}; -#[allow(deprecated)] -pub use self::future::Future; - pub mod mpsc; mod barrier; mod condvar; -mod future; mod mutex; mod once; mod rwlock; diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs index 6dd222b8f6e..68d5f49dffa 100644 --- a/src/libstd/sys/common/net.rs +++ b/src/libstd/sys/common/net.rs @@ -186,42 +186,6 @@ impl TcpStream { pub fn into_socket(self) -> Socket { self.inner } - pub fn set_nodelay(&self, nodelay: bool) -> io::Result<()> { - setsockopt(&self.inner, libc::IPPROTO_TCP, libc::TCP_NODELAY, - nodelay as c_int) - } - - pub fn set_keepalive(&self, seconds: Option<u32>) -> io::Result<()> { - let ret = setsockopt(&self.inner, libc::SOL_SOCKET, libc::SO_KEEPALIVE, - seconds.is_some() as c_int); - match seconds { - Some(n) => ret.and_then(|()| self.set_tcp_keepalive(n)), - None => ret, - } - } - - #[cfg(any(target_os = "macos", target_os = "ios"))] - fn set_tcp_keepalive(&self, seconds: u32) -> io::Result<()> { - setsockopt(&self.inner, libc::IPPROTO_TCP, libc::TCP_KEEPALIVE, - seconds as c_int) - } - #[cfg(any(target_os = "freebsd", - target_os = "dragonfly", - target_os = "linux"))] - fn set_tcp_keepalive(&self, seconds: u32) -> io::Result<()> { - setsockopt(&self.inner, libc::IPPROTO_TCP, libc::TCP_KEEPIDLE, - seconds as c_int) - } - - #[cfg(not(any(target_os = "macos", - target_os = "ios", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "linux")))] - fn set_tcp_keepalive(&self, _seconds: u32) -> io::Result<()> { - Ok(()) - } - pub fn set_read_timeout(&self, dur: Option<Duration>) -> io::Result<()> { self.inner.set_timeout(dur, libc::SO_RCVTIMEO) } @@ -431,65 +395,6 @@ impl UdpSocket { Ok(ret as usize) } - pub fn set_broadcast(&self, on: bool) -> io::Result<()> { - setsockopt(&self.inner, libc::SOL_SOCKET, libc::SO_BROADCAST, - on as c_int) - } - - pub fn set_multicast_loop(&self, on: bool) -> io::Result<()> { - setsockopt(&self.inner, libc::IPPROTO_IP, - libc::IP_MULTICAST_LOOP, on as c_int) - } - - pub fn join_multicast(&self, multi: &IpAddr) -> io::Result<()> { - match *multi { - IpAddr::V4(..) => { - self.set_membership(multi, libc::IP_ADD_MEMBERSHIP) - } - IpAddr::V6(..) => { - self.set_membership(multi, libc::IPV6_ADD_MEMBERSHIP) - } - } - } - pub fn leave_multicast(&self, multi: &IpAddr) -> io::Result<()> { - match *multi { - IpAddr::V4(..) => { - self.set_membership(multi, libc::IP_DROP_MEMBERSHIP) - } - IpAddr::V6(..) => { - self.set_membership(multi, libc::IPV6_DROP_MEMBERSHIP) - } - } - } - fn set_membership(&self, addr: &IpAddr, opt: c_int) -> io::Result<()> { - match *addr { - IpAddr::V4(ref addr) => { - let mreq = libc::ip_mreq { - imr_multiaddr: *addr.as_inner(), - // interface == INADDR_ANY - imr_interface: libc::in_addr { s_addr: 0x0 }, - }; - setsockopt(&self.inner, libc::IPPROTO_IP, opt, mreq) - } - IpAddr::V6(ref addr) => { - let mreq = libc::ip6_mreq { - ipv6mr_multiaddr: *addr.as_inner(), - ipv6mr_interface: 0, - }; - setsockopt(&self.inner, libc::IPPROTO_IPV6, opt, mreq) - } - } - } - - pub fn multicast_time_to_live(&self, ttl: i32) -> io::Result<()> { - setsockopt(&self.inner, libc::IPPROTO_IP, libc::IP_MULTICAST_TTL, - ttl as c_int) - } - - pub fn time_to_live(&self, ttl: i32) -> io::Result<()> { - setsockopt(&self.inner, libc::IPPROTO_IP, libc::IP_TTL, ttl as c_int) - } - pub fn duplicate(&self) -> io::Result<UdpSocket> { self.inner.duplicate().map(|s| UdpSocket { inner: s }) } diff --git a/src/libstd/sys/common/remutex.rs b/src/libstd/sys/common/remutex.rs index 8f416464173..20475c5463b 100644 --- a/src/libstd/sys/common/remutex.rs +++ b/src/libstd/sys/common/remutex.rs @@ -180,10 +180,11 @@ mod tests { #[test] fn is_mutex() { - let m = ReentrantMutex::new(RefCell::new(0)); + let m = Arc::new(ReentrantMutex::new(RefCell::new(0))); + let m2 = m.clone(); let lock = m.lock().unwrap(); - let handle = thread::scoped(|| { - let lock = m.lock().unwrap(); + let child = thread::spawn(move || { + let lock = m2.lock().unwrap(); assert_eq!(*lock.borrow(), 4950); }); for i in 0..100 { @@ -191,20 +192,19 @@ mod tests { *lock.borrow_mut() += i; } drop(lock); - drop(handle); + child.join().unwrap(); } #[test] fn trylock_works() { - let m = ReentrantMutex::new(()); + let m = Arc::new(ReentrantMutex::new(())); + let m2 = m.clone(); let lock = m.try_lock().unwrap(); let lock2 = m.try_lock().unwrap(); - { - thread::scoped(|| { - let lock = m.try_lock(); - assert!(lock.is_err()); - }); - } + thread::spawn(move || { + let lock = m2.try_lock(); + assert!(lock.is_err()); + }).join().unwrap(); let lock3 = m.try_lock().unwrap(); } diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 922a213f9c2..751b8e48263 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -509,13 +509,6 @@ pub fn lstat(p: &Path) -> io::Result<FileAttr> { Ok(FileAttr { stat: stat }) } -pub fn utimes(p: &Path, atime: u64, mtime: u64) -> io::Result<()> { - let p = try!(cstr(p)); - let buf = [super::ms_to_timeval(atime), super::ms_to_timeval(mtime)]; - try!(cvt(unsafe { c::utimes(p.as_ptr(), buf.as_ptr()) })); - Ok(()) -} - pub fn canonicalize(p: &Path) -> io::Result<PathBuf> { let path = try!(CString::new(p.as_os_str().as_bytes())); let mut buf = vec![0u8; 16 * 1024]; diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs index 2efca0257f3..bbed42cc31d 100644 --- a/src/libstd/sys/unix/mod.rs +++ b/src/libstd/sys/unix/mod.rs @@ -82,7 +82,6 @@ pub fn cvt<T: One + PartialEq + Neg<Output=T>>(t: T) -> io::Result<T> { } } -#[allow(deprecated)] pub fn cvt_r<T, F>(mut f: F) -> io::Result<T> where T: One + PartialEq + Neg<Output=T>, F: FnMut() -> T { @@ -93,10 +92,3 @@ pub fn cvt_r<T, F>(mut f: F) -> io::Result<T> } } } - -pub fn ms_to_timeval(ms: u64) -> libc::timeval { - libc::timeval { - tv_sec: (ms / 1000) as libc::time_t, - tv_usec: ((ms % 1000) * 1000) as libc::suseconds_t, - } -} diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs index b8c3f1e7b35..d413d536cc8 100644 --- a/src/libstd/sys/windows/fs.rs +++ b/src/libstd/sys/windows/fs.rs @@ -571,19 +571,6 @@ pub fn set_perm(p: &Path, perm: FilePermissions) -> io::Result<()> { } } -pub fn utimes(p: &Path, atime: u64, mtime: u64) -> io::Result<()> { - let atime = super::ms_to_filetime(atime); - let mtime = super::ms_to_filetime(mtime); - - let mut o = OpenOptions::new(); - o.write(true); - let f = try!(File::open(p, &o)); - try!(cvt(unsafe { - c::SetFileTime(f.handle.raw(), 0 as *const _, &atime, &mtime) - })); - Ok(()) -} - fn get_path(f: &File) -> io::Result<PathBuf> { super::fill_utf16_buf(|buf, sz| unsafe { c::GetFinalPathNameByHandleW(f.handle.raw(), buf, sz, diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs index b38945d8916..732e2e65864 100644 --- a/src/libstd/sys/windows/mod.rs +++ b/src/libstd/sys/windows/mod.rs @@ -174,13 +174,3 @@ fn dur2timeout(dur: Duration) -> libc::DWORD { } }).unwrap_or(libc::INFINITE) } - -fn ms_to_filetime(ms: u64) -> libc::FILETIME { - // A FILETIME is a count of 100 nanosecond intervals, so we multiply by - // 10000 b/c there are 10000 intervals in 1 ms - let ms = ms * 10000; - libc::FILETIME { - dwLowDateTime: ms as u32, - dwHighDateTime: (ms >> 32) as u32, - } -} diff --git a/src/libstd/sys/windows/net.rs b/src/libstd/sys/windows/net.rs index 02c5bc1f0ab..57e84b0c46c 100644 --- a/src/libstd/sys/windows/net.rs +++ b/src/libstd/sys/windows/net.rs @@ -67,7 +67,6 @@ pub fn cvt_gai(err: c_int) -> io::Result<()> { } /// Provides the functionality of `cvt` for a closure. -#[allow(deprecated)] pub fn cvt_r<T, F>(mut f: F) -> io::Result<T> where F: FnMut() -> T, T: One + Neg<Output=T> + PartialEq { diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index 694d873d0d2..3e640ceaddd 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -21,7 +21,6 @@ use fmt; use io; use libc::types::os::arch::extra::LPWCH; use libc::{self, c_int, c_void}; -use mem; use ops::Range; use os::windows::ffi::EncodeWide; use path::{self, PathBuf}; @@ -334,14 +333,6 @@ pub fn args() -> Args { } } -pub fn page_size() -> usize { - unsafe { - let mut info = mem::zeroed(); - libc::GetSystemInfo(&mut info); - return info.dwPageSize as usize; - } -} - pub fn temp_dir() -> PathBuf { super::fill_utf16_buf(|buf, sz| unsafe { c::GetTempPathW(sz, buf) diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 89a51391624..3435a1fccdf 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -253,36 +253,6 @@ impl Builder { } } - /// Spawns a new child thread that must be joined within a given - /// scope, and returns a `JoinGuard`. - /// - /// The join guard can be used to explicitly join the child thread (via - /// `join`), returning `Result<T>`, or it will implicitly join the child - /// upon being dropped. Because the child thread may refer to data on the - /// current thread's stack (hence the "scoped" name), it cannot be detached; - /// it *must* be joined before the relevant stack frame is popped. See the - /// documentation on `thread::scoped` for additional details. - /// - /// # Errors - /// - /// Unlike the `scoped` free function, this method yields an - /// `io::Result` to capture any failure to create the thread at - /// the OS level. - #[unstable(feature = "scoped", - reason = "memory unsafe if destructor is avoided, see #24292")] - #[deprecated(since = "1.2.0", - reason = "this unsafe API is unlikely to ever be stabilized \ - in this form")] - pub fn scoped<'a, T, F>(self, f: F) -> io::Result<JoinGuard<'a, T>> where - T: Send + 'a, F: FnOnce() -> T, F: Send + 'a - { - unsafe { - self.spawn_inner(Box::new(f)).map(|inner| { - JoinGuard { inner: inner, _marker: PhantomData } - }) - } - } - // NB: this function is unsafe as the lifetime parameter of the code to run // in the new thread is not tied into the return value, and the return // value must not outlast that lifetime. @@ -346,50 +316,6 @@ pub fn spawn<F, T>(f: F) -> JoinHandle<T> where Builder::new().spawn(f).unwrap() } -/// Spawns a new *scoped* thread, returning a `JoinGuard` for it. -/// -/// The `spawn` method does not allow the child and parent threads to -/// share any stack data, since that is not safe in general. However, -/// `scoped` makes it possible to share the parent's stack by forcing -/// a join before any relevant stack frames are popped: -/// -/// ```rust -/// #![feature(scoped)] -/// -/// use std::thread; -/// -/// let guard = thread::scoped(move || { -/// // some work here -/// }); -/// -/// // do some other work in the meantime -/// let output = guard.join(); -/// ``` -/// -/// The `scoped` function doesn't return a `Thread` directly; instead, it -/// returns a *join guard*. The join guard can be used to explicitly join -/// the child thread (via `join`), returning `Result<T>`, or it will -/// implicitly join the child upon being dropped. Because the child thread -/// may refer to data on the current thread's stack (hence the "scoped" -/// name), it cannot be detached; it *must* be joined before the relevant -/// stack frame is popped. -/// -/// # Panics -/// -/// Panics if the OS fails to create a thread; use `Builder::scoped` -/// to recover from such errors. -#[unstable(feature = "scoped", - reason = "memory unsafe if destructor is avoided, see #24292")] -#[deprecated(since = "1.2.0", - reason = "this unsafe API is unlikely to ever be stabilized \ - in this form")] -#[allow(deprecated)] -pub fn scoped<'a, T, F>(f: F) -> JoinGuard<'a, T> where - T: Send + 'a, F: FnOnce() -> T, F: Send + 'a -{ - Builder::new().scoped(f).unwrap() -} - /// Gets a handle to the thread that invokes it. #[stable(feature = "rust1", since = "1.0.0")] pub fn current() -> Thread { @@ -769,7 +695,6 @@ mod tests { use result; use super::{Builder}; use thread; - use thunk::Thunk; use time::Duration; use u32; @@ -785,9 +710,9 @@ mod tests { #[test] fn test_named_thread() { - Builder::new().name("ada lovelace".to_string()).scoped(move|| { + Builder::new().name("ada lovelace".to_string()).spawn(move|| { assert!(thread::current().name().unwrap() == "ada lovelace".to_string()); - }).unwrap().join(); + }).unwrap().join().unwrap(); } #[test] @@ -800,13 +725,6 @@ mod tests { } #[test] - fn test_join_success() { - assert!(thread::scoped(move|| -> String { - "Success!".to_string() - }).join() == "Success!"); - } - - #[test] fn test_join_panic() { match thread::spawn(move|| { panic!() @@ -817,26 +735,6 @@ mod tests { } #[test] - fn test_scoped_success() { - let res = thread::scoped(move|| -> String { - "Success!".to_string() - }).join(); - assert!(res == "Success!"); - } - - #[test] - #[should_panic] - fn test_scoped_panic() { - thread::scoped(|| panic!()).join(); - } - - #[test] - #[should_panic] - fn test_scoped_implicit_panic() { - let _ = thread::scoped(|| panic!()); - } - - #[test] fn test_spawn_sched() { use clone::Clone; @@ -870,7 +768,7 @@ mod tests { rx.recv().unwrap(); } - fn avoid_copying_the_body<F>(spawnfn: F) where F: FnOnce(Thunk<'static>) { + fn avoid_copying_the_body<F>(spawnfn: F) where F: FnOnce(Box<Fn() + Send>) { let (tx, rx) = channel(); let x: Box<_> = box 1; @@ -917,7 +815,7 @@ mod tests { // (well, it would if the constant were 8000+ - I lowered it to be more // valgrind-friendly. try this at home, instead..!) const GENERATIONS: u32 = 16; - fn child_no(x: u32) -> Thunk<'static> { + fn child_no(x: u32) -> Box<Fn() + Send> { return Box::new(move|| { if x < GENERATIONS { thread::spawn(move|| child_no(x+1)()); diff --git a/src/libstd/thunk.rs b/src/libstd/thunk.rs deleted file mode 100644 index f1dc91f135f..00000000000 --- a/src/libstd/thunk.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2014 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. - -// Because this module is temporary... -#![allow(missing_docs)] -#![unstable(feature = "thunk")] -#![deprecated(since = "1.2.0", reason = "use FnBox instead")] - -use alloc::boxed::{Box, FnBox}; -use core::marker::Send; - -pub type Thunk<'a, A=(), R=()> = - Box<FnBox<A,Output=R> + Send + 'a>; - diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index ba9c3157b02..d16fa83c2af 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -92,14 +92,6 @@ impl Duration { #[stable(feature = "duration", since = "1.3.0")] pub fn as_secs(&self) -> u64 { self.secs } - #[deprecated(reason = "renamed to `as_secs`", since = "1.3.0")] - #[unstable(feature = "duration_deprecated")] - /// Returns the number of whole seconds represented by this duration. - /// - /// The extra precision represented by this duration is ignored (e.g. extra - /// nanoseconds are not represented in the returned value). - pub fn secs(&self) -> u64 { self.as_secs() } - /// Returns the nanosecond precision represented by this duration. /// /// This method does **not** return the length of the duration when @@ -107,15 +99,6 @@ impl Duration { /// fractional portion of a second (e.g. it is less than one billion). #[stable(feature = "duration", since = "1.3.0")] pub fn subsec_nanos(&self) -> u32 { self.nanos } - - #[deprecated(reason = "renamed to `subsec_nanos`", since = "1.3.0")] - #[unstable(feature = "duration_deprecated")] - /// Returns the nanosecond precision represented by this duration. - /// - /// This method does **not** return the length of the duration when - /// represented by nanoseconds. The returned number always represents a - /// fractional portion of a second (e.g. it is less than one billion). - pub fn extra_nanos(&self) -> u32 { self.subsec_nanos() } } impl Add for Duration { |
