From 9c906da7ade767925aca1da06f139152835b661b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 14 Mar 2015 23:40:12 -0700 Subject: std: Fix create_dir_all for empty paths Recent changes in path semantics meant that if none of the components in a relative path existed as a part of a call to `create_dir_all` then the call would fail as `create_dir("")` would be attempted and would fail with an OS error. --- src/libstd/fs/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libstd') diff --git a/src/libstd/fs/mod.rs b/src/libstd/fs/mod.rs index ac1f5993aa1..813283ed164 100644 --- a/src/libstd/fs/mod.rs +++ b/src/libstd/fs/mod.rs @@ -570,7 +570,7 @@ pub fn create_dir(path: &P) -> io::Result<()> { #[stable(feature = "rust1", since = "1.0.0")] pub fn create_dir_all(path: &P) -> io::Result<()> { let path = path.as_path(); - if path.is_dir() { return Ok(()) } + if path == Path::new("") || path.is_dir() { return Ok(()) } if let Some(p) = path.parent() { try!(create_dir_all(p)) } create_dir(path) } -- cgit 1.4.1-3-g733a5 From 6f693e94868b12fcffa9d5b53b2ca02778ff8daa Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Wed, 18 Mar 2015 23:36:19 -0700 Subject: Stabilize Entry types This commit marks as `#[stable]` the `Entry` types for the maps provided by `std`. The main reason these had been left unstable previously was uncertainty about an eventual trait design, but several plausible designs have been proposed that all work fine with the current type definitions. --- src/libcollections/btree/map.rs | 16 ++++++++-------- src/libcollections/vec_map.rs | 16 +++++++++------- src/libstd/collections/hash/map.rs | 16 ++++++++-------- 3 files changed, 25 insertions(+), 23 deletions(-) (limited to 'src/libstd') diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index c7e1e3c9176..75c0ec486cf 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -124,26 +124,26 @@ pub struct RangeMut<'a, K: 'a, V: 'a> { } /// A view into a single entry in a map, which may either be vacant or occupied. -#[unstable(feature = "collections", - reason = "precise API still under development")] +#[stable(feature = "rust1", since = "1.0.0")] pub enum Entry<'a, K:'a, V:'a> { /// A vacant Entry + #[stable(feature = "rust1", since = "1.0.0")] Vacant(VacantEntry<'a, K, V>), + /// An occupied Entry + #[stable(feature = "rust1", since = "1.0.0")] Occupied(OccupiedEntry<'a, K, V>), } /// A vacant Entry. -#[unstable(feature = "collections", - reason = "precise API still under development")] +#[stable(feature = "rust1", since = "1.0.0")] pub struct VacantEntry<'a, K:'a, V:'a> { key: K, stack: stack::SearchStack<'a, K, V, node::handle::Edge, node::handle::Leaf>, } /// An occupied Entry. -#[unstable(feature = "collections", - reason = "precise API still under development")] +#[stable(feature = "rust1", since = "1.0.0")] pub struct OccupiedEntry<'a, K:'a, V:'a> { stack: stack::SearchStack<'a, K, V, node::handle::KV, node::handle::LeafOrInternal>, } @@ -1124,9 +1124,9 @@ impl<'a, K, V> DoubleEndedIterator for RangeMut<'a, K, V> { } impl<'a, K: Ord, V> Entry<'a, K, V> { - #[unstable(feature = "collections", - reason = "matches collection reform v2 specification, waiting for dust to settle")] /// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant + #[unstable(feature = "std_misc", + reason = "will soon be replaced by or_insert")] pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, K, V>> { match self { Occupied(entry) => Ok(entry.into_mut()), diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index 6e67d876327..056be4acaeb 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -67,26 +67,28 @@ pub struct VecMap { } /// A view into a single entry in a map, which may either be vacant or occupied. -#[unstable(feature = "collections", - reason = "precise API still under development")] + +#[stable(feature = "rust1", since = "1.0.0")] pub enum Entry<'a, V:'a> { /// A vacant Entry + #[stable(feature = "rust1", since = "1.0.0")] Vacant(VacantEntry<'a, V>), + /// An occupied Entry + #[stable(feature = "rust1", since = "1.0.0")] Occupied(OccupiedEntry<'a, V>), } /// A vacant Entry. -#[unstable(feature = "collections", - reason = "precise API still under development")] + +#[stable(feature = "rust1", since = "1.0.0")] pub struct VacantEntry<'a, V:'a> { map: &'a mut VecMap, index: usize, } /// An occupied Entry. -#[unstable(feature = "collections", - reason = "precise API still under development")] +#[stable(feature = "rust1", since = "1.0.0")] pub struct OccupiedEntry<'a, V:'a> { map: &'a mut VecMap, index: usize, @@ -651,7 +653,7 @@ impl VecMap { impl<'a, V> Entry<'a, V> { #[unstable(feature = "collections", - reason = "matches collection reform v2 specification, waiting for dust to settle")] + reason = "will soon be replaced by or_insert")] /// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, V>> { match self { diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 60b1738d2c9..43e60d4dc4f 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1335,15 +1335,13 @@ pub struct Drain<'a, K: 'a, V: 'a> { } /// A view into a single occupied location in a HashMap. -#[unstable(feature = "std_misc", - reason = "precise API still being fleshed out")] +#[stable(feature = "rust1", since = "1.0.0")] pub struct OccupiedEntry<'a, K: 'a, V: 'a> { elem: FullBucket>, } /// A view into a single empty location in a HashMap. -#[unstable(feature = "std_misc", - reason = "precise API still being fleshed out")] +#[stable(feature = "rust1", since = "1.0.0")] pub struct VacantEntry<'a, K: 'a, V: 'a> { hash: SafeHash, key: K, @@ -1351,12 +1349,14 @@ pub struct VacantEntry<'a, K: 'a, V: 'a> { } /// A view into a single location in a map, which may be vacant or occupied. -#[unstable(feature = "std_misc", - reason = "precise API still being fleshed out")] +#[stable(feature = "rust1", since = "1.0.0")] pub enum Entry<'a, K: 'a, V: 'a> { /// An occupied Entry. + #[stable(feature = "rust1", since = "1.0.0")] Occupied(OccupiedEntry<'a, K, V>), + /// A vacant Entry. + #[stable(feature = "rust1", since = "1.0.0")] Vacant(VacantEntry<'a, K, V>), } @@ -1477,10 +1477,10 @@ impl<'a, K, V> ExactSizeIterator for Drain<'a, K, V> { #[inline] fn len(&self) -> usize { self.inner.len() } } -#[unstable(feature = "std_misc", - reason = "matches collection reform v2 specification, waiting for dust to settle")] impl<'a, K, V> Entry<'a, K, V> { /// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant. + #[unstable(feature = "std_misc", + reason = "will soon be replaced by or_insert")] pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, K, V>> { match self { Occupied(entry) => Ok(entry.into_mut()), -- cgit 1.4.1-3-g733a5 From e24fe5b8cfabb65a763a67403e7b0c91aaa848a9 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 18 Mar 2015 19:51:10 -0700 Subject: std: Remove deprecated ptr functions The method with which backwards compatibility was retained ended up leading to documentation that rustdoc didn't handle well and largely ended up confusing. --- src/libcollectionstest/slice.rs | 2 +- src/libcore/intrinsics.rs | 34 ++++++++++++++++++++++----- src/libcore/ptr.rs | 20 +++------------- src/libcoretest/ptr.rs | 14 +++++------ src/librustc_trans/trans/intrinsic.rs | 6 ++--- src/librustc_typeck/check/mod.rs | 4 ++-- src/libstd/old_io/extensions.rs | 4 ++-- src/test/bench/shootout-reverse-complement.rs | 6 ++--- 8 files changed, 49 insertions(+), 41 deletions(-) (limited to 'src/libstd') diff --git a/src/libcollectionstest/slice.rs b/src/libcollectionstest/slice.rs index 0c3c82eea78..4168fe88a4b 100644 --- a/src/libcollectionstest/slice.rs +++ b/src/libcollectionstest/slice.rs @@ -1428,7 +1428,7 @@ mod bench { let mut v = Vec::::with_capacity(1024); unsafe { let vp = v.as_mut_ptr(); - ptr::set_memory(vp, 0, 1024); + ptr::write_bytes(vp, 0, 1024); v.set_len(1024); } v diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 1462d07652d..297c3192ecb 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -44,6 +44,10 @@ use marker::Sized; +#[cfg(stage0)] pub use self::copy_memory as copy; +#[cfg(stage0)] pub use self::set_memory as write_bytes; +#[cfg(stage0)] pub use self::copy_nonoverlapping_memory as copy_nonoverlapping; + extern "rust-intrinsic" { // NB: These intrinsics take unsafe pointers because they mutate aliased @@ -246,7 +250,7 @@ extern "rust-intrinsic" { /// Copies `count * size_of` bytes from `src` to `dst`. The source /// and destination may *not* overlap. /// - /// `copy_nonoverlapping_memory` is semantically equivalent to C's `memcpy`. + /// `copy_nonoverlapping` is semantically equivalent to C's `memcpy`. /// /// # Safety /// @@ -271,9 +275,9 @@ extern "rust-intrinsic" { /// let mut t: T = mem::uninitialized(); /// /// // Perform the swap, `&mut` pointers never alias - /// ptr::copy_nonoverlapping_memory(&mut t, &*x, 1); - /// ptr::copy_nonoverlapping_memory(x, &*y, 1); - /// ptr::copy_nonoverlapping_memory(y, &t, 1); + /// ptr::copy_nonoverlapping(&mut t, &*x, 1); + /// ptr::copy_nonoverlapping(x, &*y, 1); + /// ptr::copy_nonoverlapping(y, &t, 1); /// /// // y and t now point to the same thing, but we need to completely forget `tmp` /// // because it's no longer relevant. @@ -282,12 +286,18 @@ extern "rust-intrinsic" { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(not(stage0))] + pub fn copy_nonoverlapping(dst: *mut T, src: *const T, count: usize); + + /// dox + #[stable(feature = "rust1", since = "1.0.0")] + #[cfg(stage0)] pub fn copy_nonoverlapping_memory(dst: *mut T, src: *const T, count: usize); /// Copies `count * size_of` bytes from `src` to `dst`. The source /// and destination may overlap. /// - /// `copy_memory` is semantically equivalent to C's `memmove`. + /// `copy` is semantically equivalent to C's `memmove`. /// /// # Safety /// @@ -306,16 +316,28 @@ extern "rust-intrinsic" { /// unsafe fn from_buf_raw(ptr: *const T, elts: uint) -> Vec { /// let mut dst = Vec::with_capacity(elts); /// dst.set_len(elts); - /// ptr::copy_memory(dst.as_mut_ptr(), ptr, elts); + /// ptr::copy(dst.as_mut_ptr(), ptr, elts); /// dst /// } /// ``` /// + #[cfg(not(stage0))] + #[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(dst: *mut T, src: *const T, count: usize); + + /// dox + #[cfg(stage0)] #[stable(feature = "rust1", since = "1.0.0")] pub fn copy_memory(dst: *mut T, src: *const T, count: usize); /// Invokes memset on the specified pointer, setting `count * size_of::()` /// bytes of memory starting at `dst` to `c`. + #[cfg(not(stage0))] + #[stable(feature = "rust1", since = "1.0.0")] + pub fn write_bytes(dst: *mut T, val: u8, count: usize); + + /// dox + #[cfg(stage0)] #[stable(feature = "rust1", since = "1.0.0")] pub fn set_memory(dst: *mut T, val: u8, count: usize); diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 1cbea057e88..0c0cb81a89e 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -105,27 +105,13 @@ use cmp::Ordering::{self, Less, Equal, Greater}; // FIXME #19649: intrinsic docs don't render, so these have no docs :( #[stable(feature = "rust1", since = "1.0.0")] -pub use intrinsics::copy_nonoverlapping_memory as copy_nonoverlapping; +pub use intrinsics::copy_nonoverlapping; #[stable(feature = "rust1", since = "1.0.0")] -pub use intrinsics::copy_memory as copy; +pub use intrinsics::copy; #[stable(feature = "rust1", since = "1.0.0")] -pub use intrinsics::set_memory as write_bytes; - -extern "rust-intrinsic" { - #[unstable(feature = "core")] - #[deprecated(since = "1.0.0", reason = "renamed to `copy_nonoverlapping`")] - pub fn copy_nonoverlapping_memory(dst: *mut T, src: *const T, count: usize); - #[unstable(feature = "core")] - #[deprecated(since = "1.0.0", reason = "renamed to `copy`")] - pub fn copy_memory(dst: *mut T, src: *const T, count: usize); - - #[unstable(feature = "core", - reason = "uncertain about naming and semantics")] - #[deprecated(since = "1.0.0", reason = "renamed to `write_bytes`")] - pub fn set_memory(dst: *mut T, val: u8, count: usize); -} +pub use intrinsics::write_bytes; /// Creates a null raw pointer. /// diff --git a/src/libcoretest/ptr.rs b/src/libcoretest/ptr.rs index 6a25c8be14e..adc15b9fbc2 100644 --- a/src/libcoretest/ptr.rs +++ b/src/libcoretest/ptr.rs @@ -35,18 +35,18 @@ fn test() { let v0 = vec![32000u16, 32001u16, 32002u16]; let mut v1 = vec![0u16, 0u16, 0u16]; - copy_memory(v1.as_mut_ptr().offset(1), - v0.as_ptr().offset(1), 1); + copy(v1.as_mut_ptr().offset(1), + v0.as_ptr().offset(1), 1); assert!((v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16)); - copy_memory(v1.as_mut_ptr(), - v0.as_ptr().offset(2), 1); + copy(v1.as_mut_ptr(), + v0.as_ptr().offset(2), 1); assert!((v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 0u16)); - copy_memory(v1.as_mut_ptr().offset(2), - v0.as_ptr(), 1); + copy(v1.as_mut_ptr().offset(2), + v0.as_ptr(), 1); assert!((v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 32000u16)); @@ -164,7 +164,7 @@ fn test_ptr_subtraction() { fn test_set_memory() { let mut xs = [0u8; 20]; let ptr = xs.as_mut_ptr(); - unsafe { set_memory(ptr, 5u8, xs.len()); } + unsafe { write_bytes(ptr, 5u8, xs.len()); } assert!(xs == [5u8; 20]); } diff --git a/src/librustc_trans/trans/intrinsic.rs b/src/librustc_trans/trans/intrinsic.rs index 69ca9a5e81c..7f4b0b02d53 100644 --- a/src/librustc_trans/trans/intrinsic.rs +++ b/src/librustc_trans/trans/intrinsic.rs @@ -386,7 +386,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, InBoundsGEP(bcx, ptr, &[offset]) } - (_, "copy_nonoverlapping_memory") => { + (_, "copy_nonoverlapping") => { copy_intrinsic(bcx, false, false, @@ -396,7 +396,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, llargs[2], call_debug_location) } - (_, "copy_memory") => { + (_, "copy") => { copy_intrinsic(bcx, true, false, @@ -406,7 +406,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, llargs[2], call_debug_location) } - (_, "set_memory") => { + (_, "write_bytes") => { memset_intrinsic(bcx, false, *substs.types.get(FnSpace, 0), diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 45d4a1edc6b..b9a6a05fda9 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -5365,7 +5365,7 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) { mutbl: ast::MutImmutable })) } - "copy_memory" | "copy_nonoverlapping_memory" | + "copy" | "copy_nonoverlapping" | "volatile_copy_memory" | "volatile_copy_nonoverlapping_memory" => { (1, vec!( @@ -5381,7 +5381,7 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) { ), ty::mk_nil(tcx)) } - "set_memory" | "volatile_set_memory" => { + "write_bytes" | "volatile_set_memory" => { (1, vec!( ty::mk_ptr(tcx, ty::mt { diff --git a/src/libstd/old_io/extensions.rs b/src/libstd/old_io/extensions.rs index 2990c1c265d..5b1b9471b07 100644 --- a/src/libstd/old_io/extensions.rs +++ b/src/libstd/old_io/extensions.rs @@ -159,7 +159,7 @@ pub fn u64_to_be_bytes(n: u64, size: uint, f: F) -> T where /// that many bytes are parsed. For example, if `size` is 4, then a /// 32-bit value is parsed. pub fn u64_from_be_bytes(data: &[u8], start: uint, size: uint) -> u64 { - use ptr::{copy_nonoverlapping_memory}; + use ptr::{copy_nonoverlapping}; assert!(size <= 8); @@ -171,7 +171,7 @@ pub fn u64_from_be_bytes(data: &[u8], start: uint, size: uint) -> u64 { unsafe { let ptr = data.as_ptr().offset(start as int); let out = buf.as_mut_ptr(); - copy_nonoverlapping_memory(out.offset((8 - size) as int), ptr, size); + copy_nonoverlapping(out.offset((8 - size) as int), ptr, size); (*(out as *const u64)).to_be() } } diff --git a/src/test/bench/shootout-reverse-complement.rs b/src/test/bench/shootout-reverse-complement.rs index 93aa5f2571b..0ab552cf047 100644 --- a/src/test/bench/shootout-reverse-complement.rs +++ b/src/test/bench/shootout-reverse-complement.rs @@ -46,7 +46,7 @@ extern crate libc; use std::old_io::stdio::{stdin_raw, stdout_raw}; use std::old_io::*; -use std::ptr::{copy_memory, Unique}; +use std::ptr::{copy, Unique}; use std::thread; struct Tables { @@ -181,8 +181,8 @@ fn reverse_complement(seq: &mut [u8], tables: &Tables) { let mut i = LINE_LEN; while i < len { unsafe { - copy_memory(seq.as_mut_ptr().offset((i - off + 1) as int), - seq.as_ptr().offset((i - off) as int), off); + copy(seq.as_mut_ptr().offset((i - off + 1) as int), + seq.as_ptr().offset((i - off) as int), off); *seq.get_unchecked_mut(i - off) = b'\n'; } i += LINE_LEN + 1; -- cgit 1.4.1-3-g733a5 From 90c8592889187681b9766b7507c090e180f61a78 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Sun, 22 Mar 2015 17:16:26 +0200 Subject: Refine Cursor docstring --- src/libstd/io/cursor.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/io/cursor.rs b/src/libstd/io/cursor.rs index 87e5a2a4488..1ca424f7c61 100644 --- a/src/libstd/io/cursor.rs +++ b/src/libstd/io/cursor.rs @@ -17,17 +17,14 @@ use iter::repeat; use num::Int; use slice; -/// A `Cursor` is a type which wraps another I/O object to provide a `Seek` +/// A `Cursor` is a type which wraps a non-I/O object to provide a `Seek` /// implementation. /// -/// Cursors are currently typically used with memory buffer objects in order to -/// allow `Seek` plus `Read` and `Write` implementations. For example, common -/// cursor types include: +/// Cursors are typically used with memory buffer objects in order to allow +/// `Seek`, `Read`, and `Write` implementations. For example, common cursor types +/// include `Cursor>` and `Cursor<&[u8]>`. /// -/// * `Cursor>` -/// * `Cursor<&[u8]>` -/// -/// Implementations of the I/O traits for `Cursor` are not currently generic +/// Implementations of the I/O traits for `Cursor` are currently not generic /// over `T` itself. Instead, specific implementations are provided for various /// in-memory buffer types like `Vec` and `&[u8]`. #[stable(feature = "rust1", since = "1.0.0")] -- cgit 1.4.1-3-g733a5 From 5321d22afa2593cc4bd0418298ce7c247ff45ffe Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Sun, 22 Mar 2015 15:04:54 -0400 Subject: Remove bad reference to std::io Closes #23540 --- src/libstd/macros.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index f4a7e8b1b98..0b9cb14e04c 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -90,8 +90,7 @@ macro_rules! println { } /// Helper macro for unwrapping `Result` values while returning early with an -/// error if the value of the expression is `Err`. For more information, see -/// `std::io`. +/// error if the value of the expression is `Err`. #[macro_export] #[stable(feature = "rust1", since = "1.0.0")] macro_rules! try { -- cgit 1.4.1-3-g733a5 From 29aca83eb46cdc39dc695852ab30bb0ad06bea8f Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 21 Mar 2015 10:34:15 +0100 Subject: Remove an unsafe function definition in __thread_local_inner. This fixes a build error when using thread_local!() in a deny(unsafe_code) scope in Servo for Android. --- src/libstd/thread_local/mod.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/thread_local/mod.rs b/src/libstd/thread_local/mod.rs index 08780292c88..380ac0c838e 100644 --- a/src/libstd/thread_local/mod.rs +++ b/src/libstd/thread_local/mod.rs @@ -205,15 +205,13 @@ macro_rules! __thread_local_inner { #[cfg(any(not(any(target_os = "macos", target_os = "linux")), target_arch = "aarch64"))] const _INIT: ::std::thread_local::__impl::KeyInner<$t> = { - unsafe extern fn __destroy(ptr: *mut u8) { - ::std::thread_local::__impl::destroy_value::<$t>(ptr); - } - ::std::thread_local::__impl::KeyInner { inner: ::std::cell::UnsafeCell { value: $init }, os: ::std::thread_local::__impl::OsStaticKey { inner: ::std::thread_local::__impl::OS_INIT_INNER, - dtor: ::std::option::Option::Some(__destroy as unsafe extern fn(*mut u8)), + dtor: ::std::option::Option::Some( + ::std::thread_local::__impl::destroy_value::<$t> + ), }, } }; -- cgit 1.4.1-3-g733a5 From 0090e01f08f7ed564a62fb3cd2e3b652317d39d7 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Mon, 23 Mar 2015 00:58:19 -0400 Subject: Get __pthread_get_minstack at runtime with dlsym MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Linking __pthread_get_minstack, even weakly, was causing Debian’s dpkg-shlibdeps to detect an unnecessarily strict versioned dependency on libc6. Closes #23628. Signed-off-by: Anders Kaseorg --- src/libstd/sys/unix/thread.rs | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index c5f07c6c75a..1d3cb43465b 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -13,12 +13,14 @@ use core::prelude::*; use cmp; +use dynamic_lib::DynamicLibrary; use ffi::CString; use io; use libc::consts::os::posix01::PTHREAD_STACK_MIN; use libc; use mem; use ptr; +use sync::{Once, ONCE_INIT}; use sys::os; use thunk::Thunk; use time::Duration; @@ -314,21 +316,30 @@ pub fn sleep(dur: Duration) { // is created in an application with big thread-local storage requirements. // See #6233 for rationale and details. // -// Link weakly to the symbol for compatibility with older versions of glibc. -// Assumes that we've been dynamically linked to libpthread but that is -// currently always the case. Note that you need to check that the symbol -// is non-null before calling it! +// Use dlsym to get the symbol value at runtime, for compatibility +// with older versions of glibc. Assumes that we've been dynamically +// linked to libpthread but that is currently always the case. We +// previously used weak linkage (under the same assumption), but that +// caused Debian to detect an unnecessarily strict versioned +// dependency on libc6 (#23628). #[cfg(target_os = "linux")] fn min_stack_size(attr: *const libc::pthread_attr_t) -> libc::size_t { type F = unsafe extern "C" fn(*const libc::pthread_attr_t) -> libc::size_t; - extern { - #[linkage = "extern_weak"] - static __pthread_get_minstack: *const (); - } - if __pthread_get_minstack.is_null() { - PTHREAD_STACK_MIN - } else { - unsafe { mem::transmute::<*const (), F>(__pthread_get_minstack)(attr) } + static INIT: Once = ONCE_INIT; + static mut __pthread_get_minstack: Option = None; + + INIT.call_once(|| { + let lib = DynamicLibrary::open(None).unwrap(); + unsafe { + if let Ok(f) = lib.symbol("__pthread_get_minstack") { + __pthread_get_minstack = Some(mem::transmute::<*const (), F>(f)); + } + } + }); + + match unsafe { __pthread_get_minstack } { + None => PTHREAD_STACK_MIN, + Some(f) => unsafe { f(attr) }, } } -- cgit 1.4.1-3-g733a5 From b6641c1595687a6c7c8ba381b46b931a58a3ada4 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Mon, 23 Mar 2015 03:48:06 -0400 Subject: min_stack_size: update non-Linux implementation comment Signed-off-by: Anders Kaseorg --- src/libstd/sys/unix/thread.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index 1d3cb43465b..b3594dcaa75 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -343,8 +343,8 @@ fn min_stack_size(attr: *const libc::pthread_attr_t) -> libc::size_t { } } -// __pthread_get_minstack() is marked as weak but extern_weak linkage is -// not supported on OS X, hence this kludge... +// No point in looking up __pthread_get_minstack() on non-glibc +// platforms. #[cfg(not(target_os = "linux"))] fn min_stack_size(_: *const libc::pthread_attr_t) -> libc::size_t { PTHREAD_STACK_MIN -- cgit 1.4.1-3-g733a5 From 737bb30f0af5b27785a006a91a8792a06478de87 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Mon, 23 Mar 2015 04:02:02 -0400 Subject: min_stack_size: clarify both reasons to use dlsym Signed-off-by: Anders Kaseorg --- src/libstd/sys/unix/thread.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index b3594dcaa75..c66d86b7625 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -316,11 +316,12 @@ pub fn sleep(dur: Duration) { // is created in an application with big thread-local storage requirements. // See #6233 for rationale and details. // -// Use dlsym to get the symbol value at runtime, for compatibility -// with older versions of glibc. Assumes that we've been dynamically -// linked to libpthread but that is currently always the case. We -// previously used weak linkage (under the same assumption), but that -// caused Debian to detect an unnecessarily strict versioned +// Use dlsym to get the symbol value at runtime, both for +// compatibility with older versions of glibc, and to avoid creating +// dependencies on GLIBC_PRIVATE symbols. Assumes that we've been +// dynamically linked to libpthread but that is currently always the +// case. We previously used weak linkage (under the same assumption), +// but that caused Debian to detect an unnecessarily strict versioned // dependency on libc6 (#23628). #[cfg(target_os = "linux")] fn min_stack_size(attr: *const libc::pthread_attr_t) -> libc::size_t { -- cgit 1.4.1-3-g733a5 From d944689cf6c702170c663a073810b019adc8bcca Mon Sep 17 00:00:00 2001 From: Wangshan Lu Date: Mon, 23 Mar 2015 19:11:03 +0800 Subject: Fix dead link for std::sync::mpsc. --- src/libstd/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libstd') diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index b055796ba54..244a51e5efc 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -75,7 +75,7 @@ //! //! The [`thread`](thread/index.html) module contains Rust's threading abstractions. //! [`sync`](sync/index.html) contains further, primitive, shared memory types, -//! including [`atomic`](sync/atomic/index.html), and [`mpsc`](sync/mpmc/index.html), +//! including [`atomic`](sync/atomic/index.html), and [`mpsc`](sync/mpsc/index.html), //! which contains the channel types for message passing. //! //! Common types of I/O, including files, TCP, UDP, pipes, Unix domain sockets, -- cgit 1.4.1-3-g733a5 From 64532f7f0001e4627be839d877ded1ba0326b615 Mon Sep 17 00:00:00 2001 From: Andrew Paseltiner Date: Mon, 23 Mar 2015 08:50:47 -0400 Subject: implement `Clone` for various iterators --- src/libcollections/bit.rs | 4 ++++ src/libcollections/vec_deque.rs | 1 + src/libstd/collections/hash/set.rs | 25 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+) (limited to 'src/libstd') diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index 90fbe04d348..1e6171af4d8 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -1792,12 +1792,16 @@ struct TwoBitPositions<'a> { next_idx: usize } +#[derive(Clone)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Union<'a>(TwoBitPositions<'a>); +#[derive(Clone)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Intersection<'a>(Take>); +#[derive(Clone)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Difference<'a>(TwoBitPositions<'a>); +#[derive(Clone)] #[stable(feature = "rust1", since = "1.0.0")] pub struct SymmetricDifference<'a>(TwoBitPositions<'a>); diff --git a/src/libcollections/vec_deque.rs b/src/libcollections/vec_deque.rs index 56ca74dab1f..2ade67f26bb 100644 --- a/src/libcollections/vec_deque.rs +++ b/src/libcollections/vec_deque.rs @@ -1573,6 +1573,7 @@ impl<'a, T> DoubleEndedIterator for IterMut<'a, T> { impl<'a, T> ExactSizeIterator for IterMut<'a, T> {} /// A by-value VecDeque iterator +#[derive(Clone)] #[stable(feature = "rust1", since = "1.0.0")] pub struct IntoIter { inner: VecDeque, diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index de3f080de82..8d69ab430d3 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -853,6 +853,9 @@ impl IntoIterator for HashSet } } +impl<'a, K> Clone for Iter<'a, K> { + fn clone(&self) -> Iter<'a, K> { Iter { iter: self.iter.clone() } } +} #[stable(feature = "rust1", since = "1.0.0")] impl<'a, K> Iterator for Iter<'a, K> { type Item = &'a K; @@ -889,6 +892,12 @@ impl<'a, K> ExactSizeIterator for Drain<'a, K> { fn len(&self) -> usize { self.iter.len() } } +impl<'a, T, S> Clone for Intersection<'a, T, S> { + fn clone(&self) -> Intersection<'a, T, S> { + Intersection { iter: self.iter.clone(), ..*self } + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T, S> Iterator for Intersection<'a, T, S> where T: Eq + Hash, S: HashState @@ -912,6 +921,12 @@ impl<'a, T, S> Iterator for Intersection<'a, T, S> } } +impl<'a, T, S> Clone for Difference<'a, T, S> { + fn clone(&self) -> Difference<'a, T, S> { + Difference { iter: self.iter.clone(), ..*self } + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T, S> Iterator for Difference<'a, T, S> where T: Eq + Hash, S: HashState @@ -935,6 +950,12 @@ impl<'a, T, S> Iterator for Difference<'a, T, S> } } +impl<'a, T, S> Clone for SymmetricDifference<'a, T, S> { + fn clone(&self) -> SymmetricDifference<'a, T, S> { + SymmetricDifference { iter: self.iter.clone() } + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T, S> Iterator for SymmetricDifference<'a, T, S> where T: Eq + Hash, S: HashState @@ -945,6 +966,10 @@ impl<'a, T, S> Iterator for SymmetricDifference<'a, T, S> fn size_hint(&self) -> (usize, Option) { self.iter.size_hint() } } +impl<'a, T, S> Clone for Union<'a, T, S> { + fn clone(&self) -> Union<'a, T, S> { Union { iter: self.iter.clone() } } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T, S> Iterator for Union<'a, T, S> where T: Eq + Hash, S: HashState -- cgit 1.4.1-3-g733a5 From d6fb7e9da8d0c1216a1f60ea71ee91080f7b24ae Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Sun, 22 Mar 2015 16:16:04 +0100 Subject: derive missing trait implementations for cursor --- src/libstd/io/cursor.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/libstd') diff --git a/src/libstd/io/cursor.rs b/src/libstd/io/cursor.rs index 365f5e37b0b..e6debeb2a9c 100644 --- a/src/libstd/io/cursor.rs +++ b/src/libstd/io/cursor.rs @@ -31,6 +31,7 @@ use slice; /// over `T` itself. Instead, specific implementations are provided for various /// in-memory buffer types like `Vec` and `&[u8]`. #[stable(feature = "rust1", since = "1.0.0")] +#[derive(Clone, Debug)] pub struct Cursor { inner: T, pos: u64, -- cgit 1.4.1-3-g733a5 From 9ec9bc68fb310aac29e984d26cc37952de328f1e Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 11 Mar 2015 10:55:31 -0700 Subject: Clarify behavior of Path::relative_from --- src/libstd/path.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/libstd') diff --git a/src/libstd/path.rs b/src/libstd/path.rs index ddceed14cc6..05c7761be7b 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1243,6 +1243,9 @@ impl Path { } /// Returns a path that, when joined onto `base`, yields `self`. + /// + /// If `base` is not a prefix of `self` (i.e. `starts_with` + /// returns false), then `relative_from` returns `None`. #[unstable(feature = "path_relative_from", reason = "see #23284")] pub fn relative_from<'a, P: ?Sized>(&'a self, base: &'a P) -> Option<&Path> where P: AsPath -- cgit 1.4.1-3-g733a5 From a5e1cbe1915f9fd31900f25f72533fb296ff9a3a Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Sun, 22 Mar 2015 18:38:40 -0400 Subject: Beef up BufRead::consume documentation. Fixes #23196 --- src/libstd/io/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/libstd') diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 237435d6dfb..39c718c96b3 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -558,6 +558,12 @@ pub trait BufRead: Read { /// This function does not perform any I/O, it simply informs this object /// that some amount of its buffer, returned from `fill_buf`, has been /// consumed and should no longer be returned. + /// + /// This function is used to tell the buffer how many bytes you've consumed + /// from the return value of `fill_buf`, and so may do odd things if + /// `fill_buf` isn't called before calling this. + /// + /// The `amt` must be `<=` the number of bytes in the buffer returned by `fill_buf`. #[stable(feature = "rust1", since = "1.0.0")] fn consume(&mut self, amt: usize); -- cgit 1.4.1-3-g733a5 From d52c36246a2e7e1d263b31709424798cfdaa00e3 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Mon, 23 Mar 2015 13:40:41 -0400 Subject: Clarify that slices don't just point to arrays Fixes #23632 --- src/libstd/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index b055796ba54..6833b6a0a21 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -40,11 +40,11 @@ //! //! ## Vectors, slices and strings //! -//! The common container type, `Vec`, a growable vector backed by an -//! array, lives in the [`vec`](vec/index.html) module. References to -//! arrays, `&[T]`, more commonly called "slices", are built-in types -//! for which the [`slice`](slice/index.html) module defines many -//! methods. +//! The common container type, `Vec`, a growable vector backed by an array, +//! lives in the [`vec`](vec/index.html) module. Contiguous, unsized regions +//! of memory, `[T]`, commonly called "slices", and their borrowed versions, +//! `&[T]`, commonly called "borrowed slices", are built-in types for which the +//! for which the [`slice`](slice/index.html) module defines many methods. //! //! `&str`, a UTF-8 string, is a built-in type, and the standard library //! defines methods for it on a variety of traits in the -- cgit 1.4.1-3-g733a5 From d29d5545b6a5485bb1a51e035889e20330b2e4f7 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Mon, 23 Mar 2015 19:06:09 +0200 Subject: prctl instead of pthread on linux for name setup This is more portable as far as linux is concerned. --- src/libstd/sys/unix/thread.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index c5f07c6c75a..4ba0d6472b6 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -227,19 +227,16 @@ pub unsafe fn create(stack: usize, p: Thunk) -> io::Result { #[cfg(any(target_os = "linux", target_os = "android"))] pub unsafe fn set_name(name: &str) { - // pthread_setname_np() since glibc 2.12 - // availability autodetected via weak linkage - type F = unsafe extern fn(libc::pthread_t, *const libc::c_char) - -> libc::c_int; + // pthread wrapper only appeared in glibc 2.12, so we use syscall directly. extern { - #[linkage = "extern_weak"] - static pthread_setname_np: *const (); - } - if !pthread_setname_np.is_null() { - let cname = CString::new(name).unwrap(); - mem::transmute::<*const (), F>(pthread_setname_np)(pthread_self(), - cname.as_ptr()); + fn prctl(option: libc::c_int, arg2: libc::c_ulong, arg3: libc::c_ulong, + arg4: libc::c_ulong, arg5: libc::c_ulong) -> libc::c_int; } + const PR_SET_NAME: libc::c_int = 15; + let cname = CString::new(name).unwrap_or_else(|_| { + panic!("thread name may not contain interior null bytes") + }); + prctl(PR_SET_NAME, cname.as_ptr() as libc::c_ulong, 0, 0, 0); } #[cfg(any(target_os = "freebsd", -- cgit 1.4.1-3-g733a5 From 9231ceb6dd273d8101e1b3906e6060f802e6423d Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Thu, 19 Mar 2015 16:37:34 -0700 Subject: Stabilize the Error trait This small commit stabilizes the `Error` trait as-is, except that `Send` and `Debug` are added as constraints. The `Send` constraint is because most uses of `Error` will be for trait objects, and by default we would like these objects to be transferrable between threads. The `Debug` constraint is to ensure that e.g. `Box` is `Debug`, and because types that implement `Display` should certainly implement `Debug` in any case. In the near future we expect to add `Any`-like downcasting features to `Error`, but this is waiting on some additional mechanisms (`Reflect`). It will be added before 1.0 via default methods. [breaking-change] --- src/libcore/error.rs | 15 ++++++++++----- src/libstd/io/buffered.rs | 2 +- src/libstd/sync/mpsc/mod.rs | 4 ++-- src/libstd/sync/poison.rs | 8 ++++---- src/rustbook/error.rs | 1 + 5 files changed, 18 insertions(+), 12 deletions(-) (limited to 'src/libstd') diff --git a/src/libcore/error.rs b/src/libcore/error.rs index 161f6c78921..d29964d63a5 100644 --- a/src/libcore/error.rs +++ b/src/libcore/error.rs @@ -82,16 +82,21 @@ #![stable(feature = "rust1", since = "1.0.0")] use prelude::*; -use fmt::Display; +use fmt::{Debug, Display}; /// Base functionality for all errors in Rust. -#[unstable(feature = "core", - reason = "the exact API of this trait may change")] -pub trait Error: Display { - /// A short description of the error; usually a static string. +#[stable(feature = "rust1", since = "1.0.0")] +pub trait Error: Debug + Display + Send { + /// A short description of the error. + /// + /// The description should not contain newlines or sentence-ending + /// punctuation, to facilitate embedding in larger user-facing + /// strings. + #[stable(feature = "rust1", since = "1.0.0")] fn description(&self) -> &str; /// The lower-level cause of this error, if any. + #[stable(feature = "rust1", since = "1.0.0")] fn cause(&self) -> Option<&Error> { None } } diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 43eec695274..4def601f1c0 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -258,7 +258,7 @@ impl FromError> for Error { } #[stable(feature = "rust1", since = "1.0.0")] -impl error::Error for IntoInnerError { +impl error::Error for IntoInnerError { fn description(&self) -> &str { error::Error::description(self.error()) } diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 01eeed4fb54..2cf0df305c2 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -977,7 +977,7 @@ impl fmt::Display for SendError { } #[stable(feature = "rust1", since = "1.0.0")] -impl error::Error for SendError { +impl error::Error for SendError { fn description(&self) -> &str { "sending on a closed channel" @@ -1013,7 +1013,7 @@ impl fmt::Display for TrySendError { } #[stable(feature = "rust1", since = "1.0.0")] -impl error::Error for TrySendError { +impl error::Error for TrySendError { fn description(&self) -> &str { match *self { diff --git a/src/libstd/sync/poison.rs b/src/libstd/sync/poison.rs index 2587ff5238e..c07c83d37f4 100644 --- a/src/libstd/sync/poison.rs +++ b/src/libstd/sync/poison.rs @@ -105,11 +105,11 @@ impl fmt::Debug for PoisonError { #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Display for PoisonError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.description().fmt(f) + "poisoned lock: another task failed inside".fmt(f) } } -impl Error for PoisonError { +impl Error for PoisonError { fn description(&self) -> &str { "poisoned lock: another task failed inside" } @@ -161,13 +161,13 @@ impl fmt::Debug for TryLockError { } #[stable(feature = "rust1", since = "1.0.0")] -impl fmt::Display for TryLockError { +impl fmt::Display for TryLockError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.description().fmt(f) } } -impl Error for TryLockError { +impl Error for TryLockError { fn description(&self) -> &str { match *self { TryLockError::Poisoned(ref p) => p.description(), diff --git a/src/rustbook/error.rs b/src/rustbook/error.rs index 294b4e55669..e896dee2791 100644 --- a/src/rustbook/error.rs +++ b/src/rustbook/error.rs @@ -20,6 +20,7 @@ pub type CommandError = Box; pub type CommandResult = Result; pub fn err(s: &str) -> CliError { + #[derive(Debug)] struct E(String); impl Error for E { -- cgit 1.4.1-3-g733a5 From 6bd3ab0d8140053475a901ad4e2e80e98955bcb0 Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Fri, 20 Mar 2015 00:46:13 -0700 Subject: Implement RFC 909: move thread_local into thread This commit implements [RFC 909](https://github.com/rust-lang/rfcs/pull/909): The `std::thread_local` module is now deprecated, and its contents are available directly in `std::thread` as `LocalKey`, `LocalKeyState`, and `ScopedKey`. The macros remain exactly as they were, which means little if any code should break. Nevertheless, this is technically a: [breaking-change] Closes #23547 --- src/libstd/lib.rs | 23 +- src/libstd/sys/common/thread_info.rs | 4 +- src/libstd/thread.rs | 960 ------------------------------- src/libstd/thread/local.rs | 735 ++++++++++++++++++++++++ src/libstd/thread/mod.rs | 1026 ++++++++++++++++++++++++++++++++++ src/libstd/thread/scoped.rs | 317 +++++++++++ src/libstd/thread_local/mod.rs | 762 ------------------------- src/libstd/thread_local/scoped.rs | 313 ----------- 8 files changed, 2088 insertions(+), 2052 deletions(-) delete mode 100644 src/libstd/thread.rs create mode 100644 src/libstd/thread/local.rs create mode 100644 src/libstd/thread/mod.rs create mode 100644 src/libstd/thread/scoped.rs delete mode 100644 src/libstd/thread_local/mod.rs delete mode 100644 src/libstd/thread_local/scoped.rs (limited to 'src/libstd') diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index b055796ba54..970074f7930 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -249,30 +249,23 @@ pub mod num; /* Runtime and platform support */ #[macro_use] -pub mod thread_local; +pub mod thread; +pub mod collections; pub mod dynamic_lib; +pub mod env; pub mod ffi; -pub mod old_io; -pub mod io; pub mod fs; +pub mod io; pub mod net; +pub mod old_io; +pub mod old_path; pub mod os; -pub mod env; pub mod path; -pub mod old_path; pub mod process; pub mod rand; -pub mod time; - -/* Common data structures */ - -pub mod collections; - -/* Threads and communication */ - -pub mod thread; pub mod sync; +pub mod time; #[macro_use] #[path = "sys/common/mod.rs"] mod sys_common; @@ -305,7 +298,7 @@ mod std { pub use rt; // used for panic!() pub use vec; // used for vec![] pub use cell; // used for tls! - pub use thread_local; // used for thread_local! + pub use thread; // used for thread_local! pub use marker; // used for tls! pub use ops; // used for bitflags! diff --git a/src/libstd/sys/common/thread_info.rs b/src/libstd/sys/common/thread_info.rs index e4985e703ba..90526b8f4f3 100644 --- a/src/libstd/sys/common/thread_info.rs +++ b/src/libstd/sys/common/thread_info.rs @@ -15,7 +15,7 @@ use core::prelude::*; use cell::RefCell; use string::String; use thread::Thread; -use thread_local::State; +use thread::LocalKeyState; struct ThreadInfo { stack_guard: uint, @@ -26,7 +26,7 @@ thread_local! { static THREAD_INFO: RefCell> = RefCell::new(N impl ThreadInfo { fn with(f: F) -> R where F: FnOnce(&mut ThreadInfo) -> R { - if THREAD_INFO.state() == State::Destroyed { + if THREAD_INFO.state() == LocalKeyState::Destroyed { panic!("Use of std::thread::current() is not possible after \ the thread's local data has been destroyed"); } diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs deleted file mode 100644 index ab74442cac9..00000000000 --- a/src/libstd/thread.rs +++ /dev/null @@ -1,960 +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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Native threads -//! -//! ## The threading model -//! -//! An executing Rust program consists of a collection of native OS threads, -//! each with their own stack and local state. -//! -//! Communication between threads can be done through -//! [channels](../../std/sync/mpsc/index.html), Rust's message-passing -//! types, along with [other forms of thread -//! synchronization](../../std/sync/index.html) and shared-memory data -//! structures. In particular, types that are guaranteed to be -//! threadsafe are easily shared between threads using the -//! atomically-reference-counted container, -//! [`Arc`](../../std/sync/struct.Arc.html). -//! -//! Fatal logic errors in Rust cause *thread panic*, during which -//! a thread will unwind the stack, running destructors and freeing -//! owned resources. Thread panic is unrecoverable from within -//! the panicking thread (i.e. there is no 'try/catch' in Rust), but -//! the panic may optionally be detected from a different thread. If -//! the main thread panics, the application will exit with a non-zero -//! exit code. -//! -//! When the main thread of a Rust program terminates, the entire program shuts -//! down, even if other threads are still running. However, this module provides -//! convenient facilities for automatically waiting for the termination of a -//! child thread (i.e., join). -//! -//! ## The `Thread` type -//! -//! Threads are represented via the `Thread` type, which you can -//! get in one of two ways: -//! -//! * By spawning a new thread, e.g. using the `thread::spawn` function. -//! * By requesting the current thread, using the `thread::current` function. -//! -//! Threads can be named, and provide some built-in support for low-level -//! synchronization (described below). -//! -//! The `thread::current()` function is available even for threads not spawned -//! by the APIs of this module. -//! -//! ## Spawning a thread -//! -//! A new thread can be spawned using the `thread::spawn` function: -//! -//! ```rust -//! use std::thread; -//! -//! thread::spawn(move || { -//! // some work here -//! }); -//! ``` -//! -//! In this example, the spawned thread is "detached" from the current -//! thread. This means that it can outlive its parent (the thread that spawned -//! it), unless this parent is the main thread. -//! -//! ## Scoped threads -//! -//! Often a parent thread uses a child thread to perform some particular task, -//! and at some point must wait for the child to complete before continuing. -//! For this scenario, use the `thread::scoped` function: -//! -//! ```rust -//! 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 is an RAII-style guard -//! that will automatically join the child thread (block until it -//! terminates) when it is dropped. You can join the child thread in -//! advance by calling the `join` method on the guard, which will also -//! return the result produced by the thread. A handle to the thread -//! itself is available via the `thread` method of the join guard. -//! -//! ## Configuring threads -//! -//! A new thread can be configured before it is spawned via the `Builder` type, -//! which currently allows you to set the name, stack size, and writers for -//! `println!` and `panic!` for the child thread: -//! -//! ```rust -//! use std::thread; -//! -//! thread::Builder::new().name("child1".to_string()).spawn(move || { -//! println!("Hello, world!"); -//! }); -//! ``` -//! -//! ## Blocking support: park and unpark -//! -//! Every thread is equipped with some basic low-level blocking support, via the -//! `park` and `unpark` functions. -//! -//! Conceptually, each `Thread` handle has an associated token, which is -//! initially not present: -//! -//! * The `thread::park()` function blocks the current thread unless or until -//! the token is available for its thread handle, at which point it atomically -//! consumes the token. It may also return *spuriously*, without consuming the -//! token. `thread::park_timeout()` does the same, but allows specifying a -//! maximum time to block the thread for. -//! -//! * The `unpark()` method on a `Thread` atomically makes the token available -//! if it wasn't already. -//! -//! In other words, each `Thread` acts a bit like a semaphore with initial count -//! 0, except that the semaphore is *saturating* (the count cannot go above 1), -//! and can return spuriously. -//! -//! The API is typically used by acquiring a handle to the current thread, -//! placing that handle in a shared data structure so that other threads can -//! find it, and then `park`ing. When some desired condition is met, another -//! thread calls `unpark` on the handle. -//! -//! The motivation for this design is twofold: -//! -//! * It avoids the need to allocate mutexes and condvars when building new -//! synchronization primitives; the threads already provide basic blocking/signaling. -//! -//! * It can be implemented very efficiently on many platforms. - -#![stable(feature = "rust1", since = "1.0.0")] - -use prelude::v1::*; - -use any::Any; -use cell::UnsafeCell; -use fmt; -use io; -use marker::PhantomData; -use rt::{self, unwind}; -use sync::{Mutex, Condvar, Arc}; -use sys::thread as imp; -use sys_common::{stack, thread_info}; -use thunk::Thunk; -use time::Duration; - -#[allow(deprecated)] use old_io::Writer; - -/// Thread configuration. Provides detailed control over the properties -/// and behavior of new threads. -#[stable(feature = "rust1", since = "1.0.0")] -pub struct Builder { - // A name for the thread-to-be, for identification in panic messages - name: Option, - // The size of the stack for the spawned thread - stack_size: Option, -} - -impl Builder { - /// Generate the base configuration for spawning a thread, from which - /// configuration methods can be chained. - #[stable(feature = "rust1", since = "1.0.0")] - pub fn new() -> Builder { - Builder { - name: None, - stack_size: None, - } - } - - /// Name the thread-to-be. Currently the name is used for identification - /// only in panic messages. - #[stable(feature = "rust1", since = "1.0.0")] - pub fn name(mut self, name: String) -> Builder { - self.name = Some(name); - self - } - - /// Set the size of the stack for the new thread. - #[stable(feature = "rust1", since = "1.0.0")] - pub fn stack_size(mut self, size: usize) -> Builder { - self.stack_size = Some(size); - self - } - - /// Redirect thread-local stdout. - #[unstable(feature = "std_misc", - reason = "Will likely go away after proc removal")] - #[deprecated(since = "1.0.0", - reason = "the old I/O module is deprecated and this function \ - will be removed with no replacement")] - #[allow(deprecated)] - pub fn stdout(self, _stdout: Box) -> Builder { - self - } - - /// Redirect thread-local stderr. - #[unstable(feature = "std_misc", - reason = "Will likely go away after proc removal")] - #[deprecated(since = "1.0.0", - reason = "the old I/O module is deprecated and this function \ - will be removed with no replacement")] - #[allow(deprecated)] - pub fn stderr(self, _stderr: Box) -> Builder { - self - } - - /// Spawn a new thread, and return a join handle for it. - /// - /// The child thread may outlive the parent (unless the parent thread - /// is the main thread; the whole process is terminated when the main - /// thread finishes.) The join handle can be used to block on - /// termination of the child thread, including recovering its panics. - /// - /// # Errors - /// - /// Unlike the `spawn` free function, this method yields an - /// `io::Result` to capture any failure to create the thread at - /// the OS level. - #[stable(feature = "rust1", since = "1.0.0")] - pub fn spawn(self, f: F) -> io::Result where - F: FnOnce(), F: Send + 'static - { - self.spawn_inner(Thunk::new(f)).map(|i| JoinHandle(i)) - } - - /// Spawn a new child thread that must be joined within a given - /// scope, and return a `JoinGuard`. - /// - /// The join guard can be used to explicitly join the child thread (via - /// `join`), returning `Result`, 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 - /// module documentation 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. - #[stable(feature = "rust1", since = "1.0.0")] - pub fn scoped<'a, T, F>(self, f: F) -> io::Result> where - T: Send + 'a, F: FnOnce() -> T, F: Send + 'a - { - self.spawn_inner(Thunk::new(f)).map(|inner| { - JoinGuard { inner: inner, _marker: PhantomData } - }) - } - - fn spawn_inner(self, f: Thunk<(), T>) -> io::Result> { - let Builder { name, stack_size } = self; - - let stack_size = stack_size.unwrap_or(rt::min_stack()); - - let my_thread = Thread::new(name); - let their_thread = my_thread.clone(); - - let my_packet = Packet(Arc::new(UnsafeCell::new(None))); - let their_packet = Packet(my_packet.0.clone()); - - // Spawning a new OS thread guarantees that __morestack will never get - // triggered, but we must manually set up the actual stack bounds once - // this function starts executing. This raises the lower limit by a bit - // because by the time that this function is executing we've already - // consumed at least a little bit of stack (we don't know the exact byte - // address at which our stack started). - let main = move || { - let something_around_the_top_of_the_stack = 1; - let addr = &something_around_the_top_of_the_stack as *const i32; - let my_stack_top = addr as usize; - let my_stack_bottom = my_stack_top - stack_size + 1024; - unsafe { - if let Some(name) = their_thread.name() { - imp::set_name(name); - } - stack::record_os_managed_stack_bounds(my_stack_bottom, - my_stack_top); - thread_info::set(imp::guard::current(), their_thread); - } - - let mut output = None; - let try_result = { - let ptr = &mut output; - - // There are two primary reasons that general try/catch is - // unsafe. The first is that we do not support nested - // try/catch. The fact that this is happening in a newly-spawned - // thread suffices. The second is that unwinding while unwinding - // is not defined. We take care of that by having an - // 'unwinding' flag in the thread itself. For these reasons, - // this unsafety should be ok. - unsafe { - unwind::try(move || *ptr = Some(f.invoke(()))) - } - }; - unsafe { - *their_packet.0.get() = Some(match (output, try_result) { - (Some(data), Ok(_)) => Ok(data), - (None, Err(cause)) => Err(cause), - _ => unreachable!() - }); - } - }; - - Ok(JoinInner { - native: try!(unsafe { imp::create(stack_size, Thunk::new(main)) }), - thread: my_thread, - packet: my_packet, - joined: false, - }) - } -} - -/// Spawn a new thread, returning a `JoinHandle` for it. -/// -/// The join handle will implicitly *detach* the child thread upon being -/// dropped. In this case, the child thread may outlive the parent (unless -/// the parent thread is the main thread; the whole process is terminated when -/// the main thread finishes.) Additionally, the join handle provides a `join` -/// method that can be used to join the child thread. If the child thread -/// panics, `join` will return an `Err` containing the argument given to -/// `panic`. -/// -/// # Panics -/// -/// Panicks if the OS fails to create a thread; use `Builder::spawn` -/// to recover from such errors. -#[stable(feature = "rust1", since = "1.0.0")] -pub fn spawn(f: F) -> JoinHandle where F: FnOnce(), F: Send + 'static { - Builder::new().spawn(f).unwrap() -} - -/// Spawn a new *scoped* thread, returning a `JoinGuard` for it. -/// -/// The join guard can be used to explicitly join the child thread (via -/// `join`), returning `Result`, 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 -/// module documentation for additional details. -/// -/// # Panics -/// -/// Panicks if the OS fails to create a thread; use `Builder::scoped` -/// to recover from such errors. -#[stable(feature = "rust1", since = "1.0.0")] -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 { - thread_info::current_thread() -} - -/// Cooperatively give up a timeslice to the OS scheduler. -#[stable(feature = "rust1", since = "1.0.0")] -pub fn yield_now() { - unsafe { imp::yield_now() } -} - -/// Determines whether the current thread is unwinding because of panic. -#[inline] -#[stable(feature = "rust1", since = "1.0.0")] -pub fn panicking() -> bool { - unwind::panicking() -} - -/// Put the current thread to sleep for the specified amount of time. -/// -/// The thread may sleep longer than the duration specified due to scheduling -/// specifics or platform-dependent functionality. Note that on unix platforms -/// this function will not return early due to a signal being received or a -/// spurious wakeup. -#[unstable(feature = "thread_sleep", - reason = "recently added, needs an RFC, and `Duration` itself is \ - unstable")] -pub fn sleep(dur: Duration) { - imp::sleep(dur) -} - -/// Block unless or until the current thread's token is made available (may wake spuriously). -/// -/// See the module doc for more detail. -// -// The implementation currently uses the trivial strategy of a Mutex+Condvar -// with wakeup flag, which does not actually allow spurious wakeups. In the -// future, this will be implemented in a more efficient way, perhaps along the lines of -// http://cr.openjdk.java.net/~stefank/6989984.1/raw_files/new/src/os/linux/vm/os_linux.cpp -// or futuxes, and in either case may allow spurious wakeups. -#[stable(feature = "rust1", since = "1.0.0")] -pub fn park() { - let thread = current(); - let mut guard = thread.inner.lock.lock().unwrap(); - while !*guard { - guard = thread.inner.cvar.wait(guard).unwrap(); - } - *guard = false; -} - -/// Block unless or until the current thread's token is made available or -/// the specified duration has been reached (may wake spuriously). -/// -/// The semantics of this function are equivalent to `park()` except that the -/// thread will be blocked for roughly no longer than *duration*. This method -/// should not be used for precise timing due to anomalies such as -/// preemption or platform differences that may not cause the maximum -/// amount of time waited to be precisely *duration* long. -/// -/// See the module doc for more detail. -#[unstable(feature = "std_misc", reason = "recently introduced, depends on Duration")] -pub fn park_timeout(duration: Duration) { - let thread = current(); - let mut guard = thread.inner.lock.lock().unwrap(); - if !*guard { - let (g, _) = thread.inner.cvar.wait_timeout(guard, duration).unwrap(); - guard = g; - } - *guard = false; -} - -/// The internal representation of a `Thread` handle -struct Inner { - name: Option, - lock: Mutex, // true when there is a buffered unpark - cvar: Condvar, -} - -unsafe impl Sync for Inner {} - -#[derive(Clone)] -#[stable(feature = "rust1", since = "1.0.0")] -/// A handle to a thread. -pub struct Thread { - inner: Arc, -} - -impl Thread { - // Used only internally to construct a thread object without spawning - fn new(name: Option) -> Thread { - Thread { - inner: Arc::new(Inner { - name: name, - lock: Mutex::new(false), - cvar: Condvar::new(), - }) - } - } - - /// Deprecated: use module-level free function. - #[deprecated(since = "1.0.0", reason = "use module-level free function")] - #[unstable(feature = "std_misc", - reason = "may change with specifics of new Send semantics")] - pub fn spawn(f: F) -> Thread where F: FnOnce(), F: Send + 'static { - Builder::new().spawn(f).unwrap().thread().clone() - } - - /// Deprecated: use module-level free function. - #[deprecated(since = "1.0.0", reason = "use module-level free function")] - #[unstable(feature = "std_misc", - reason = "may change with specifics of new Send semantics")] - 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() - } - - /// Deprecated: use module-level free function. - #[deprecated(since = "1.0.0", reason = "use module-level free function")] - #[stable(feature = "rust1", since = "1.0.0")] - pub fn current() -> Thread { - thread_info::current_thread() - } - - /// Deprecated: use module-level free function. - #[deprecated(since = "1.0.0", reason = "use module-level free function")] - #[unstable(feature = "std_misc", reason = "name may change")] - pub fn yield_now() { - unsafe { imp::yield_now() } - } - - /// Deprecated: use module-level free function. - #[deprecated(since = "1.0.0", reason = "use module-level free function")] - #[inline] - #[stable(feature = "rust1", since = "1.0.0")] - pub fn panicking() -> bool { - unwind::panicking() - } - - /// Deprecated: use module-level free function. - #[deprecated(since = "1.0.0", reason = "use module-level free function")] - #[unstable(feature = "std_misc", reason = "recently introduced")] - pub fn park() { - let thread = current(); - let mut guard = thread.inner.lock.lock().unwrap(); - while !*guard { - guard = thread.inner.cvar.wait(guard).unwrap(); - } - *guard = false; - } - - /// Deprecated: use module-level free function. - #[deprecated(since = "1.0.0", reason = "use module-level free function")] - #[unstable(feature = "std_misc", reason = "recently introduced")] - pub fn park_timeout(duration: Duration) { - let thread = current(); - let mut guard = thread.inner.lock.lock().unwrap(); - if !*guard { - let (g, _) = thread.inner.cvar.wait_timeout(guard, duration).unwrap(); - guard = g; - } - *guard = false; - } - - /// Atomically makes the handle's token available if it is not already. - /// - /// See the module doc for more detail. - #[stable(feature = "rust1", since = "1.0.0")] - pub fn unpark(&self) { - let mut guard = self.inner.lock.lock().unwrap(); - if !*guard { - *guard = true; - self.inner.cvar.notify_one(); - } - } - - /// Get the thread's name. - #[stable(feature = "rust1", since = "1.0.0")] - pub fn name(&self) -> Option<&str> { - self.inner.name.as_ref().map(|s| &**s) - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl fmt::Debug for Thread { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::Debug::fmt(&self.name(), f) - } -} - -// a hack to get around privacy restrictions -impl thread_info::NewThread for Thread { - fn new(name: Option) -> Thread { Thread::new(name) } -} - -/// Indicates the manner in which a thread exited. -/// -/// A thread that completes without panicking is considered to exit successfully. -#[stable(feature = "rust1", since = "1.0.0")] -pub type Result = ::result::Result>; - -struct Packet(Arc>>>); - -unsafe impl Send for Packet {} -unsafe impl Sync for Packet {} - -/// Inner representation for JoinHandle and JoinGuard -struct JoinInner { - native: imp::rust_thread, - thread: Thread, - packet: Packet, - joined: bool, -} - -impl JoinInner { - fn join(&mut self) -> Result { - assert!(!self.joined); - unsafe { imp::join(self.native) }; - self.joined = true; - unsafe { - (*self.packet.0.get()).take().unwrap() - } - } -} - -/// An owned permission to join on a thread (block on its termination). -/// -/// Unlike a `JoinGuard`, a `JoinHandle` *detaches* the child thread -/// when it is dropped, rather than automatically joining on drop. -/// -/// Due to platform restrictions, it is not possible to `Clone` this -/// handle: the ability to join a child thread is a uniquely-owned -/// permission. -#[stable(feature = "rust1", since = "1.0.0")] -pub struct JoinHandle(JoinInner<()>); - -impl JoinHandle { - /// Extract a handle to the underlying thread - #[stable(feature = "rust1", since = "1.0.0")] - pub fn thread(&self) -> &Thread { - &self.0.thread - } - - /// Wait for the associated thread to finish. - /// - /// If the child thread panics, `Err` is returned with the parameter given - /// to `panic`. - #[stable(feature = "rust1", since = "1.0.0")] - pub fn join(mut self) -> Result<()> { - self.0.join() - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl Drop for JoinHandle { - fn drop(&mut self) { - if !self.0.joined { - unsafe { imp::detach(self.0.native) } - } - } -} - -/// An RAII-style guard that will block until thread termination when dropped. -/// -/// The type `T` is the return type for the thread's main function. -/// -/// Joining on drop is necessary to ensure memory safety when stack -/// data is shared between a parent and child thread. -/// -/// Due to platform restrictions, it is not possible to `Clone` this -/// handle: the ability to join a child thread is a uniquely-owned -/// permission. -#[must_use = "thread will be immediately joined if `JoinGuard` is not used"] -#[stable(feature = "rust1", since = "1.0.0")] -pub struct JoinGuard<'a, T: 'a> { - inner: JoinInner, - _marker: PhantomData<&'a T>, -} - -#[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<'a, T: Send + 'a> Sync for JoinGuard<'a, T> {} - -impl<'a, T: Send + 'a> JoinGuard<'a, T> { - /// Extract a handle to the thread this guard will join on. - #[stable(feature = "rust1", since = "1.0.0")] - pub fn thread(&self) -> &Thread { - &self.inner.thread - } - - /// Wait for the associated thread to finish, returning the result of the thread's - /// calculation. - /// - /// # Panics - /// - /// Panics on the child thread are propagated by panicking the parent. - #[stable(feature = "rust1", since = "1.0.0")] - pub fn join(mut self) -> T { - match self.inner.join() { - Ok(res) => res, - Err(_) => panic!("child thread {:?} panicked", self.thread()), - } - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl JoinGuard<'static, T> { - /// Detaches the child thread, allowing it to outlive its parent. - #[deprecated(since = "1.0.0", reason = "use spawn instead")] - #[unstable(feature = "std_misc")] - pub fn detach(mut self) { - unsafe { imp::detach(self.inner.native) }; - self.inner.joined = true; // avoid joining in the destructor - } -} - -#[unsafe_destructor] -#[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T: Send + 'a> Drop for JoinGuard<'a, T> { - fn drop(&mut self) { - if !self.inner.joined { - if self.inner.join().is_err() { - panic!("child thread {:?} panicked", self.thread()); - } - } - } -} - -#[cfg(test)] -mod test { - use prelude::v1::*; - - use any::Any; - use sync::mpsc::{channel, Sender}; - use boxed::BoxAny; - use result; - use std::old_io::{ChanReader, ChanWriter}; - use super::{Builder}; - use thread; - use thunk::Thunk; - use time::Duration; - - // !!! These tests are dangerous. If something is buggy, they will hang, !!! - // !!! instead of exiting cleanly. This might wedge the buildbots. !!! - - #[test] - fn test_unnamed_thread() { - thread::spawn(move|| { - assert!(thread::current().name().is_none()); - }).join().ok().unwrap(); - } - - #[test] - fn test_named_thread() { - Builder::new().name("ada lovelace".to_string()).scoped(move|| { - assert!(thread::current().name().unwrap() == "ada lovelace".to_string()); - }).unwrap().join(); - } - - #[test] - fn test_run_basic() { - let (tx, rx) = channel(); - thread::spawn(move|| { - tx.send(()).unwrap(); - }); - rx.recv().unwrap(); - } - - #[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!() - }).join() { - result::Result::Err(_) => (), - result::Result::Ok(()) => panic!() - } - } - - #[test] - fn test_scoped_success() { - let res = thread::scoped(move|| -> String { - "Success!".to_string() - }).join(); - assert!(res == "Success!"); - } - - #[test] - #[should_fail] - fn test_scoped_panic() { - thread::scoped(|| panic!()).join(); - } - - #[test] - #[should_fail] - fn test_scoped_implicit_panic() { - let _ = thread::scoped(|| panic!()); - } - - #[test] - fn test_spawn_sched() { - use clone::Clone; - - let (tx, rx) = channel(); - - fn f(i: i32, tx: Sender<()>) { - let tx = tx.clone(); - thread::spawn(move|| { - if i == 0 { - tx.send(()).unwrap(); - } else { - f(i - 1, tx); - } - }); - - } - f(10, tx); - rx.recv().unwrap(); - } - - #[test] - fn test_spawn_sched_childs_on_default_sched() { - let (tx, rx) = channel(); - - thread::spawn(move|| { - thread::spawn(move|| { - tx.send(()).unwrap(); - }); - }); - - rx.recv().unwrap(); - } - - fn avoid_copying_the_body(spawnfn: F) where F: FnOnce(Thunk<'static>) { - let (tx, rx) = channel(); - - let x: Box<_> = box 1; - let x_in_parent = (&*x) as *const i32 as usize; - - spawnfn(Thunk::new(move|| { - let x_in_child = (&*x) as *const i32 as usize; - tx.send(x_in_child).unwrap(); - })); - - let x_in_child = rx.recv().unwrap(); - assert_eq!(x_in_parent, x_in_child); - } - - #[test] - fn test_avoid_copying_the_body_spawn() { - avoid_copying_the_body(|v| { - thread::spawn(move || v.invoke(())); - }); - } - - #[test] - fn test_avoid_copying_the_body_thread_spawn() { - avoid_copying_the_body(|f| { - thread::spawn(move|| { - f.invoke(()); - }); - }) - } - - #[test] - fn test_avoid_copying_the_body_join() { - avoid_copying_the_body(|f| { - let _ = thread::spawn(move|| { - f.invoke(()) - }).join(); - }) - } - - #[test] - fn test_child_doesnt_ref_parent() { - // If the child refcounts the parent task, this will stack overflow when - // climbing the task tree to dereference each ancestor. (See #1789) - // (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> { - return Thunk::new(move|| { - if x < GENERATIONS { - thread::spawn(move|| child_no(x+1).invoke(())); - } - }); - } - thread::spawn(|| child_no(0).invoke(())); - } - - #[test] - fn test_simple_newsched_spawn() { - thread::spawn(move || {}); - } - - #[test] - fn test_try_panic_message_static_str() { - match thread::spawn(move|| { - panic!("static string"); - }).join() { - Err(e) => { - type T = &'static str; - assert!(e.is::()); - assert_eq!(*e.downcast::().unwrap(), "static string"); - } - Ok(()) => panic!() - } - } - - #[test] - fn test_try_panic_message_owned_str() { - match thread::spawn(move|| { - panic!("owned string".to_string()); - }).join() { - Err(e) => { - type T = String; - assert!(e.is::()); - assert_eq!(*e.downcast::().unwrap(), "owned string".to_string()); - } - Ok(()) => panic!() - } - } - - #[test] - fn test_try_panic_message_any() { - match thread::spawn(move|| { - panic!(box 413u16 as Box); - }).join() { - Err(e) => { - type T = Box; - assert!(e.is::()); - let any = e.downcast::().unwrap(); - assert!(any.is::()); - assert_eq!(*any.downcast::().unwrap(), 413); - } - Ok(()) => panic!() - } - } - - #[test] - fn test_try_panic_message_unit_struct() { - struct Juju; - - match thread::spawn(move|| { - panic!(Juju) - }).join() { - Err(ref e) if e.is::() => {} - Err(_) | Ok(()) => panic!() - } - } - - #[test] - fn test_park_timeout_unpark_before() { - for _ in 0..10 { - thread::current().unpark(); - thread::park_timeout(Duration::seconds(10_000_000)); - } - } - - #[test] - fn test_park_timeout_unpark_not_called() { - for _ in 0..10 { - thread::park_timeout(Duration::milliseconds(10)); - } - } - - #[test] - fn test_park_timeout_unpark_called_other_thread() { - use std::old_io; - - for _ in 0..10 { - let th = thread::current(); - - let _guard = thread::spawn(move || { - old_io::timer::sleep(Duration::milliseconds(50)); - th.unpark(); - }); - - thread::park_timeout(Duration::seconds(10_000_000)); - } - } - - #[test] - fn sleep_smoke() { - thread::sleep(Duration::milliseconds(2)); - thread::sleep(Duration::milliseconds(-2)); - } - - // NOTE: the corresponding test for stderr is in run-pass/task-stderr, due - // to the test harness apparently interfering with stderr configuration. -} diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs new file mode 100644 index 00000000000..43142d2e5bc --- /dev/null +++ b/src/libstd/thread/local.rs @@ -0,0 +1,735 @@ +// Copyright 2014-2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Thread local storage + +#![unstable(feature = "thread_local_internals")] + +use prelude::v1::*; + +use cell::UnsafeCell; + +// Sure wish we had macro hygiene, no? +#[doc(hidden)] +#[unstable(feature = "thread_local_internals")] +pub mod __impl { + pub use super::imp::Key as KeyInner; + pub use super::imp::destroy_value; + pub use sys_common::thread_local::INIT_INNER as OS_INIT_INNER; + pub use sys_common::thread_local::StaticKey as OsStaticKey; +} + +/// A thread local storage key which owns its contents. +/// +/// This key uses the fastest possible implementation available to it for the +/// target platform. It is instantiated with the `thread_local!` macro and the +/// primary method is the `with` method. +/// +/// The `with` method yields a reference to the contained value which cannot be +/// sent across tasks or escape the given closure. +/// +/// # Initialization and Destruction +/// +/// Initialization is dynamically performed on the first call to `with()` +/// within a thread, and values support destructors which will be run when a +/// thread exits. +/// +/// # Examples +/// +/// ``` +/// use std::cell::RefCell; +/// use std::thread; +/// +/// thread_local!(static FOO: RefCell = RefCell::new(1)); +/// +/// FOO.with(|f| { +/// assert_eq!(*f.borrow(), 1); +/// *f.borrow_mut() = 2; +/// }); +/// +/// // each thread starts out with the initial value of 1 +/// thread::spawn(move|| { +/// FOO.with(|f| { +/// assert_eq!(*f.borrow(), 1); +/// *f.borrow_mut() = 3; +/// }); +/// }); +/// +/// // we retain our original value of 2 despite the child thread +/// FOO.with(|f| { +/// assert_eq!(*f.borrow(), 2); +/// }); +/// ``` +#[stable(feature = "rust1", since = "1.0.0")] +pub struct LocalKey { + // The key itself may be tagged with #[thread_local], and this `Key` is + // stored as a `static`, and it's not valid for a static to reference the + // address of another thread_local static. For this reason we kinda wonkily + // work around this by generating a shim function which will give us the + // address of the inner TLS key at runtime. + // + // This is trivially devirtualizable by LLVM because we never store anything + // to this field and rustc can declare the `static` as constant as well. + #[doc(hidden)] + #[unstable(feature = "thread_local_internals")] + pub inner: fn() -> &'static __impl::KeyInner>>, + + // initialization routine to invoke to create a value + #[doc(hidden)] + #[unstable(feature = "thread_local_internals")] + pub init: fn() -> T, +} + +/// Declare a new thread local storage key of type `std::thread::LocalKey`. +#[macro_export] +#[stable(feature = "rust1", since = "1.0.0")] +#[allow_internal_unstable] +macro_rules! thread_local { + (static $name:ident: $t:ty = $init:expr) => ( + static $name: ::std::thread::LocalKey<$t> = { + use std::cell::UnsafeCell as __UnsafeCell; + use std::thread::__local::__impl::KeyInner as __KeyInner; + use std::option::Option as __Option; + use std::option::Option::None as __None; + + __thread_local_inner!(static __KEY: __UnsafeCell<__Option<$t>> = { + __UnsafeCell { value: __None } + }); + fn __init() -> $t { $init } + fn __getit() -> &'static __KeyInner<__UnsafeCell<__Option<$t>>> { + &__KEY + } + ::std::thread::LocalKey { inner: __getit, init: __init } + }; + ); + (pub static $name:ident: $t:ty = $init:expr) => ( + pub static $name: ::std::thread::LocalKey<$t> = { + use std::cell::UnsafeCell as __UnsafeCell; + use std::thread::__local::__impl::KeyInner as __KeyInner; + use std::option::Option as __Option; + use std::option::Option::None as __None; + + __thread_local_inner!(static __KEY: __UnsafeCell<__Option<$t>> = { + __UnsafeCell { value: __None } + }); + fn __init() -> $t { $init } + fn __getit() -> &'static __KeyInner<__UnsafeCell<__Option<$t>>> { + &__KEY + } + ::std::thread::LocalKey { inner: __getit, init: __init } + }; + ); +} + +// Macro pain #4586: +// +// When cross compiling, rustc will load plugins and macros from the *host* +// platform before search for macros from the target platform. This is primarily +// done to detect, for example, plugins. Ideally the macro below would be +// defined once per module below, but unfortunately this means we have the +// following situation: +// +// 1. We compile libstd for x86_64-unknown-linux-gnu, this thread_local!() macro +// will inject #[thread_local] statics. +// 2. We then try to compile a program for arm-linux-androideabi +// 3. The compiler has a host of linux and a target of android, so it loads +// macros from the *linux* libstd. +// 4. The macro generates a #[thread_local] field, but the android libstd does +// not use #[thread_local] +// 5. Compile error about structs with wrong fields. +// +// To get around this, we're forced to inject the #[cfg] logic into the macro +// itself. Woohoo. + +#[macro_export] +#[doc(hidden)] +#[allow_internal_unstable] +macro_rules! __thread_local_inner { + (static $name:ident: $t:ty = $init:expr) => ( + #[cfg_attr(all(any(target_os = "macos", target_os = "linux"), + not(target_arch = "aarch64")), + thread_local)] + static $name: ::std::thread::__local::__impl::KeyInner<$t> = + __thread_local_inner!($init, $t); + ); + (pub static $name:ident: $t:ty = $init:expr) => ( + #[cfg_attr(all(any(target_os = "macos", target_os = "linux"), + not(target_arch = "aarch64")), + thread_local)] + pub static $name: ::std::thread::__local::__impl::KeyInner<$t> = + __thread_local_inner!($init, $t); + ); + ($init:expr, $t:ty) => ({ + #[cfg(all(any(target_os = "macos", target_os = "linux"), not(target_arch = "aarch64")))] + const _INIT: ::std::thread::__local::__impl::KeyInner<$t> = { + ::std::thread::__local::__impl::KeyInner { + inner: ::std::cell::UnsafeCell { value: $init }, + dtor_registered: ::std::cell::UnsafeCell { value: false }, + dtor_running: ::std::cell::UnsafeCell { value: false }, + } + }; + + #[cfg(any(not(any(target_os = "macos", target_os = "linux")), target_arch = "aarch64"))] + const _INIT: ::std::thread::__local::__impl::KeyInner<$t> = { + unsafe extern fn __destroy(ptr: *mut u8) { + ::std::thread::__local::__impl::destroy_value::<$t>(ptr); + } + + ::std::thread::__local::__impl::KeyInner { + inner: ::std::cell::UnsafeCell { value: $init }, + os: ::std::thread::__local::__impl::OsStaticKey { + inner: ::std::thread::__local::__impl::OS_INIT_INNER, + dtor: ::std::option::Option::Some(__destroy as unsafe extern fn(*mut u8)), + }, + } + }; + + _INIT + }); +} + +/// Indicator of the state of a thread local storage key. +#[unstable(feature = "std_misc", + reason = "state querying was recently added")] +#[derive(Eq, PartialEq, Copy)] +pub enum LocalKeyState { + /// All keys are in this state whenever a thread starts. Keys will + /// transition to the `Valid` state once the first call to `with` happens + /// and the initialization expression succeeds. + /// + /// Keys in the `Uninitialized` state will yield a reference to the closure + /// passed to `with` so long as the initialization routine does not panic. + Uninitialized, + + /// Once a key has been accessed successfully, it will enter the `Valid` + /// state. Keys in the `Valid` state will remain so until the thread exits, + /// at which point the destructor will be run and the key will enter the + /// `Destroyed` state. + /// + /// Keys in the `Valid` state will be guaranteed to yield a reference to the + /// closure passed to `with`. + Valid, + + /// When a thread exits, the destructors for keys will be run (if + /// necessary). While a destructor is running, and possibly after a + /// destructor has run, a key is in the `Destroyed` state. + /// + /// Keys in the `Destroyed` states will trigger a panic when accessed via + /// `with`. + Destroyed, +} + +impl LocalKey { + /// Acquire a reference to the value in this TLS key. + /// + /// This will lazily initialize the value if this thread has not referenced + /// this key yet. + /// + /// # Panics + /// + /// This function will `panic!()` if the key currently has its + /// destructor running, and it **may** panic if the destructor has + /// previously been run for this thread. + #[stable(feature = "rust1", since = "1.0.0")] + pub fn with(&'static self, f: F) -> R + where F: FnOnce(&T) -> R { + let slot = (self.inner)(); + unsafe { + let slot = slot.get().expect("cannot access a TLS value during or \ + after it is destroyed"); + f(match *slot.get() { + Some(ref inner) => inner, + None => self.init(slot), + }) + } + } + + unsafe fn init(&self, slot: &UnsafeCell>) -> &T { + // Execute the initialization up front, *then* move it into our slot, + // just in case initialization fails. + let value = (self.init)(); + let ptr = slot.get(); + *ptr = Some(value); + (*ptr).as_ref().unwrap() + } + + /// Query the current state of this key. + /// + /// A key is initially in the `Uninitialized` state whenever a thread + /// starts. It will remain in this state up until the first call to `with` + /// within a thread has run the initialization expression successfully. + /// + /// Once the initialization expression succeeds, the key transitions to the + /// `Valid` state which will guarantee that future calls to `with` will + /// succeed within the thread. + /// + /// When a thread exits, each key will be destroyed in turn, and as keys are + /// destroyed they will enter the `Destroyed` state just before the + /// destructor starts to run. Keys may remain in the `Destroyed` state after + /// destruction has completed. Keys without destructors (e.g. with types + /// that are `Copy`), may never enter the `Destroyed` state. + /// + /// Keys in the `Uninitialized` can be accessed so long as the + /// initialization does not panic. Keys in the `Valid` state are guaranteed + /// to be able to be accessed. Keys in the `Destroyed` state will panic on + /// any call to `with`. + #[unstable(feature = "std_misc", + reason = "state querying was recently added")] + pub fn state(&'static self) -> LocalKeyState { + unsafe { + match (self.inner)().get() { + Some(cell) => { + match *cell.get() { + Some(..) => LocalKeyState::Valid, + None => LocalKeyState::Uninitialized, + } + } + None => LocalKeyState::Destroyed, + } + } + } + + /// Deprecated + #[unstable(feature = "std_misc")] + #[deprecated(since = "1.0.0", + reason = "function renamed to state() and returns more info")] + pub fn destroyed(&'static self) -> bool { self.state() == LocalKeyState::Destroyed } +} + +#[cfg(all(any(target_os = "macos", target_os = "linux"), not(target_arch = "aarch64")))] +mod imp { + use prelude::v1::*; + + use cell::UnsafeCell; + use intrinsics; + use ptr; + + #[doc(hidden)] + #[unstable(feature = "thread_local_internals")] + pub struct Key { + // Place the inner bits in an `UnsafeCell` to currently get around the + // "only Sync statics" restriction. This allows any type to be placed in + // the cell. + // + // Note that all access requires `T: 'static` so it can't be a type with + // any borrowed pointers still. + #[unstable(feature = "thread_local_internals")] + pub inner: UnsafeCell, + + // Metadata to keep track of the state of the destructor. Remember that + // these variables are thread-local, not global. + #[unstable(feature = "thread_local_internals")] + pub dtor_registered: UnsafeCell, // should be Cell + #[unstable(feature = "thread_local_internals")] + pub dtor_running: UnsafeCell, // should be Cell + } + + unsafe impl ::marker::Sync for Key { } + + #[doc(hidden)] + impl Key { + pub unsafe fn get(&'static self) -> Option<&'static T> { + if intrinsics::needs_drop::() && *self.dtor_running.get() { + return None + } + self.register_dtor(); + Some(&*self.inner.get()) + } + + unsafe fn register_dtor(&self) { + if !intrinsics::needs_drop::() || *self.dtor_registered.get() { + return + } + + register_dtor(self as *const _ as *mut u8, + destroy_value::); + *self.dtor_registered.get() = true; + } + } + + // Since what appears to be glibc 2.18 this symbol has been shipped which + // GCC and clang both use to invoke destructors in thread_local globals, so + // let's do the same! + // + // Note, however, that we run on lots older linuxes, as well as cross + // compiling from a newer linux to an older linux, so we also have a + // fallback implementation to use as well. + // + // Due to rust-lang/rust#18804, make sure this is not generic! + #[cfg(target_os = "linux")] + unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern fn(*mut u8)) { + use boxed; + use mem; + use libc; + use sys_common::thread_local as os; + + extern { + static __dso_handle: *mut u8; + #[linkage = "extern_weak"] + static __cxa_thread_atexit_impl: *const (); + } + if !__cxa_thread_atexit_impl.is_null() { + type F = unsafe extern fn(dtor: unsafe extern fn(*mut u8), + arg: *mut u8, + dso_handle: *mut u8) -> libc::c_int; + mem::transmute::<*const (), F>(__cxa_thread_atexit_impl) + (dtor, t, __dso_handle); + return + } + + // The fallback implementation uses a vanilla OS-based TLS key to track + // the list of destructors that need to be run for this thread. The key + // then has its own destructor which runs all the other destructors. + // + // The destructor for DTORS is a little special in that it has a `while` + // loop to continuously drain the list of registered destructors. It + // *should* be the case that this loop always terminates because we + // provide the guarantee that a TLS key cannot be set after it is + // flagged for destruction. + static DTORS: os::StaticKey = os::StaticKey { + inner: os::INIT_INNER, + dtor: Some(run_dtors as unsafe extern "C" fn(*mut u8)), + }; + type List = Vec<(*mut u8, unsafe extern fn(*mut u8))>; + if DTORS.get().is_null() { + let v: Box = box Vec::new(); + DTORS.set(boxed::into_raw(v) as *mut u8); + } + let list: &mut List = &mut *(DTORS.get() as *mut List); + list.push((t, dtor)); + + unsafe extern fn run_dtors(mut ptr: *mut u8) { + while !ptr.is_null() { + let list: Box = Box::from_raw(ptr as *mut List); + for &(ptr, dtor) in &*list { + dtor(ptr); + } + ptr = DTORS.get(); + DTORS.set(ptr::null_mut()); + } + } + } + + // OSX's analog of the above linux function is this _tlv_atexit function. + // The disassembly of thread_local globals in C++ (at least produced by + // clang) will have this show up in the output. + #[cfg(target_os = "macos")] + unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern fn(*mut u8)) { + extern { + fn _tlv_atexit(dtor: unsafe extern fn(*mut u8), + arg: *mut u8); + } + _tlv_atexit(dtor, t); + } + + #[doc(hidden)] + #[unstable(feature = "thread_local_internals")] + pub unsafe extern fn destroy_value(ptr: *mut u8) { + let ptr = ptr as *mut Key; + // Right before we run the user destructor be sure to flag the + // destructor as running for this thread so calls to `get` will return + // `None`. + *(*ptr).dtor_running.get() = true; + ptr::read((*ptr).inner.get()); + } +} + +#[cfg(any(not(any(target_os = "macos", target_os = "linux")), target_arch = "aarch64"))] +mod imp { + use prelude::v1::*; + + use alloc::boxed; + use cell::UnsafeCell; + use mem; + use ptr; + use sys_common::thread_local::StaticKey as OsStaticKey; + + #[doc(hidden)] + #[unstable(feature = "thread_local_internals")] + pub struct Key { + // Statically allocated initialization expression, using an `UnsafeCell` + // for the same reasons as above. + #[unstable(feature = "thread_local_internals")] + pub inner: UnsafeCell, + + // OS-TLS key that we'll use to key off. + #[unstable(feature = "thread_local_internals")] + pub os: OsStaticKey, + } + + unsafe impl ::marker::Sync for Key { } + + struct Value { + key: &'static Key, + value: T, + } + + #[doc(hidden)] + impl Key { + pub unsafe fn get(&'static self) -> Option<&'static T> { + self.ptr().map(|p| &*p) + } + + unsafe fn ptr(&'static self) -> Option<*mut T> { + let ptr = self.os.get() as *mut Value; + if !ptr.is_null() { + if ptr as usize == 1 { + return None + } + return Some(&mut (*ptr).value as *mut T); + } + + // If the lookup returned null, we haven't initialized our own local + // copy, so do that now. + // + // Also note that this transmute_copy should be ok because the value + // `inner` is already validated to be a valid `static` value, so we + // should be able to freely copy the bits. + let ptr: Box> = box Value { + key: self, + value: mem::transmute_copy(&self.inner), + }; + let ptr: *mut Value = boxed::into_raw(ptr); + self.os.set(ptr as *mut u8); + Some(&mut (*ptr).value as *mut T) + } + } + + #[doc(hidden)] + #[unstable(feature = "thread_local_internals")] + pub unsafe extern fn destroy_value(ptr: *mut u8) { + // The OS TLS ensures that this key contains a NULL value when this + // destructor starts to run. We set it back to a sentinel value of 1 to + // ensure that any future calls to `get` for this thread will return + // `None`. + // + // Note that to prevent an infinite loop we reset it back to null right + // before we return from the destructor ourselves. + let ptr: Box> = Box::from_raw(ptr as *mut Value); + let key = ptr.key; + key.os.set(1 as *mut u8); + drop(ptr); + key.os.set(ptr::null_mut()); + } +} + +#[cfg(test)] +mod tests { + use prelude::v1::*; + + use sync::mpsc::{channel, Sender}; + use cell::UnsafeCell; + use super::LocalKeyState; + use thread; + + struct Foo(Sender<()>); + + impl Drop for Foo { + fn drop(&mut self) { + let Foo(ref s) = *self; + s.send(()).unwrap(); + } + } + + #[test] + fn smoke_no_dtor() { + thread_local!(static FOO: UnsafeCell = UnsafeCell { value: 1 }); + + FOO.with(|f| unsafe { + assert_eq!(*f.get(), 1); + *f.get() = 2; + }); + let (tx, rx) = channel(); + let _t = thread::spawn(move|| { + FOO.with(|f| unsafe { + assert_eq!(*f.get(), 1); + }); + tx.send(()).unwrap(); + }); + rx.recv().unwrap(); + + FOO.with(|f| unsafe { + assert_eq!(*f.get(), 2); + }); + } + + #[test] + fn states() { + struct Foo; + impl Drop for Foo { + fn drop(&mut self) { + assert!(FOO.state() == LocalKeyState::Destroyed); + } + } + fn foo() -> Foo { + assert!(FOO.state() == LocalKeyState::Uninitialized); + Foo + } + thread_local!(static FOO: Foo = foo()); + + thread::spawn(|| { + assert!(FOO.state() == LocalKeyState::Uninitialized); + FOO.with(|_| { + assert!(FOO.state() == LocalKeyState::Valid); + }); + assert!(FOO.state() == LocalKeyState::Valid); + }).join().ok().unwrap(); + } + + #[test] + fn smoke_dtor() { + thread_local!(static FOO: UnsafeCell> = UnsafeCell { + value: None + }); + + let (tx, rx) = channel(); + let _t = thread::spawn(move|| unsafe { + let mut tx = Some(tx); + FOO.with(|f| { + *f.get() = Some(Foo(tx.take().unwrap())); + }); + }); + rx.recv().unwrap(); + } + + #[test] + fn circular() { + struct S1; + struct S2; + thread_local!(static K1: UnsafeCell> = UnsafeCell { + value: None + }); + thread_local!(static K2: UnsafeCell> = UnsafeCell { + value: None + }); + static mut HITS: u32 = 0; + + impl Drop for S1 { + fn drop(&mut self) { + unsafe { + HITS += 1; + if K2.state() == LocalKeyState::Destroyed { + assert_eq!(HITS, 3); + } else { + if HITS == 1 { + K2.with(|s| *s.get() = Some(S2)); + } else { + assert_eq!(HITS, 3); + } + } + } + } + } + impl Drop for S2 { + fn drop(&mut self) { + unsafe { + HITS += 1; + assert!(K1.state() != LocalKeyState::Destroyed); + assert_eq!(HITS, 2); + K1.with(|s| *s.get() = Some(S1)); + } + } + } + + thread::spawn(move|| { + drop(S1); + }).join().ok().unwrap(); + } + + #[test] + fn self_referential() { + struct S1; + thread_local!(static K1: UnsafeCell> = UnsafeCell { + value: None + }); + + impl Drop for S1 { + fn drop(&mut self) { + assert!(K1.state() == LocalKeyState::Destroyed); + } + } + + thread::spawn(move|| unsafe { + K1.with(|s| *s.get() = Some(S1)); + }).join().ok().unwrap(); + } + + #[test] + fn dtors_in_dtors_in_dtors() { + struct S1(Sender<()>); + thread_local!(static K1: UnsafeCell> = UnsafeCell { + value: None + }); + thread_local!(static K2: UnsafeCell> = UnsafeCell { + value: None + }); + + impl Drop for S1 { + fn drop(&mut self) { + let S1(ref tx) = *self; + unsafe { + if K2.state() != LocalKeyState::Destroyed { + K2.with(|s| *s.get() = Some(Foo(tx.clone()))); + } + } + } + } + + let (tx, rx) = channel(); + let _t = thread::spawn(move|| unsafe { + let mut tx = Some(tx); + K1.with(|s| *s.get() = Some(S1(tx.take().unwrap()))); + }); + rx.recv().unwrap(); + } +} + +#[cfg(test)] +mod dynamic_tests { + use prelude::v1::*; + + use cell::RefCell; + use collections::HashMap; + + #[test] + fn smoke() { + fn square(i: i32) -> i32 { i * i } + thread_local!(static FOO: i32 = square(3)); + + FOO.with(|f| { + assert_eq!(*f, 9); + }); + } + + #[test] + fn hashmap() { + fn map() -> RefCell> { + let mut m = HashMap::new(); + m.insert(1, 2); + RefCell::new(m) + } + thread_local!(static FOO: RefCell> = map()); + + FOO.with(|map| { + assert_eq!(map.borrow()[1], 2); + }); + } + + #[test] + fn refcell_vec() { + thread_local!(static FOO: RefCell> = RefCell::new(vec![1, 2, 3])); + + FOO.with(|vec| { + assert_eq!(vec.borrow().len(), 3); + vec.borrow_mut().push(4); + assert_eq!(vec.borrow()[3], 4); + }); + } +} diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs new file mode 100644 index 00000000000..57baeb1fb74 --- /dev/null +++ b/src/libstd/thread/mod.rs @@ -0,0 +1,1026 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Native threads +//! +//! ## The threading model +//! +//! An executing Rust program consists of a collection of native OS threads, +//! each with their own stack and local state. +//! +//! Communication between threads can be done through +//! [channels](../../std/sync/mpsc/index.html), Rust's message-passing +//! types, along with [other forms of thread +//! synchronization](../../std/sync/index.html) and shared-memory data +//! structures. In particular, types that are guaranteed to be +//! threadsafe are easily shared between threads using the +//! atomically-reference-counted container, +//! [`Arc`](../../std/sync/struct.Arc.html). +//! +//! Fatal logic errors in Rust cause *thread panic*, during which +//! a thread will unwind the stack, running destructors and freeing +//! owned resources. Thread panic is unrecoverable from within +//! the panicking thread (i.e. there is no 'try/catch' in Rust), but +//! the panic may optionally be detected from a different thread. If +//! the main thread panics, the application will exit with a non-zero +//! exit code. +//! +//! When the main thread of a Rust program terminates, the entire program shuts +//! down, even if other threads are still running. However, this module provides +//! convenient facilities for automatically waiting for the termination of a +//! child thread (i.e., join). +//! +//! ## The `Thread` type +//! +//! Threads are represented via the `Thread` type, which you can +//! get in one of two ways: +//! +//! * By spawning a new thread, e.g. using the `thread::spawn` function. +//! * By requesting the current thread, using the `thread::current` function. +//! +//! Threads can be named, and provide some built-in support for low-level +//! synchronization (described below). +//! +//! The `thread::current()` function is available even for threads not spawned +//! by the APIs of this module. +//! +//! ## Spawning a thread +//! +//! A new thread can be spawned using the `thread::spawn` function: +//! +//! ```rust +//! use std::thread; +//! +//! thread::spawn(move || { +//! // some work here +//! }); +//! ``` +//! +//! In this example, the spawned thread is "detached" from the current +//! thread. This means that it can outlive its parent (the thread that spawned +//! it), unless this parent is the main thread. +//! +//! ## Scoped threads +//! +//! Often a parent thread uses a child thread to perform some particular task, +//! and at some point must wait for the child to complete before continuing. +//! For this scenario, use the `thread::scoped` function: +//! +//! ```rust +//! 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 is an RAII-style guard +//! that will automatically join the child thread (block until it +//! terminates) when it is dropped. You can join the child thread in +//! advance by calling the `join` method on the guard, which will also +//! return the result produced by the thread. A handle to the thread +//! itself is available via the `thread` method of the join guard. +//! +//! ## Configuring threads +//! +//! A new thread can be configured before it is spawned via the `Builder` type, +//! which currently allows you to set the name, stack size, and writers for +//! `println!` and `panic!` for the child thread: +//! +//! ```rust +//! use std::thread; +//! +//! thread::Builder::new().name("child1".to_string()).spawn(move || { +//! println!("Hello, world!"); +//! }); +//! ``` +//! +//! ## Blocking support: park and unpark +//! +//! Every thread is equipped with some basic low-level blocking support, via the +//! `park` and `unpark` functions. +//! +//! Conceptually, each `Thread` handle has an associated token, which is +//! initially not present: +//! +//! * The `thread::park()` function blocks the current thread unless or until +//! the token is available for its thread handle, at which point it atomically +//! consumes the token. It may also return *spuriously*, without consuming the +//! token. `thread::park_timeout()` does the same, but allows specifying a +//! maximum time to block the thread for. +//! +//! * The `unpark()` method on a `Thread` atomically makes the token available +//! if it wasn't already. +//! +//! In other words, each `Thread` acts a bit like a semaphore with initial count +//! 0, except that the semaphore is *saturating* (the count cannot go above 1), +//! and can return spuriously. +//! +//! The API is typically used by acquiring a handle to the current thread, +//! placing that handle in a shared data structure so that other threads can +//! find it, and then `park`ing. When some desired condition is met, another +//! thread calls `unpark` on the handle. +//! +//! The motivation for this design is twofold: +//! +//! * It avoids the need to allocate mutexes and condvars when building new +//! synchronization primitives; the threads already provide basic blocking/signaling. +//! +//! * It can be implemented very efficiently on many platforms. +//! +//! ## Thread-local storage +//! +//! This module also provides an implementation of thread local storage for Rust +//! programs. Thread local storage is a method of storing data into a global +//! variable which each thread in the program will have its own copy of. +//! Threads do not share this data, so accesses do not need to be synchronized. +//! +//! At a high level, this module provides two variants of storage: +//! +//! * Owned thread-local storage. This is a type of thread local key which +//! owns the value that it contains, and will destroy the value when the +//! thread exits. This variant is created with the `thread_local!` macro and +//! can contain any value which is `'static` (no borrowed pointers). +//! +//! * Scoped thread-local storage. This type of key is used to store a reference +//! to a value into local storage temporarily for the scope of a function +//! call. There are no restrictions on what types of values can be placed +//! into this key. +//! +//! Both forms of thread local storage provide an accessor function, `with`, +//! which will yield a shared reference to the value to the specified +//! closure. Thread-local keys only allow shared access to values as there is no +//! way to guarantee uniqueness if a mutable borrow was allowed. Most values +//! will want to make use of some form of **interior mutability** through the +//! `Cell` or `RefCell` types. + +#![stable(feature = "rust1", since = "1.0.0")] + +#[stable(feature = "rust1", since = "1.0.0")] +pub use self::__local::{LocalKey, LocalKeyState}; + +#[unstable(feature = "scoped_tls", + reason = "scoped TLS has yet to have wide enough use to fully consider \ + stabilizing its interface")] +pub use self::__scoped::ScopedKey; + +use prelude::v1::*; + +use any::Any; +use cell::UnsafeCell; +use fmt; +use io; +use marker::PhantomData; +use rt::{self, unwind}; +use sync::{Mutex, Condvar, Arc}; +use sys::thread as imp; +use sys_common::{stack, thread_info}; +use thunk::Thunk; +use time::Duration; + +#[allow(deprecated)] use old_io::Writer; + +//////////////////////////////////////////////////////////////////////////////// +// Thread-local storage +//////////////////////////////////////////////////////////////////////////////// + +#[macro_use] +#[doc(hidden)] +#[path = "local.rs"] pub mod __local; + +#[macro_use] +#[doc(hidden)] +#[path = "scoped.rs"] pub mod __scoped; + +//////////////////////////////////////////////////////////////////////////////// +// Builder +//////////////////////////////////////////////////////////////////////////////// + +/// Thread configuration. Provides detailed control over the properties +/// and behavior of new threads. +#[stable(feature = "rust1", since = "1.0.0")] +pub struct Builder { + // A name for the thread-to-be, for identification in panic messages + name: Option, + // The size of the stack for the spawned thread + stack_size: Option, +} + +impl Builder { + /// Generate the base configuration for spawning a thread, from which + /// configuration methods can be chained. + #[stable(feature = "rust1", since = "1.0.0")] + pub fn new() -> Builder { + Builder { + name: None, + stack_size: None, + } + } + + /// Name the thread-to-be. Currently the name is used for identification + /// only in panic messages. + #[stable(feature = "rust1", since = "1.0.0")] + pub fn name(mut self, name: String) -> Builder { + self.name = Some(name); + self + } + + /// Set the size of the stack for the new thread. + #[stable(feature = "rust1", since = "1.0.0")] + pub fn stack_size(mut self, size: usize) -> Builder { + self.stack_size = Some(size); + self + } + + /// Redirect thread-local stdout. + #[unstable(feature = "std_misc", + reason = "Will likely go away after proc removal")] + #[deprecated(since = "1.0.0", + reason = "the old I/O module is deprecated and this function \ + will be removed with no replacement")] + #[allow(deprecated)] + pub fn stdout(self, _stdout: Box) -> Builder { + self + } + + /// Redirect thread-local stderr. + #[unstable(feature = "std_misc", + reason = "Will likely go away after proc removal")] + #[deprecated(since = "1.0.0", + reason = "the old I/O module is deprecated and this function \ + will be removed with no replacement")] + #[allow(deprecated)] + pub fn stderr(self, _stderr: Box) -> Builder { + self + } + + /// Spawn a new thread, and return a join handle for it. + /// + /// The child thread may outlive the parent (unless the parent thread + /// is the main thread; the whole process is terminated when the main + /// thread finishes.) The join handle can be used to block on + /// termination of the child thread, including recovering its panics. + /// + /// # Errors + /// + /// Unlike the `spawn` free function, this method yields an + /// `io::Result` to capture any failure to create the thread at + /// the OS level. + #[stable(feature = "rust1", since = "1.0.0")] + pub fn spawn(self, f: F) -> io::Result where + F: FnOnce(), F: Send + 'static + { + self.spawn_inner(Thunk::new(f)).map(|i| JoinHandle(i)) + } + + /// Spawn a new child thread that must be joined within a given + /// scope, and return a `JoinGuard`. + /// + /// The join guard can be used to explicitly join the child thread (via + /// `join`), returning `Result`, 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 + /// module documentation 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. + #[stable(feature = "rust1", since = "1.0.0")] + pub fn scoped<'a, T, F>(self, f: F) -> io::Result> where + T: Send + 'a, F: FnOnce() -> T, F: Send + 'a + { + self.spawn_inner(Thunk::new(f)).map(|inner| { + JoinGuard { inner: inner, _marker: PhantomData } + }) + } + + fn spawn_inner(self, f: Thunk<(), T>) -> io::Result> { + let Builder { name, stack_size } = self; + + let stack_size = stack_size.unwrap_or(rt::min_stack()); + + let my_thread = Thread::new(name); + let their_thread = my_thread.clone(); + + let my_packet = Packet(Arc::new(UnsafeCell::new(None))); + let their_packet = Packet(my_packet.0.clone()); + + // Spawning a new OS thread guarantees that __morestack will never get + // triggered, but we must manually set up the actual stack bounds once + // this function starts executing. This raises the lower limit by a bit + // because by the time that this function is executing we've already + // consumed at least a little bit of stack (we don't know the exact byte + // address at which our stack started). + let main = move || { + let something_around_the_top_of_the_stack = 1; + let addr = &something_around_the_top_of_the_stack as *const i32; + let my_stack_top = addr as usize; + let my_stack_bottom = my_stack_top - stack_size + 1024; + unsafe { + if let Some(name) = their_thread.name() { + imp::set_name(name); + } + stack::record_os_managed_stack_bounds(my_stack_bottom, + my_stack_top); + thread_info::set(imp::guard::current(), their_thread); + } + + let mut output = None; + let try_result = { + let ptr = &mut output; + + // There are two primary reasons that general try/catch is + // unsafe. The first is that we do not support nested + // try/catch. The fact that this is happening in a newly-spawned + // thread suffices. The second is that unwinding while unwinding + // is not defined. We take care of that by having an + // 'unwinding' flag in the thread itself. For these reasons, + // this unsafety should be ok. + unsafe { + unwind::try(move || *ptr = Some(f.invoke(()))) + } + }; + unsafe { + *their_packet.0.get() = Some(match (output, try_result) { + (Some(data), Ok(_)) => Ok(data), + (None, Err(cause)) => Err(cause), + _ => unreachable!() + }); + } + }; + + Ok(JoinInner { + native: try!(unsafe { imp::create(stack_size, Thunk::new(main)) }), + thread: my_thread, + packet: my_packet, + joined: false, + }) + } +} + +//////////////////////////////////////////////////////////////////////////////// +// Free functions +//////////////////////////////////////////////////////////////////////////////// + +/// Spawn a new thread, returning a `JoinHandle` for it. +/// +/// The join handle will implicitly *detach* the child thread upon being +/// dropped. In this case, the child thread may outlive the parent (unless +/// the parent thread is the main thread; the whole process is terminated when +/// the main thread finishes.) Additionally, the join handle provides a `join` +/// method that can be used to join the child thread. If the child thread +/// panics, `join` will return an `Err` containing the argument given to +/// `panic`. +/// +/// # Panics +/// +/// Panicks if the OS fails to create a thread; use `Builder::spawn` +/// to recover from such errors. +#[stable(feature = "rust1", since = "1.0.0")] +pub fn spawn(f: F) -> JoinHandle where F: FnOnce(), F: Send + 'static { + Builder::new().spawn(f).unwrap() +} + +/// Spawn a new *scoped* thread, returning a `JoinGuard` for it. +/// +/// The join guard can be used to explicitly join the child thread (via +/// `join`), returning `Result`, 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 +/// module documentation for additional details. +/// +/// # Panics +/// +/// Panicks if the OS fails to create a thread; use `Builder::scoped` +/// to recover from such errors. +#[stable(feature = "rust1", since = "1.0.0")] +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 { + thread_info::current_thread() +} + +/// Cooperatively give up a timeslice to the OS scheduler. +#[stable(feature = "rust1", since = "1.0.0")] +pub fn yield_now() { + unsafe { imp::yield_now() } +} + +/// Determines whether the current thread is unwinding because of panic. +#[inline] +#[stable(feature = "rust1", since = "1.0.0")] +pub fn panicking() -> bool { + unwind::panicking() +} + +/// Put the current thread to sleep for the specified amount of time. +/// +/// The thread may sleep longer than the duration specified due to scheduling +/// specifics or platform-dependent functionality. Note that on unix platforms +/// this function will not return early due to a signal being received or a +/// spurious wakeup. +#[unstable(feature = "thread_sleep", + reason = "recently added, needs an RFC, and `Duration` itself is \ + unstable")] +pub fn sleep(dur: Duration) { + imp::sleep(dur) +} + +/// Block unless or until the current thread's token is made available (may wake spuriously). +/// +/// See the module doc for more detail. +// +// The implementation currently uses the trivial strategy of a Mutex+Condvar +// with wakeup flag, which does not actually allow spurious wakeups. In the +// future, this will be implemented in a more efficient way, perhaps along the lines of +// http://cr.openjdk.java.net/~stefank/6989984.1/raw_files/new/src/os/linux/vm/os_linux.cpp +// or futuxes, and in either case may allow spurious wakeups. +#[stable(feature = "rust1", since = "1.0.0")] +pub fn park() { + let thread = current(); + let mut guard = thread.inner.lock.lock().unwrap(); + while !*guard { + guard = thread.inner.cvar.wait(guard).unwrap(); + } + *guard = false; +} + +/// Block unless or until the current thread's token is made available or +/// the specified duration has been reached (may wake spuriously). +/// +/// The semantics of this function are equivalent to `park()` except that the +/// thread will be blocked for roughly no longer than *duration*. This method +/// should not be used for precise timing due to anomalies such as +/// preemption or platform differences that may not cause the maximum +/// amount of time waited to be precisely *duration* long. +/// +/// See the module doc for more detail. +#[unstable(feature = "std_misc", reason = "recently introduced, depends on Duration")] +pub fn park_timeout(duration: Duration) { + let thread = current(); + let mut guard = thread.inner.lock.lock().unwrap(); + if !*guard { + let (g, _) = thread.inner.cvar.wait_timeout(guard, duration).unwrap(); + guard = g; + } + *guard = false; +} + +//////////////////////////////////////////////////////////////////////////////// +// Thread +//////////////////////////////////////////////////////////////////////////////// + +/// The internal representation of a `Thread` handle +struct Inner { + name: Option, + lock: Mutex, // true when there is a buffered unpark + cvar: Condvar, +} + +unsafe impl Sync for Inner {} + +#[derive(Clone)] +#[stable(feature = "rust1", since = "1.0.0")] +/// A handle to a thread. +pub struct Thread { + inner: Arc, +} + +impl Thread { + // Used only internally to construct a thread object without spawning + fn new(name: Option) -> Thread { + Thread { + inner: Arc::new(Inner { + name: name, + lock: Mutex::new(false), + cvar: Condvar::new(), + }) + } + } + + /// Deprecated: use module-level free function. + #[deprecated(since = "1.0.0", reason = "use module-level free function")] + #[unstable(feature = "std_misc", + reason = "may change with specifics of new Send semantics")] + pub fn spawn(f: F) -> Thread where F: FnOnce(), F: Send + 'static { + Builder::new().spawn(f).unwrap().thread().clone() + } + + /// Deprecated: use module-level free function. + #[deprecated(since = "1.0.0", reason = "use module-level free function")] + #[unstable(feature = "std_misc", + reason = "may change with specifics of new Send semantics")] + 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() + } + + /// Deprecated: use module-level free function. + #[deprecated(since = "1.0.0", reason = "use module-level free function")] + #[stable(feature = "rust1", since = "1.0.0")] + pub fn current() -> Thread { + thread_info::current_thread() + } + + /// Deprecated: use module-level free function. + #[deprecated(since = "1.0.0", reason = "use module-level free function")] + #[unstable(feature = "std_misc", reason = "name may change")] + pub fn yield_now() { + unsafe { imp::yield_now() } + } + + /// Deprecated: use module-level free function. + #[deprecated(since = "1.0.0", reason = "use module-level free function")] + #[inline] + #[stable(feature = "rust1", since = "1.0.0")] + pub fn panicking() -> bool { + unwind::panicking() + } + + /// Deprecated: use module-level free function. + #[deprecated(since = "1.0.0", reason = "use module-level free function")] + #[unstable(feature = "std_misc", reason = "recently introduced")] + pub fn park() { + let thread = current(); + let mut guard = thread.inner.lock.lock().unwrap(); + while !*guard { + guard = thread.inner.cvar.wait(guard).unwrap(); + } + *guard = false; + } + + /// Deprecated: use module-level free function. + #[deprecated(since = "1.0.0", reason = "use module-level free function")] + #[unstable(feature = "std_misc", reason = "recently introduced")] + pub fn park_timeout(duration: Duration) { + let thread = current(); + let mut guard = thread.inner.lock.lock().unwrap(); + if !*guard { + let (g, _) = thread.inner.cvar.wait_timeout(guard, duration).unwrap(); + guard = g; + } + *guard = false; + } + + /// Atomically makes the handle's token available if it is not already. + /// + /// See the module doc for more detail. + #[stable(feature = "rust1", since = "1.0.0")] + pub fn unpark(&self) { + let mut guard = self.inner.lock.lock().unwrap(); + if !*guard { + *guard = true; + self.inner.cvar.notify_one(); + } + } + + /// Get the thread's name. + #[stable(feature = "rust1", since = "1.0.0")] + pub fn name(&self) -> Option<&str> { + self.inner.name.as_ref().map(|s| &**s) + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl fmt::Debug for Thread { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.name(), f) + } +} + +// a hack to get around privacy restrictions +impl thread_info::NewThread for Thread { + fn new(name: Option) -> Thread { Thread::new(name) } +} + +//////////////////////////////////////////////////////////////////////////////// +// JoinHandle and JoinGuard +//////////////////////////////////////////////////////////////////////////////// + +/// Indicates the manner in which a thread exited. +/// +/// A thread that completes without panicking is considered to exit successfully. +#[stable(feature = "rust1", since = "1.0.0")] +pub type Result = ::result::Result>; + +struct Packet(Arc>>>); + +unsafe impl Send for Packet {} +unsafe impl Sync for Packet {} + +/// Inner representation for JoinHandle and JoinGuard +struct JoinInner { + native: imp::rust_thread, + thread: Thread, + packet: Packet, + joined: bool, +} + +impl JoinInner { + fn join(&mut self) -> Result { + assert!(!self.joined); + unsafe { imp::join(self.native) }; + self.joined = true; + unsafe { + (*self.packet.0.get()).take().unwrap() + } + } +} + +/// An owned permission to join on a thread (block on its termination). +/// +/// Unlike a `JoinGuard`, a `JoinHandle` *detaches* the child thread +/// when it is dropped, rather than automatically joining on drop. +/// +/// Due to platform restrictions, it is not possible to `Clone` this +/// handle: the ability to join a child thread is a uniquely-owned +/// permission. +#[stable(feature = "rust1", since = "1.0.0")] +pub struct JoinHandle(JoinInner<()>); + +impl JoinHandle { + /// Extract a handle to the underlying thread + #[stable(feature = "rust1", since = "1.0.0")] + pub fn thread(&self) -> &Thread { + &self.0.thread + } + + /// Wait for the associated thread to finish. + /// + /// If the child thread panics, `Err` is returned with the parameter given + /// to `panic`. + #[stable(feature = "rust1", since = "1.0.0")] + pub fn join(mut self) -> Result<()> { + self.0.join() + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl Drop for JoinHandle { + fn drop(&mut self) { + if !self.0.joined { + unsafe { imp::detach(self.0.native) } + } + } +} + +/// An RAII-style guard that will block until thread termination when dropped. +/// +/// The type `T` is the return type for the thread's main function. +/// +/// Joining on drop is necessary to ensure memory safety when stack +/// data is shared between a parent and child thread. +/// +/// Due to platform restrictions, it is not possible to `Clone` this +/// handle: the ability to join a child thread is a uniquely-owned +/// permission. +#[must_use = "thread will be immediately joined if `JoinGuard` is not used"] +#[stable(feature = "rust1", since = "1.0.0")] +pub struct JoinGuard<'a, T: 'a> { + inner: JoinInner, + _marker: PhantomData<&'a T>, +} + +#[stable(feature = "rust1", since = "1.0.0")] +unsafe impl<'a, T: Send + 'a> Sync for JoinGuard<'a, T> {} + +impl<'a, T: Send + 'a> JoinGuard<'a, T> { + /// Extract a handle to the thread this guard will join on. + #[stable(feature = "rust1", since = "1.0.0")] + pub fn thread(&self) -> &Thread { + &self.inner.thread + } + + /// Wait for the associated thread to finish, returning the result of the thread's + /// calculation. + /// + /// # Panics + /// + /// Panics on the child thread are propagated by panicking the parent. + #[stable(feature = "rust1", since = "1.0.0")] + pub fn join(mut self) -> T { + match self.inner.join() { + Ok(res) => res, + Err(_) => panic!("child thread {:?} panicked", self.thread()), + } + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl JoinGuard<'static, T> { + /// Detaches the child thread, allowing it to outlive its parent. + #[deprecated(since = "1.0.0", reason = "use spawn instead")] + #[unstable(feature = "std_misc")] + pub fn detach(mut self) { + unsafe { imp::detach(self.inner.native) }; + self.inner.joined = true; // avoid joining in the destructor + } +} + +#[unsafe_destructor] +#[stable(feature = "rust1", since = "1.0.0")] +impl<'a, T: Send + 'a> Drop for JoinGuard<'a, T> { + fn drop(&mut self) { + if !self.inner.joined { + if self.inner.join().is_err() { + panic!("child thread {:?} panicked", self.thread()); + } + } + } +} + +//////////////////////////////////////////////////////////////////////////////// +// Tests +//////////////////////////////////////////////////////////////////////////////// + +#[cfg(test)] +mod test { + use prelude::v1::*; + + use any::Any; + use sync::mpsc::{channel, Sender}; + use boxed::BoxAny; + use result; + use std::old_io::{ChanReader, ChanWriter}; + use super::{Builder}; + use thread; + use thunk::Thunk; + use time::Duration; + + // !!! These tests are dangerous. If something is buggy, they will hang, !!! + // !!! instead of exiting cleanly. This might wedge the buildbots. !!! + + #[test] + fn test_unnamed_thread() { + thread::spawn(move|| { + assert!(thread::current().name().is_none()); + }).join().ok().unwrap(); + } + + #[test] + fn test_named_thread() { + Builder::new().name("ada lovelace".to_string()).scoped(move|| { + assert!(thread::current().name().unwrap() == "ada lovelace".to_string()); + }).unwrap().join(); + } + + #[test] + fn test_run_basic() { + let (tx, rx) = channel(); + thread::spawn(move|| { + tx.send(()).unwrap(); + }); + rx.recv().unwrap(); + } + + #[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!() + }).join() { + result::Result::Err(_) => (), + result::Result::Ok(()) => panic!() + } + } + + #[test] + fn test_scoped_success() { + let res = thread::scoped(move|| -> String { + "Success!".to_string() + }).join(); + assert!(res == "Success!"); + } + + #[test] + #[should_fail] + fn test_scoped_panic() { + thread::scoped(|| panic!()).join(); + } + + #[test] + #[should_fail] + fn test_scoped_implicit_panic() { + let _ = thread::scoped(|| panic!()); + } + + #[test] + fn test_spawn_sched() { + use clone::Clone; + + let (tx, rx) = channel(); + + fn f(i: i32, tx: Sender<()>) { + let tx = tx.clone(); + thread::spawn(move|| { + if i == 0 { + tx.send(()).unwrap(); + } else { + f(i - 1, tx); + } + }); + + } + f(10, tx); + rx.recv().unwrap(); + } + + #[test] + fn test_spawn_sched_childs_on_default_sched() { + let (tx, rx) = channel(); + + thread::spawn(move|| { + thread::spawn(move|| { + tx.send(()).unwrap(); + }); + }); + + rx.recv().unwrap(); + } + + fn avoid_copying_the_body(spawnfn: F) where F: FnOnce(Thunk<'static>) { + let (tx, rx) = channel(); + + let x: Box<_> = box 1; + let x_in_parent = (&*x) as *const i32 as usize; + + spawnfn(Thunk::new(move|| { + let x_in_child = (&*x) as *const i32 as usize; + tx.send(x_in_child).unwrap(); + })); + + let x_in_child = rx.recv().unwrap(); + assert_eq!(x_in_parent, x_in_child); + } + + #[test] + fn test_avoid_copying_the_body_spawn() { + avoid_copying_the_body(|v| { + thread::spawn(move || v.invoke(())); + }); + } + + #[test] + fn test_avoid_copying_the_body_thread_spawn() { + avoid_copying_the_body(|f| { + thread::spawn(move|| { + f.invoke(()); + }); + }) + } + + #[test] + fn test_avoid_copying_the_body_join() { + avoid_copying_the_body(|f| { + let _ = thread::spawn(move|| { + f.invoke(()) + }).join(); + }) + } + + #[test] + fn test_child_doesnt_ref_parent() { + // If the child refcounts the parent task, this will stack overflow when + // climbing the task tree to dereference each ancestor. (See #1789) + // (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> { + return Thunk::new(move|| { + if x < GENERATIONS { + thread::spawn(move|| child_no(x+1).invoke(())); + } + }); + } + thread::spawn(|| child_no(0).invoke(())); + } + + #[test] + fn test_simple_newsched_spawn() { + thread::spawn(move || {}); + } + + #[test] + fn test_try_panic_message_static_str() { + match thread::spawn(move|| { + panic!("static string"); + }).join() { + Err(e) => { + type T = &'static str; + assert!(e.is::()); + assert_eq!(*e.downcast::().unwrap(), "static string"); + } + Ok(()) => panic!() + } + } + + #[test] + fn test_try_panic_message_owned_str() { + match thread::spawn(move|| { + panic!("owned string".to_string()); + }).join() { + Err(e) => { + type T = String; + assert!(e.is::()); + assert_eq!(*e.downcast::().unwrap(), "owned string".to_string()); + } + Ok(()) => panic!() + } + } + + #[test] + fn test_try_panic_message_any() { + match thread::spawn(move|| { + panic!(box 413u16 as Box); + }).join() { + Err(e) => { + type T = Box; + assert!(e.is::()); + let any = e.downcast::().unwrap(); + assert!(any.is::()); + assert_eq!(*any.downcast::().unwrap(), 413); + } + Ok(()) => panic!() + } + } + + #[test] + fn test_try_panic_message_unit_struct() { + struct Juju; + + match thread::spawn(move|| { + panic!(Juju) + }).join() { + Err(ref e) if e.is::() => {} + Err(_) | Ok(()) => panic!() + } + } + + #[test] + fn test_park_timeout_unpark_before() { + for _ in 0..10 { + thread::current().unpark(); + thread::park_timeout(Duration::seconds(10_000_000)); + } + } + + #[test] + fn test_park_timeout_unpark_not_called() { + for _ in 0..10 { + thread::park_timeout(Duration::milliseconds(10)); + } + } + + #[test] + fn test_park_timeout_unpark_called_other_thread() { + use std::old_io; + + for _ in 0..10 { + let th = thread::current(); + + let _guard = thread::spawn(move || { + old_io::timer::sleep(Duration::milliseconds(50)); + th.unpark(); + }); + + thread::park_timeout(Duration::seconds(10_000_000)); + } + } + + #[test] + fn sleep_smoke() { + thread::sleep(Duration::milliseconds(2)); + thread::sleep(Duration::milliseconds(-2)); + } + + // NOTE: the corresponding test for stderr is in run-pass/task-stderr, due + // to the test harness apparently interfering with stderr configuration. +} diff --git a/src/libstd/thread/scoped.rs b/src/libstd/thread/scoped.rs new file mode 100644 index 00000000000..2a8be2ad82c --- /dev/null +++ b/src/libstd/thread/scoped.rs @@ -0,0 +1,317 @@ +// Copyright 2014-2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Scoped thread-local storage +//! +//! This module provides the ability to generate *scoped* thread-local +//! variables. In this sense, scoped indicates that thread local storage +//! actually stores a reference to a value, and this reference is only placed +//! in storage for a scoped amount of time. +//! +//! There are no restrictions on what types can be placed into a scoped +//! variable, but all scoped variables are initialized to the equivalent of +//! null. Scoped thread local storage is useful when a value is present for a known +//! period of time and it is not required to relinquish ownership of the +//! contents. +//! +//! # Examples +//! +//! ``` +//! scoped_thread_local!(static FOO: u32); +//! +//! // Initially each scoped slot is empty. +//! assert!(!FOO.is_set()); +//! +//! // When inserting a value, the value is only in place for the duration +//! // of the closure specified. +//! FOO.set(&1, || { +//! FOO.with(|slot| { +//! assert_eq!(*slot, 1); +//! }); +//! }); +//! ``` + +#![unstable(feature = "thread_local_internals")] + +use prelude::v1::*; + +// macro hygiene sure would be nice, wouldn't it? +#[doc(hidden)] +pub mod __impl { + pub use super::imp::KeyInner; + pub use sys_common::thread_local::INIT as OS_INIT; +} + +/// Type representing a thread local storage key corresponding to a reference +/// to the type parameter `T`. +/// +/// Keys are statically allocated and can contain a reference to an instance of +/// type `T` scoped to a particular lifetime. Keys provides two methods, `set` +/// and `with`, both of which currently use closures to control the scope of +/// their contents. +#[unstable(feature = "scoped_tls", + reason = "scoped TLS has yet to have wide enough use to fully consider \ + stabilizing its interface")] +pub struct ScopedKey { #[doc(hidden)] pub inner: __impl::KeyInner } + +/// Declare a new scoped thread local storage key. +/// +/// This macro declares a `static` item on which methods are used to get and +/// set the value stored within. +#[macro_export] +#[allow_internal_unstable] +macro_rules! scoped_thread_local { + (static $name:ident: $t:ty) => ( + __scoped_thread_local_inner!(static $name: $t); + ); + (pub static $name:ident: $t:ty) => ( + __scoped_thread_local_inner!(pub static $name: $t); + ); +} + +#[macro_export] +#[doc(hidden)] +#[allow_internal_unstable] +macro_rules! __scoped_thread_local_inner { + (static $name:ident: $t:ty) => ( + #[cfg_attr(not(any(windows, + target_os = "android", + target_os = "ios", + target_os = "openbsd", + target_arch = "aarch64")), + thread_local)] + static $name: ::std::thread::ScopedKey<$t> = + __scoped_thread_local_inner!($t); + ); + (pub static $name:ident: $t:ty) => ( + #[cfg_attr(not(any(windows, + target_os = "android", + target_os = "ios", + target_os = "openbsd", + target_arch = "aarch64")), + thread_local)] + pub static $name: ::std::thread::ScopedKey<$t> = + __scoped_thread_local_inner!($t); + ); + ($t:ty) => ({ + use std::thread::ScopedKey as __Key; + + #[cfg(not(any(windows, + target_os = "android", + target_os = "ios", + target_os = "openbsd", + target_arch = "aarch64")))] + const _INIT: __Key<$t> = __Key { + inner: ::std::thread::__scoped::__impl::KeyInner { + inner: ::std::cell::UnsafeCell { value: 0 as *mut _ }, + } + }; + + #[cfg(any(windows, + target_os = "android", + target_os = "ios", + target_os = "openbsd", + target_arch = "aarch64"))] + const _INIT: __Key<$t> = __Key { + inner: ::std::thread::__scoped::__impl::KeyInner { + inner: ::std::thread::__scoped::__impl::OS_INIT, + marker: ::std::marker::PhantomData::<::std::cell::Cell<$t>>, + } + }; + + _INIT + }) +} + +#[unstable(feature = "scoped_tls", + reason = "scoped TLS has yet to have wide enough use to fully consider \ + stabilizing its interface")] +impl ScopedKey { + /// Insert a value into this scoped thread local storage slot for a + /// duration of a closure. + /// + /// While `cb` is running, the value `t` will be returned by `get` unless + /// this function is called recursively inside of `cb`. + /// + /// Upon return, this function will restore the previous value, if any + /// was available. + /// + /// # Examples + /// + /// ``` + /// scoped_thread_local!(static FOO: u32); + /// + /// FOO.set(&100, || { + /// let val = FOO.with(|v| *v); + /// assert_eq!(val, 100); + /// + /// // set can be called recursively + /// FOO.set(&101, || { + /// // ... + /// }); + /// + /// // Recursive calls restore the previous value. + /// let val = FOO.with(|v| *v); + /// assert_eq!(val, 100); + /// }); + /// ``` + pub fn set(&'static self, t: &T, cb: F) -> R where + F: FnOnce() -> R, + { + struct Reset<'a, T: 'a> { + key: &'a __impl::KeyInner, + val: *mut T, + } + #[unsafe_destructor] + impl<'a, T> Drop for Reset<'a, T> { + fn drop(&mut self) { + unsafe { self.key.set(self.val) } + } + } + + let prev = unsafe { + let prev = self.inner.get(); + self.inner.set(t as *const T as *mut T); + prev + }; + + let _reset = Reset { key: &self.inner, val: prev }; + cb() + } + + /// Get a value out of this scoped variable. + /// + /// This function takes a closure which receives the value of this + /// variable. + /// + /// # Panics + /// + /// This function will panic if `set` has not previously been called. + /// + /// # Examples + /// + /// ```no_run + /// scoped_thread_local!(static FOO: u32); + /// + /// FOO.with(|slot| { + /// // work with `slot` + /// }); + /// ``` + pub fn with(&'static self, cb: F) -> R where + F: FnOnce(&T) -> R + { + unsafe { + let ptr = self.inner.get(); + assert!(!ptr.is_null(), "cannot access a scoped thread local \ + variable without calling `set` first"); + cb(&*ptr) + } + } + + /// Test whether this TLS key has been `set` for the current thread. + pub fn is_set(&'static self) -> bool { + unsafe { !self.inner.get().is_null() } + } +} + +#[cfg(not(any(windows, + target_os = "android", + target_os = "ios", + target_os = "openbsd", + target_arch = "aarch64")))] +mod imp { + use std::cell::UnsafeCell; + + #[doc(hidden)] + pub struct KeyInner { pub inner: UnsafeCell<*mut T> } + + unsafe impl ::marker::Sync for KeyInner { } + + #[doc(hidden)] + impl KeyInner { + #[doc(hidden)] + pub unsafe fn set(&self, ptr: *mut T) { *self.inner.get() = ptr; } + #[doc(hidden)] + pub unsafe fn get(&self) -> *mut T { *self.inner.get() } + } +} + +#[cfg(any(windows, + target_os = "android", + target_os = "ios", + target_os = "openbsd", + target_arch = "aarch64"))] +mod imp { + use marker; + use std::cell::Cell; + use sys_common::thread_local::StaticKey as OsStaticKey; + + #[doc(hidden)] + pub struct KeyInner { + pub inner: OsStaticKey, + pub marker: marker::PhantomData>, + } + + unsafe impl ::marker::Sync for KeyInner { } + + #[doc(hidden)] + impl KeyInner { + #[doc(hidden)] + pub unsafe fn set(&self, ptr: *mut T) { self.inner.set(ptr as *mut _) } + #[doc(hidden)] + pub unsafe fn get(&self) -> *mut T { self.inner.get() as *mut _ } + } +} + + +#[cfg(test)] +mod tests { + use cell::Cell; + use prelude::v1::*; + + scoped_thread_local!(static FOO: u32); + + #[test] + fn smoke() { + scoped_thread_local!(static BAR: u32); + + assert!(!BAR.is_set()); + BAR.set(&1, || { + assert!(BAR.is_set()); + BAR.with(|slot| { + assert_eq!(*slot, 1); + }); + }); + assert!(!BAR.is_set()); + } + + #[test] + fn cell_allowed() { + scoped_thread_local!(static BAR: Cell); + + BAR.set(&Cell::new(1), || { + BAR.with(|slot| { + assert_eq!(slot.get(), 1); + }); + }); + } + + #[test] + fn scope_item_allowed() { + assert!(!FOO.is_set()); + FOO.set(&1, || { + assert!(FOO.is_set()); + FOO.with(|slot| { + assert_eq!(*slot, 1); + }); + }); + assert!(!FOO.is_set()); + } +} diff --git a/src/libstd/thread_local/mod.rs b/src/libstd/thread_local/mod.rs deleted file mode 100644 index 08780292c88..00000000000 --- a/src/libstd/thread_local/mod.rs +++ /dev/null @@ -1,762 +0,0 @@ -// Copyright 2014-2015 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Thread local storage -//! -//! This module provides an implementation of thread local storage for Rust -//! programs. Thread local storage is a method of storing data into a global -//! variable which each thread in the program will have its own copy of. -//! Threads do not share this data, so accesses do not need to be synchronized. -//! -//! At a high level, this module provides two variants of storage: -//! -//! * Owning thread local storage. This is a type of thread local key which -//! owns the value that it contains, and will destroy the value when the -//! thread exits. This variant is created with the `thread_local!` macro and -//! can contain any value which is `'static` (no borrowed pointers. -//! -//! * Scoped thread local storage. This type of key is used to store a reference -//! to a value into local storage temporarily for the scope of a function -//! call. There are no restrictions on what types of values can be placed -//! into this key. -//! -//! Both forms of thread local storage provide an accessor function, `with`, -//! which will yield a shared reference to the value to the specified -//! closure. Thread local keys only allow shared access to values as there is no -//! way to guarantee uniqueness if a mutable borrow was allowed. Most values -//! will want to make use of some form of **interior mutability** through the -//! `Cell` or `RefCell` types. - -#![stable(feature = "rust1", since = "1.0.0")] - -use prelude::v1::*; - -use cell::UnsafeCell; - -#[macro_use] -pub mod scoped; - -// Sure wish we had macro hygiene, no? -#[doc(hidden)] -#[unstable(feature = "thread_local_internals")] -pub mod __impl { - pub use super::imp::Key as KeyInner; - pub use super::imp::destroy_value; - pub use sys_common::thread_local::INIT_INNER as OS_INIT_INNER; - pub use sys_common::thread_local::StaticKey as OsStaticKey; -} - -/// A thread local storage key which owns its contents. -/// -/// This key uses the fastest possible implementation available to it for the -/// target platform. It is instantiated with the `thread_local!` macro and the -/// primary method is the `with` method. -/// -/// The `with` method yields a reference to the contained value which cannot be -/// sent across tasks or escape the given closure. -/// -/// # Initialization and Destruction -/// -/// Initialization is dynamically performed on the first call to `with()` -/// within a thread, and values support destructors which will be run when a -/// thread exits. -/// -/// # Examples -/// -/// ``` -/// use std::cell::RefCell; -/// use std::thread; -/// -/// thread_local!(static FOO: RefCell = RefCell::new(1)); -/// -/// FOO.with(|f| { -/// assert_eq!(*f.borrow(), 1); -/// *f.borrow_mut() = 2; -/// }); -/// -/// // each thread starts out with the initial value of 1 -/// thread::spawn(move|| { -/// FOO.with(|f| { -/// assert_eq!(*f.borrow(), 1); -/// *f.borrow_mut() = 3; -/// }); -/// }); -/// -/// // we retain our original value of 2 despite the child thread -/// FOO.with(|f| { -/// assert_eq!(*f.borrow(), 2); -/// }); -/// ``` -#[stable(feature = "rust1", since = "1.0.0")] -pub struct Key { - // The key itself may be tagged with #[thread_local], and this `Key` is - // stored as a `static`, and it's not valid for a static to reference the - // address of another thread_local static. For this reason we kinda wonkily - // work around this by generating a shim function which will give us the - // address of the inner TLS key at runtime. - // - // This is trivially devirtualizable by LLVM because we never store anything - // to this field and rustc can declare the `static` as constant as well. - #[doc(hidden)] - #[unstable(feature = "thread_local_internals")] - pub inner: fn() -> &'static __impl::KeyInner>>, - - // initialization routine to invoke to create a value - #[doc(hidden)] - #[unstable(feature = "thread_local_internals")] - pub init: fn() -> T, -} - -/// Declare a new thread local storage key of type `std::thread_local::Key`. -#[macro_export] -#[stable(feature = "rust1", since = "1.0.0")] -#[allow_internal_unstable] -macro_rules! thread_local { - (static $name:ident: $t:ty = $init:expr) => ( - static $name: ::std::thread_local::Key<$t> = { - use std::cell::UnsafeCell as __UnsafeCell; - use std::thread_local::__impl::KeyInner as __KeyInner; - use std::option::Option as __Option; - use std::option::Option::None as __None; - - __thread_local_inner!(static __KEY: __UnsafeCell<__Option<$t>> = { - __UnsafeCell { value: __None } - }); - fn __init() -> $t { $init } - fn __getit() -> &'static __KeyInner<__UnsafeCell<__Option<$t>>> { - &__KEY - } - ::std::thread_local::Key { inner: __getit, init: __init } - }; - ); - (pub static $name:ident: $t:ty = $init:expr) => ( - pub static $name: ::std::thread_local::Key<$t> = { - use std::cell::UnsafeCell as __UnsafeCell; - use std::thread_local::__impl::KeyInner as __KeyInner; - use std::option::Option as __Option; - use std::option::Option::None as __None; - - __thread_local_inner!(static __KEY: __UnsafeCell<__Option<$t>> = { - __UnsafeCell { value: __None } - }); - fn __init() -> $t { $init } - fn __getit() -> &'static __KeyInner<__UnsafeCell<__Option<$t>>> { - &__KEY - } - ::std::thread_local::Key { inner: __getit, init: __init } - }; - ); -} - -// Macro pain #4586: -// -// When cross compiling, rustc will load plugins and macros from the *host* -// platform before search for macros from the target platform. This is primarily -// done to detect, for example, plugins. Ideally the macro below would be -// defined once per module below, but unfortunately this means we have the -// following situation: -// -// 1. We compile libstd for x86_64-unknown-linux-gnu, this thread_local!() macro -// will inject #[thread_local] statics. -// 2. We then try to compile a program for arm-linux-androideabi -// 3. The compiler has a host of linux and a target of android, so it loads -// macros from the *linux* libstd. -// 4. The macro generates a #[thread_local] field, but the android libstd does -// not use #[thread_local] -// 5. Compile error about structs with wrong fields. -// -// To get around this, we're forced to inject the #[cfg] logic into the macro -// itself. Woohoo. - -#[macro_export] -#[doc(hidden)] -#[allow_internal_unstable] -macro_rules! __thread_local_inner { - (static $name:ident: $t:ty = $init:expr) => ( - #[cfg_attr(all(any(target_os = "macos", target_os = "linux"), - not(target_arch = "aarch64")), - thread_local)] - static $name: ::std::thread_local::__impl::KeyInner<$t> = - __thread_local_inner!($init, $t); - ); - (pub static $name:ident: $t:ty = $init:expr) => ( - #[cfg_attr(all(any(target_os = "macos", target_os = "linux"), - not(target_arch = "aarch64")), - thread_local)] - pub static $name: ::std::thread_local::__impl::KeyInner<$t> = - __thread_local_inner!($init, $t); - ); - ($init:expr, $t:ty) => ({ - #[cfg(all(any(target_os = "macos", target_os = "linux"), not(target_arch = "aarch64")))] - const _INIT: ::std::thread_local::__impl::KeyInner<$t> = { - ::std::thread_local::__impl::KeyInner { - inner: ::std::cell::UnsafeCell { value: $init }, - dtor_registered: ::std::cell::UnsafeCell { value: false }, - dtor_running: ::std::cell::UnsafeCell { value: false }, - } - }; - - #[cfg(any(not(any(target_os = "macos", target_os = "linux")), target_arch = "aarch64"))] - const _INIT: ::std::thread_local::__impl::KeyInner<$t> = { - unsafe extern fn __destroy(ptr: *mut u8) { - ::std::thread_local::__impl::destroy_value::<$t>(ptr); - } - - ::std::thread_local::__impl::KeyInner { - inner: ::std::cell::UnsafeCell { value: $init }, - os: ::std::thread_local::__impl::OsStaticKey { - inner: ::std::thread_local::__impl::OS_INIT_INNER, - dtor: ::std::option::Option::Some(__destroy as unsafe extern fn(*mut u8)), - }, - } - }; - - _INIT - }); -} - -/// Indicator of the state of a thread local storage key. -#[unstable(feature = "std_misc", - reason = "state querying was recently added")] -#[derive(Eq, PartialEq, Copy)] -pub enum State { - /// All keys are in this state whenever a thread starts. Keys will - /// transition to the `Valid` state once the first call to `with` happens - /// and the initialization expression succeeds. - /// - /// Keys in the `Uninitialized` state will yield a reference to the closure - /// passed to `with` so long as the initialization routine does not panic. - Uninitialized, - - /// Once a key has been accessed successfully, it will enter the `Valid` - /// state. Keys in the `Valid` state will remain so until the thread exits, - /// at which point the destructor will be run and the key will enter the - /// `Destroyed` state. - /// - /// Keys in the `Valid` state will be guaranteed to yield a reference to the - /// closure passed to `with`. - Valid, - - /// When a thread exits, the destructors for keys will be run (if - /// necessary). While a destructor is running, and possibly after a - /// destructor has run, a key is in the `Destroyed` state. - /// - /// Keys in the `Destroyed` states will trigger a panic when accessed via - /// `with`. - Destroyed, -} - -impl Key { - /// Acquire a reference to the value in this TLS key. - /// - /// This will lazily initialize the value if this thread has not referenced - /// this key yet. - /// - /// # Panics - /// - /// This function will `panic!()` if the key currently has its - /// destructor running, and it **may** panic if the destructor has - /// previously been run for this thread. - #[stable(feature = "rust1", since = "1.0.0")] - pub fn with(&'static self, f: F) -> R - where F: FnOnce(&T) -> R { - let slot = (self.inner)(); - unsafe { - let slot = slot.get().expect("cannot access a TLS value during or \ - after it is destroyed"); - f(match *slot.get() { - Some(ref inner) => inner, - None => self.init(slot), - }) - } - } - - unsafe fn init(&self, slot: &UnsafeCell>) -> &T { - // Execute the initialization up front, *then* move it into our slot, - // just in case initialization fails. - let value = (self.init)(); - let ptr = slot.get(); - *ptr = Some(value); - (*ptr).as_ref().unwrap() - } - - /// Query the current state of this key. - /// - /// A key is initially in the `Uninitialized` state whenever a thread - /// starts. It will remain in this state up until the first call to `with` - /// within a thread has run the initialization expression successfully. - /// - /// Once the initialization expression succeeds, the key transitions to the - /// `Valid` state which will guarantee that future calls to `with` will - /// succeed within the thread. - /// - /// When a thread exits, each key will be destroyed in turn, and as keys are - /// destroyed they will enter the `Destroyed` state just before the - /// destructor starts to run. Keys may remain in the `Destroyed` state after - /// destruction has completed. Keys without destructors (e.g. with types - /// that are `Copy`), may never enter the `Destroyed` state. - /// - /// Keys in the `Uninitialized` can be accessed so long as the - /// initialization does not panic. Keys in the `Valid` state are guaranteed - /// to be able to be accessed. Keys in the `Destroyed` state will panic on - /// any call to `with`. - #[unstable(feature = "std_misc", - reason = "state querying was recently added")] - pub fn state(&'static self) -> State { - unsafe { - match (self.inner)().get() { - Some(cell) => { - match *cell.get() { - Some(..) => State::Valid, - None => State::Uninitialized, - } - } - None => State::Destroyed, - } - } - } - - /// Deprecated - #[unstable(feature = "std_misc")] - #[deprecated(since = "1.0.0", - reason = "function renamed to state() and returns more info")] - pub fn destroyed(&'static self) -> bool { self.state() == State::Destroyed } -} - -#[cfg(all(any(target_os = "macos", target_os = "linux"), not(target_arch = "aarch64")))] -mod imp { - use prelude::v1::*; - - use cell::UnsafeCell; - use intrinsics; - use ptr; - - #[doc(hidden)] - #[unstable(feature = "thread_local_internals")] - pub struct Key { - // Place the inner bits in an `UnsafeCell` to currently get around the - // "only Sync statics" restriction. This allows any type to be placed in - // the cell. - // - // Note that all access requires `T: 'static` so it can't be a type with - // any borrowed pointers still. - #[unstable(feature = "thread_local_internals")] - pub inner: UnsafeCell, - - // Metadata to keep track of the state of the destructor. Remember that - // these variables are thread-local, not global. - #[unstable(feature = "thread_local_internals")] - pub dtor_registered: UnsafeCell, // should be Cell - #[unstable(feature = "thread_local_internals")] - pub dtor_running: UnsafeCell, // should be Cell - } - - unsafe impl ::marker::Sync for Key { } - - #[doc(hidden)] - impl Key { - pub unsafe fn get(&'static self) -> Option<&'static T> { - if intrinsics::needs_drop::() && *self.dtor_running.get() { - return None - } - self.register_dtor(); - Some(&*self.inner.get()) - } - - unsafe fn register_dtor(&self) { - if !intrinsics::needs_drop::() || *self.dtor_registered.get() { - return - } - - register_dtor(self as *const _ as *mut u8, - destroy_value::); - *self.dtor_registered.get() = true; - } - } - - // Since what appears to be glibc 2.18 this symbol has been shipped which - // GCC and clang both use to invoke destructors in thread_local globals, so - // let's do the same! - // - // Note, however, that we run on lots older linuxes, as well as cross - // compiling from a newer linux to an older linux, so we also have a - // fallback implementation to use as well. - // - // Due to rust-lang/rust#18804, make sure this is not generic! - #[cfg(target_os = "linux")] - unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern fn(*mut u8)) { - use boxed; - use mem; - use libc; - use sys_common::thread_local as os; - - extern { - static __dso_handle: *mut u8; - #[linkage = "extern_weak"] - static __cxa_thread_atexit_impl: *const (); - } - if !__cxa_thread_atexit_impl.is_null() { - type F = unsafe extern fn(dtor: unsafe extern fn(*mut u8), - arg: *mut u8, - dso_handle: *mut u8) -> libc::c_int; - mem::transmute::<*const (), F>(__cxa_thread_atexit_impl) - (dtor, t, __dso_handle); - return - } - - // The fallback implementation uses a vanilla OS-based TLS key to track - // the list of destructors that need to be run for this thread. The key - // then has its own destructor which runs all the other destructors. - // - // The destructor for DTORS is a little special in that it has a `while` - // loop to continuously drain the list of registered destructors. It - // *should* be the case that this loop always terminates because we - // provide the guarantee that a TLS key cannot be set after it is - // flagged for destruction. - static DTORS: os::StaticKey = os::StaticKey { - inner: os::INIT_INNER, - dtor: Some(run_dtors as unsafe extern "C" fn(*mut u8)), - }; - type List = Vec<(*mut u8, unsafe extern fn(*mut u8))>; - if DTORS.get().is_null() { - let v: Box = box Vec::new(); - DTORS.set(boxed::into_raw(v) as *mut u8); - } - let list: &mut List = &mut *(DTORS.get() as *mut List); - list.push((t, dtor)); - - unsafe extern fn run_dtors(mut ptr: *mut u8) { - while !ptr.is_null() { - let list: Box = Box::from_raw(ptr as *mut List); - for &(ptr, dtor) in &*list { - dtor(ptr); - } - ptr = DTORS.get(); - DTORS.set(ptr::null_mut()); - } - } - } - - // OSX's analog of the above linux function is this _tlv_atexit function. - // The disassembly of thread_local globals in C++ (at least produced by - // clang) will have this show up in the output. - #[cfg(target_os = "macos")] - unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern fn(*mut u8)) { - extern { - fn _tlv_atexit(dtor: unsafe extern fn(*mut u8), - arg: *mut u8); - } - _tlv_atexit(dtor, t); - } - - #[doc(hidden)] - #[unstable(feature = "thread_local_internals")] - pub unsafe extern fn destroy_value(ptr: *mut u8) { - let ptr = ptr as *mut Key; - // Right before we run the user destructor be sure to flag the - // destructor as running for this thread so calls to `get` will return - // `None`. - *(*ptr).dtor_running.get() = true; - ptr::read((*ptr).inner.get()); - } -} - -#[cfg(any(not(any(target_os = "macos", target_os = "linux")), target_arch = "aarch64"))] -mod imp { - use prelude::v1::*; - - use alloc::boxed; - use cell::UnsafeCell; - use mem; - use ptr; - use sys_common::thread_local::StaticKey as OsStaticKey; - - #[doc(hidden)] - #[unstable(feature = "thread_local_internals")] - pub struct Key { - // Statically allocated initialization expression, using an `UnsafeCell` - // for the same reasons as above. - #[unstable(feature = "thread_local_internals")] - pub inner: UnsafeCell, - - // OS-TLS key that we'll use to key off. - #[unstable(feature = "thread_local_internals")] - pub os: OsStaticKey, - } - - unsafe impl ::marker::Sync for Key { } - - struct Value { - key: &'static Key, - value: T, - } - - #[doc(hidden)] - impl Key { - pub unsafe fn get(&'static self) -> Option<&'static T> { - self.ptr().map(|p| &*p) - } - - unsafe fn ptr(&'static self) -> Option<*mut T> { - let ptr = self.os.get() as *mut Value; - if !ptr.is_null() { - if ptr as usize == 1 { - return None - } - return Some(&mut (*ptr).value as *mut T); - } - - // If the lookup returned null, we haven't initialized our own local - // copy, so do that now. - // - // Also note that this transmute_copy should be ok because the value - // `inner` is already validated to be a valid `static` value, so we - // should be able to freely copy the bits. - let ptr: Box> = box Value { - key: self, - value: mem::transmute_copy(&self.inner), - }; - let ptr: *mut Value = boxed::into_raw(ptr); - self.os.set(ptr as *mut u8); - Some(&mut (*ptr).value as *mut T) - } - } - - #[doc(hidden)] - #[unstable(feature = "thread_local_internals")] - pub unsafe extern fn destroy_value(ptr: *mut u8) { - // The OS TLS ensures that this key contains a NULL value when this - // destructor starts to run. We set it back to a sentinel value of 1 to - // ensure that any future calls to `get` for this thread will return - // `None`. - // - // Note that to prevent an infinite loop we reset it back to null right - // before we return from the destructor ourselves. - let ptr: Box> = Box::from_raw(ptr as *mut Value); - let key = ptr.key; - key.os.set(1 as *mut u8); - drop(ptr); - key.os.set(ptr::null_mut()); - } -} - -#[cfg(test)] -mod tests { - use prelude::v1::*; - - use sync::mpsc::{channel, Sender}; - use cell::UnsafeCell; - use super::State; - use thread; - - struct Foo(Sender<()>); - - impl Drop for Foo { - fn drop(&mut self) { - let Foo(ref s) = *self; - s.send(()).unwrap(); - } - } - - #[test] - fn smoke_no_dtor() { - thread_local!(static FOO: UnsafeCell = UnsafeCell { value: 1 }); - - FOO.with(|f| unsafe { - assert_eq!(*f.get(), 1); - *f.get() = 2; - }); - let (tx, rx) = channel(); - let _t = thread::spawn(move|| { - FOO.with(|f| unsafe { - assert_eq!(*f.get(), 1); - }); - tx.send(()).unwrap(); - }); - rx.recv().unwrap(); - - FOO.with(|f| unsafe { - assert_eq!(*f.get(), 2); - }); - } - - #[test] - fn states() { - struct Foo; - impl Drop for Foo { - fn drop(&mut self) { - assert!(FOO.state() == State::Destroyed); - } - } - fn foo() -> Foo { - assert!(FOO.state() == State::Uninitialized); - Foo - } - thread_local!(static FOO: Foo = foo()); - - thread::spawn(|| { - assert!(FOO.state() == State::Uninitialized); - FOO.with(|_| { - assert!(FOO.state() == State::Valid); - }); - assert!(FOO.state() == State::Valid); - }).join().ok().unwrap(); - } - - #[test] - fn smoke_dtor() { - thread_local!(static FOO: UnsafeCell> = UnsafeCell { - value: None - }); - - let (tx, rx) = channel(); - let _t = thread::spawn(move|| unsafe { - let mut tx = Some(tx); - FOO.with(|f| { - *f.get() = Some(Foo(tx.take().unwrap())); - }); - }); - rx.recv().unwrap(); - } - - #[test] - fn circular() { - struct S1; - struct S2; - thread_local!(static K1: UnsafeCell> = UnsafeCell { - value: None - }); - thread_local!(static K2: UnsafeCell> = UnsafeCell { - value: None - }); - static mut HITS: u32 = 0; - - impl Drop for S1 { - fn drop(&mut self) { - unsafe { - HITS += 1; - if K2.state() == State::Destroyed { - assert_eq!(HITS, 3); - } else { - if HITS == 1 { - K2.with(|s| *s.get() = Some(S2)); - } else { - assert_eq!(HITS, 3); - } - } - } - } - } - impl Drop for S2 { - fn drop(&mut self) { - unsafe { - HITS += 1; - assert!(K1.state() != State::Destroyed); - assert_eq!(HITS, 2); - K1.with(|s| *s.get() = Some(S1)); - } - } - } - - thread::spawn(move|| { - drop(S1); - }).join().ok().unwrap(); - } - - #[test] - fn self_referential() { - struct S1; - thread_local!(static K1: UnsafeCell> = UnsafeCell { - value: None - }); - - impl Drop for S1 { - fn drop(&mut self) { - assert!(K1.state() == State::Destroyed); - } - } - - thread::spawn(move|| unsafe { - K1.with(|s| *s.get() = Some(S1)); - }).join().ok().unwrap(); - } - - #[test] - fn dtors_in_dtors_in_dtors() { - struct S1(Sender<()>); - thread_local!(static K1: UnsafeCell> = UnsafeCell { - value: None - }); - thread_local!(static K2: UnsafeCell> = UnsafeCell { - value: None - }); - - impl Drop for S1 { - fn drop(&mut self) { - let S1(ref tx) = *self; - unsafe { - if K2.state() != State::Destroyed { - K2.with(|s| *s.get() = Some(Foo(tx.clone()))); - } - } - } - } - - let (tx, rx) = channel(); - let _t = thread::spawn(move|| unsafe { - let mut tx = Some(tx); - K1.with(|s| *s.get() = Some(S1(tx.take().unwrap()))); - }); - rx.recv().unwrap(); - } -} - -#[cfg(test)] -mod dynamic_tests { - use prelude::v1::*; - - use cell::RefCell; - use collections::HashMap; - - #[test] - fn smoke() { - fn square(i: i32) -> i32 { i * i } - thread_local!(static FOO: i32 = square(3)); - - FOO.with(|f| { - assert_eq!(*f, 9); - }); - } - - #[test] - fn hashmap() { - fn map() -> RefCell> { - let mut m = HashMap::new(); - m.insert(1, 2); - RefCell::new(m) - } - thread_local!(static FOO: RefCell> = map()); - - FOO.with(|map| { - assert_eq!(map.borrow()[1], 2); - }); - } - - #[test] - fn refcell_vec() { - thread_local!(static FOO: RefCell> = RefCell::new(vec![1, 2, 3])); - - FOO.with(|vec| { - assert_eq!(vec.borrow().len(), 3); - vec.borrow_mut().push(4); - assert_eq!(vec.borrow()[3], 4); - }); - } -} diff --git a/src/libstd/thread_local/scoped.rs b/src/libstd/thread_local/scoped.rs deleted file mode 100644 index 86e6c059a70..00000000000 --- a/src/libstd/thread_local/scoped.rs +++ /dev/null @@ -1,313 +0,0 @@ -// Copyright 2014-2015 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Scoped thread-local storage -//! -//! This module provides the ability to generate *scoped* thread-local -//! variables. In this sense, scoped indicates that thread local storage -//! actually stores a reference to a value, and this reference is only placed -//! in storage for a scoped amount of time. -//! -//! There are no restrictions on what types can be placed into a scoped -//! variable, but all scoped variables are initialized to the equivalent of -//! null. Scoped thread local storage is useful when a value is present for a known -//! period of time and it is not required to relinquish ownership of the -//! contents. -//! -//! # Examples -//! -//! ``` -//! scoped_thread_local!(static FOO: u32); -//! -//! // Initially each scoped slot is empty. -//! assert!(!FOO.is_set()); -//! -//! // When inserting a value, the value is only in place for the duration -//! // of the closure specified. -//! FOO.set(&1, || { -//! FOO.with(|slot| { -//! assert_eq!(*slot, 1); -//! }); -//! }); -//! ``` - -#![unstable(feature = "std_misc", - reason = "scoped TLS has yet to have wide enough use to fully consider \ - stabilizing its interface")] - -use prelude::v1::*; - -// macro hygiene sure would be nice, wouldn't it? -#[doc(hidden)] -pub mod __impl { - pub use super::imp::KeyInner; - pub use sys_common::thread_local::INIT as OS_INIT; -} - -/// Type representing a thread local storage key corresponding to a reference -/// to the type parameter `T`. -/// -/// Keys are statically allocated and can contain a reference to an instance of -/// type `T` scoped to a particular lifetime. Keys provides two methods, `set` -/// and `with`, both of which currently use closures to control the scope of -/// their contents. -pub struct Key { #[doc(hidden)] pub inner: __impl::KeyInner } - -/// Declare a new scoped thread local storage key. -/// -/// This macro declares a `static` item on which methods are used to get and -/// set the value stored within. -#[macro_export] -#[allow_internal_unstable] -macro_rules! scoped_thread_local { - (static $name:ident: $t:ty) => ( - __scoped_thread_local_inner!(static $name: $t); - ); - (pub static $name:ident: $t:ty) => ( - __scoped_thread_local_inner!(pub static $name: $t); - ); -} - -#[macro_export] -#[doc(hidden)] -#[allow_internal_unstable] -macro_rules! __scoped_thread_local_inner { - (static $name:ident: $t:ty) => ( - #[cfg_attr(not(any(windows, - target_os = "android", - target_os = "ios", - target_os = "openbsd", - target_arch = "aarch64")), - thread_local)] - static $name: ::std::thread_local::scoped::Key<$t> = - __scoped_thread_local_inner!($t); - ); - (pub static $name:ident: $t:ty) => ( - #[cfg_attr(not(any(windows, - target_os = "android", - target_os = "ios", - target_os = "openbsd", - target_arch = "aarch64")), - thread_local)] - pub static $name: ::std::thread_local::scoped::Key<$t> = - __scoped_thread_local_inner!($t); - ); - ($t:ty) => ({ - use std::thread_local::scoped::Key as __Key; - - #[cfg(not(any(windows, - target_os = "android", - target_os = "ios", - target_os = "openbsd", - target_arch = "aarch64")))] - const _INIT: __Key<$t> = __Key { - inner: ::std::thread_local::scoped::__impl::KeyInner { - inner: ::std::cell::UnsafeCell { value: 0 as *mut _ }, - } - }; - - #[cfg(any(windows, - target_os = "android", - target_os = "ios", - target_os = "openbsd", - target_arch = "aarch64"))] - const _INIT: __Key<$t> = __Key { - inner: ::std::thread_local::scoped::__impl::KeyInner { - inner: ::std::thread_local::scoped::__impl::OS_INIT, - marker: ::std::marker::PhantomData::<::std::cell::Cell<$t>>, - } - }; - - _INIT - }) -} - -impl Key { - /// Insert a value into this scoped thread local storage slot for a - /// duration of a closure. - /// - /// While `cb` is running, the value `t` will be returned by `get` unless - /// this function is called recursively inside of `cb`. - /// - /// Upon return, this function will restore the previous value, if any - /// was available. - /// - /// # Examples - /// - /// ``` - /// scoped_thread_local!(static FOO: u32); - /// - /// FOO.set(&100, || { - /// let val = FOO.with(|v| *v); - /// assert_eq!(val, 100); - /// - /// // set can be called recursively - /// FOO.set(&101, || { - /// // ... - /// }); - /// - /// // Recursive calls restore the previous value. - /// let val = FOO.with(|v| *v); - /// assert_eq!(val, 100); - /// }); - /// ``` - pub fn set(&'static self, t: &T, cb: F) -> R where - F: FnOnce() -> R, - { - struct Reset<'a, T: 'a> { - key: &'a __impl::KeyInner, - val: *mut T, - } - #[unsafe_destructor] - impl<'a, T> Drop for Reset<'a, T> { - fn drop(&mut self) { - unsafe { self.key.set(self.val) } - } - } - - let prev = unsafe { - let prev = self.inner.get(); - self.inner.set(t as *const T as *mut T); - prev - }; - - let _reset = Reset { key: &self.inner, val: prev }; - cb() - } - - /// Get a value out of this scoped variable. - /// - /// This function takes a closure which receives the value of this - /// variable. - /// - /// # Panics - /// - /// This function will panic if `set` has not previously been called. - /// - /// # Examples - /// - /// ```no_run - /// scoped_thread_local!(static FOO: u32); - /// - /// FOO.with(|slot| { - /// // work with `slot` - /// }); - /// ``` - pub fn with(&'static self, cb: F) -> R where - F: FnOnce(&T) -> R - { - unsafe { - let ptr = self.inner.get(); - assert!(!ptr.is_null(), "cannot access a scoped thread local \ - variable without calling `set` first"); - cb(&*ptr) - } - } - - /// Test whether this TLS key has been `set` for the current thread. - pub fn is_set(&'static self) -> bool { - unsafe { !self.inner.get().is_null() } - } -} - -#[cfg(not(any(windows, - target_os = "android", - target_os = "ios", - target_os = "openbsd", - target_arch = "aarch64")))] -mod imp { - use std::cell::UnsafeCell; - - #[doc(hidden)] - pub struct KeyInner { pub inner: UnsafeCell<*mut T> } - - unsafe impl ::marker::Sync for KeyInner { } - - #[doc(hidden)] - impl KeyInner { - #[doc(hidden)] - pub unsafe fn set(&self, ptr: *mut T) { *self.inner.get() = ptr; } - #[doc(hidden)] - pub unsafe fn get(&self) -> *mut T { *self.inner.get() } - } -} - -#[cfg(any(windows, - target_os = "android", - target_os = "ios", - target_os = "openbsd", - target_arch = "aarch64"))] -mod imp { - use marker; - use std::cell::Cell; - use sys_common::thread_local::StaticKey as OsStaticKey; - - #[doc(hidden)] - pub struct KeyInner { - pub inner: OsStaticKey, - pub marker: marker::PhantomData>, - } - - unsafe impl ::marker::Sync for KeyInner { } - - #[doc(hidden)] - impl KeyInner { - #[doc(hidden)] - pub unsafe fn set(&self, ptr: *mut T) { self.inner.set(ptr as *mut _) } - #[doc(hidden)] - pub unsafe fn get(&self) -> *mut T { self.inner.get() as *mut _ } - } -} - - -#[cfg(test)] -mod tests { - use cell::Cell; - use prelude::v1::*; - - scoped_thread_local!(static FOO: u32); - - #[test] - fn smoke() { - scoped_thread_local!(static BAR: u32); - - assert!(!BAR.is_set()); - BAR.set(&1, || { - assert!(BAR.is_set()); - BAR.with(|slot| { - assert_eq!(*slot, 1); - }); - }); - assert!(!BAR.is_set()); - } - - #[test] - fn cell_allowed() { - scoped_thread_local!(static BAR: Cell); - - BAR.set(&Cell::new(1), || { - BAR.with(|slot| { - assert_eq!(slot.get(), 1); - }); - }); - } - - #[test] - fn scope_item_allowed() { - assert!(!FOO.is_set()); - FOO.set(&1, || { - assert!(FOO.is_set()); - FOO.with(|slot| { - assert_eq!(*slot, 1); - }); - }); - assert!(!FOO.is_set()); - } -} -- cgit 1.4.1-3-g733a5 From b4d4daf007753dfb04d87b1ffe1c2ad2d8811d5a Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sat, 21 Mar 2015 19:33:27 -0400 Subject: Adjust Index/IndexMut impls. For generic collections, we take references. For collections whose keys are integers, we take both references and by-value. --- src/libcollections/btree/map.rs | 15 +++ src/libcollections/string.rs | 32 ++++++ src/libcollections/vec.rs | 82 +++++++++++++++ src/libcollections/vec_deque.rs | 14 +++ src/libcollections/vec_map.rs | 42 +++++++- src/libcore/ops.rs | 6 +- src/libcore/slice.rs | 201 +++++++++++++++++++++++++++++++++++++ src/libcore/str/mod.rs | 78 ++++++++++++++ src/libserialize/json.rs | 23 +++++ src/libstd/collections/hash/map.rs | 24 ++++- src/libstd/ffi/os_str.rs | 12 +++ src/libstd/sys/common/wtf8.rs | 79 +++++++++++++++ 12 files changed, 600 insertions(+), 8 deletions(-) (limited to 'src/libstd') diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index a9e1ce8d7ce..0a72f24b437 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -914,12 +914,27 @@ impl Debug for BTreeMap { } } +#[cfg(stage0)] #[stable(feature = "rust1", since = "1.0.0")] impl Index for BTreeMap where K: Borrow, Q: Ord { type Output = V; + #[inline] + fn index(&self, key: &Q) -> &V { + self.get(key).expect("no entry found for key") + } +} + +#[cfg(not(stage0))] +#[stable(feature = "rust1", since = "1.0.0")] +impl<'a, K: Ord, Q: ?Sized, V> Index<&'a Q> for BTreeMap + where K: Borrow, Q: Ord +{ + type Output = V; + + #[inline] fn index(&self, key: &Q) -> &V { self.get(key).expect("no entry found for key") } diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index cd6f27bf65f..3f869d0b8ae 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -870,34 +870,66 @@ impl<'a> Add<&'a str> for String { #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index> for String { type Output = str; + + #[cfg(stage0)] #[inline] fn index(&self, index: &ops::Range) -> &str { &self[..][*index] } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, index: ops::Range) -> &str { + &self[..][index] + } } #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index> for String { type Output = str; + + #[cfg(stage0)] #[inline] fn index(&self, index: &ops::RangeTo) -> &str { &self[..][*index] } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, index: ops::RangeTo) -> &str { + &self[..][index] + } } #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index> for String { type Output = str; + + #[cfg(stage0)] #[inline] fn index(&self, index: &ops::RangeFrom) -> &str { &self[..][*index] } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, index: ops::RangeFrom) -> &str { + &self[..][index] + } } #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index for String { type Output = str; + + #[cfg(stage0)] #[inline] fn index(&self, _index: &ops::RangeFull) -> &str { unsafe { mem::transmute(&*self.vec) } } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, _index: ops::RangeFull) -> &str { + unsafe { mem::transmute(&*self.vec) } + } } #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index b0e8dc7d0b6..3e46ebfc446 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1323,83 +1323,165 @@ impl Hash for Vec { impl Index for Vec { type Output = T; + + #[cfg(stage0)] #[inline] fn index(&self, index: &usize) -> &T { // NB built-in indexing via `&[T]` &(**self)[*index] } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, index: usize) -> &T { + // NB built-in indexing via `&[T]` + &(**self)[index] + } } #[stable(feature = "rust1", since = "1.0.0")] impl IndexMut for Vec { + + #[cfg(stage0)] #[inline] fn index_mut(&mut self, index: &usize) -> &mut T { // NB built-in indexing via `&mut [T]` &mut (**self)[*index] } + + #[cfg(not(stage0))] + #[inline] + fn index_mut(&mut self, index: usize) -> &mut T { + // NB built-in indexing via `&mut [T]` + &mut (**self)[index] + } } #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index> for Vec { type Output = [T]; + + #[cfg(stage0)] #[inline] fn index(&self, index: &ops::Range) -> &[T] { Index::index(&**self, index) } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, index: ops::Range) -> &[T] { + Index::index(&**self, index) + } } #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index> for Vec { type Output = [T]; + + #[cfg(stage0)] #[inline] fn index(&self, index: &ops::RangeTo) -> &[T] { Index::index(&**self, index) } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, index: ops::RangeTo) -> &[T] { + Index::index(&**self, index) + } } #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index> for Vec { type Output = [T]; + + #[cfg(stage0)] #[inline] fn index(&self, index: &ops::RangeFrom) -> &[T] { Index::index(&**self, index) } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, index: ops::RangeFrom) -> &[T] { + Index::index(&**self, index) + } } #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index for Vec { type Output = [T]; + + #[cfg(stage0)] #[inline] fn index(&self, _index: &ops::RangeFull) -> &[T] { self.as_slice() } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, _index: ops::RangeFull) -> &[T] { + self.as_slice() + } } #[stable(feature = "rust1", since = "1.0.0")] impl ops::IndexMut> for Vec { + + #[cfg(stage0)] #[inline] fn index_mut(&mut self, index: &ops::Range) -> &mut [T] { IndexMut::index_mut(&mut **self, index) } + + #[cfg(not(stage0))] + #[inline] + fn index_mut(&mut self, index: ops::Range) -> &mut [T] { + IndexMut::index_mut(&mut **self, index) + } } #[stable(feature = "rust1", since = "1.0.0")] impl ops::IndexMut> for Vec { + + #[cfg(stage0)] #[inline] fn index_mut(&mut self, index: &ops::RangeTo) -> &mut [T] { IndexMut::index_mut(&mut **self, index) } + + #[cfg(not(stage0))] + #[inline] + fn index_mut(&mut self, index: ops::RangeTo) -> &mut [T] { + IndexMut::index_mut(&mut **self, index) + } } #[stable(feature = "rust1", since = "1.0.0")] impl ops::IndexMut> for Vec { + + #[cfg(stage0)] #[inline] fn index_mut(&mut self, index: &ops::RangeFrom) -> &mut [T] { IndexMut::index_mut(&mut **self, index) } + + #[cfg(not(stage0))] + #[inline] + fn index_mut(&mut self, index: ops::RangeFrom) -> &mut [T] { + IndexMut::index_mut(&mut **self, index) + } } #[stable(feature = "rust1", since = "1.0.0")] impl ops::IndexMut for Vec { + + #[cfg(stage0)] #[inline] fn index_mut(&mut self, _index: &ops::RangeFull) -> &mut [T] { self.as_mut_slice() } + + #[cfg(not(stage0))] + #[inline] + fn index_mut(&mut self, _index: ops::RangeFull) -> &mut [T] { + self.as_mut_slice() + } } #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcollections/vec_deque.rs b/src/libcollections/vec_deque.rs index 56ca74dab1f..591ad48f579 100644 --- a/src/libcollections/vec_deque.rs +++ b/src/libcollections/vec_deque.rs @@ -1689,18 +1689,32 @@ impl Hash for VecDeque { impl Index for VecDeque { type Output = A; + #[cfg(stage0)] #[inline] fn index(&self, i: &usize) -> &A { self.get(*i).expect("Out of bounds access") } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, i: usize) -> &A { + self.get(i).expect("Out of bounds access") + } } #[stable(feature = "rust1", since = "1.0.0")] impl IndexMut for VecDeque { + #[cfg(stage0)] #[inline] fn index_mut(&mut self, i: &usize) -> &mut A { self.get_mut(*i).expect("Out of bounds access") } + + #[cfg(not(stage0))] + #[inline] + fn index_mut(&mut self, i: usize) -> &mut A { + self.get_mut(i).expect("Out of bounds access") + } } #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index 6e67d876327..05693ec5275 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -798,6 +798,7 @@ impl Extend<(usize, V)> for VecMap { } } +#[cfg(stage0)] impl Index for VecMap { type Output = V; @@ -807,10 +808,49 @@ impl Index for VecMap { } } +#[cfg(not(stage0))] +impl Index for VecMap { + type Output = V; + + #[inline] + fn index<'a>(&'a self, i: usize) -> &'a V { + self.get(&i).expect("key not present") + } +} + +#[cfg(not(stage0))] +impl<'a,V> Index<&'a usize> for VecMap { + type Output = V; + + #[inline] + fn index(&self, i: &usize) -> &V { + self.get(i).expect("key not present") + } +} + +#[cfg(stage0)] +#[stable(feature = "rust1", since = "1.0.0")] +impl IndexMut for VecMap { + #[inline] + fn index_mut(&mut self, i: &usize) -> &mut V { + self.get_mut(&i).expect("key not present") + } +} + +#[cfg(not(stage0))] #[stable(feature = "rust1", since = "1.0.0")] impl IndexMut for VecMap { #[inline] - fn index_mut<'a>(&'a mut self, i: &usize) -> &'a mut V { + fn index_mut(&mut self, i: usize) -> &mut V { + self.get_mut(&i).expect("key not present") + } +} + +#[cfg(not(stage0))] +#[stable(feature = "rust1", since = "1.0.0")] +impl<'a, V> IndexMut<&'a usize> for VecMap { + #[inline] + fn index_mut(&mut self, i: &usize) -> &mut V { self.get_mut(i).expect("key not present") } } diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index e1e352b5b64..6e6f97a7af7 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -898,7 +898,7 @@ shr_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize } /// impl Index for Foo { /// type Output = Foo; /// -/// fn index<'a>(&'a self, _index: &Bar) -> &'a Foo { +/// fn index<'a>(&'a self, _index: Bar) -> &'a Foo { /// println!("Indexing!"); /// self /// } @@ -945,13 +945,13 @@ pub trait Index { /// impl Index for Foo { /// type Output = Foo; /// -/// fn index<'a>(&'a self, _index: &Bar) -> &'a Foo { +/// fn index<'a>(&'a self, _index: Bar) -> &'a Foo { /// self /// } /// } /// /// impl IndexMut for Foo { -/// fn index_mut<'a>(&'a mut self, _index: &Bar) -> &'a mut Foo { +/// fn index_mut<'a>(&'a mut self, _index: Bar) -> &'a mut Foo { /// println!("Indexing!"); /// self /// } diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 907b2eba80c..04b425416f3 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -263,6 +263,7 @@ impl SliceExt for [T] { #[inline] fn as_mut_slice(&mut self) -> &mut [T] { self } + #[cfg(stage0)] #[inline] fn split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T]) { unsafe { @@ -273,6 +274,17 @@ impl SliceExt for [T] { } } + #[cfg(not(stage0))] + #[inline] + fn split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T]) { + unsafe { + let self2: &mut [T] = mem::transmute_copy(&self); + + (ops::IndexMut::index_mut(self, ops::RangeTo { end: mid } ), + ops::IndexMut::index_mut(self2, ops::RangeFrom { start: mid } )) + } + } + #[inline] fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T> { unsafe { @@ -495,25 +507,45 @@ impl SliceExt for [T] { impl ops::Index for [T] { type Output = T; + #[cfg(stage0)] fn index(&self, &index: &usize) -> &T { assert!(index < self.len()); unsafe { mem::transmute(self.repr().data.offset(index as isize)) } } + + #[cfg(not(stage0))] + fn index(&self, index: usize) -> &T { + assert!(index < self.len()); + + unsafe { mem::transmute(self.repr().data.offset(index as isize)) } + } } #[stable(feature = "rust1", since = "1.0.0")] impl ops::IndexMut for [T] { + #[cfg(stage0)] + #[inline] fn index_mut(&mut self, &index: &usize) -> &mut T { assert!(index < self.len()); unsafe { mem::transmute(self.repr().data.offset(index as isize)) } } + + #[cfg(not(stage0))] + #[inline] + fn index_mut(&mut self, index: usize) -> &mut T { + assert!(index < self.len()); + + unsafe { mem::transmute(self.repr().data.offset(index as isize)) } + } } #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index> for [T] { type Output = [T]; + + #[cfg(stage0)] #[inline] fn index(&self, index: &ops::Range) -> &[T] { assert!(index.start <= index.end); @@ -525,34 +557,72 @@ impl ops::Index> for [T] { ) } } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, index: ops::Range) -> &[T] { + assert!(index.start <= index.end); + assert!(index.end <= self.len()); + unsafe { + from_raw_parts ( + self.as_ptr().offset(index.start as isize), + index.end - index.start + ) + } + } } #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index> for [T] { type Output = [T]; + + #[cfg(stage0)] #[inline] fn index(&self, index: &ops::RangeTo) -> &[T] { self.index(&ops::Range{ start: 0, end: index.end }) } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, index: ops::RangeTo) -> &[T] { + self.index(ops::Range{ start: 0, end: index.end }) + } } #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index> for [T] { type Output = [T]; + + #[cfg(stage0)] #[inline] fn index(&self, index: &ops::RangeFrom) -> &[T] { self.index(&ops::Range{ start: index.start, end: self.len() }) } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, index: ops::RangeFrom) -> &[T] { + self.index(ops::Range{ start: index.start, end: self.len() }) + } } #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index for [T] { type Output = [T]; + + #[cfg(stage0)] #[inline] fn index(&self, _index: &RangeFull) -> &[T] { self } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, _index: RangeFull) -> &[T] { + self + } } #[stable(feature = "rust1", since = "1.0.0")] impl ops::IndexMut> for [T] { + #[cfg(stage0)] #[inline] fn index_mut(&mut self, index: &ops::Range) -> &mut [T] { assert!(index.start <= index.end); @@ -564,28 +634,64 @@ impl ops::IndexMut> for [T] { ) } } + + #[cfg(not(stage0))] + #[inline] + fn index_mut(&mut self, index: ops::Range) -> &mut [T] { + assert!(index.start <= index.end); + assert!(index.end <= self.len()); + unsafe { + from_raw_parts_mut( + self.as_mut_ptr().offset(index.start as isize), + index.end - index.start + ) + } + } } #[stable(feature = "rust1", since = "1.0.0")] impl ops::IndexMut> for [T] { + #[cfg(stage0)] #[inline] fn index_mut(&mut self, index: &ops::RangeTo) -> &mut [T] { self.index_mut(&ops::Range{ start: 0, end: index.end }) } + + #[cfg(not(stage0))] + #[inline] + fn index_mut(&mut self, index: ops::RangeTo) -> &mut [T] { + self.index_mut(ops::Range{ start: 0, end: index.end }) + } } #[stable(feature = "rust1", since = "1.0.0")] impl ops::IndexMut> for [T] { + #[cfg(stage0)] #[inline] fn index_mut(&mut self, index: &ops::RangeFrom) -> &mut [T] { let len = self.len(); self.index_mut(&ops::Range{ start: index.start, end: len }) } + + #[cfg(not(stage0))] + #[inline] + fn index_mut(&mut self, index: ops::RangeFrom) -> &mut [T] { + let len = self.len(); + self.index_mut(ops::Range{ start: index.start, end: len }) + } } #[stable(feature = "rust1", since = "1.0.0")] impl ops::IndexMut for [T] { + + #[cfg(stage0)] #[inline] fn index_mut(&mut self, _index: &RangeFull) -> &mut [T] { self } + + #[cfg(not(stage0))] + #[inline] + fn index_mut(&mut self, _index: RangeFull) -> &mut [T] { + self + } } @@ -763,37 +869,69 @@ unsafe impl<'a, T: Sync> Send for Iter<'a, T> {} #[unstable(feature = "core")] impl<'a, T> ops::Index> for Iter<'a, T> { type Output = [T]; + + #[cfg(stage0)] #[inline] fn index(&self, index: &ops::Range) -> &[T] { self.as_slice().index(index) } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, index: ops::Range) -> &[T] { + self.as_slice().index(index) + } } #[unstable(feature = "core")] impl<'a, T> ops::Index> for Iter<'a, T> { type Output = [T]; + + #[cfg(stage0)] #[inline] fn index(&self, index: &ops::RangeTo) -> &[T] { self.as_slice().index(index) } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, index: ops::RangeTo) -> &[T] { + self.as_slice().index(index) + } } #[unstable(feature = "core")] impl<'a, T> ops::Index> for Iter<'a, T> { type Output = [T]; + + #[cfg(stage0)] #[inline] fn index(&self, index: &ops::RangeFrom) -> &[T] { self.as_slice().index(index) } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, index: ops::RangeFrom) -> &[T] { + self.as_slice().index(index) + } } #[unstable(feature = "core")] impl<'a, T> ops::Index for Iter<'a, T> { type Output = [T]; + + #[cfg(stage0)] #[inline] fn index(&self, _index: &RangeFull) -> &[T] { self.as_slice() } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, _index: RangeFull) -> &[T] { + self.as_slice() + } } impl<'a, T> Iter<'a, T> { @@ -856,63 +994,126 @@ unsafe impl<'a, T: Send> Send for IterMut<'a, T> {} #[unstable(feature = "core")] impl<'a, T> ops::Index> for IterMut<'a, T> { type Output = [T]; + + #[cfg(stage0)] #[inline] fn index(&self, index: &ops::Range) -> &[T] { self.index(&RangeFull).index(index) } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, index: ops::Range) -> &[T] { + self.index(RangeFull).index(index) + } } #[unstable(feature = "core")] impl<'a, T> ops::Index> for IterMut<'a, T> { type Output = [T]; + + #[cfg(stage0)] #[inline] fn index(&self, index: &ops::RangeTo) -> &[T] { self.index(&RangeFull).index(index) } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, index: ops::RangeTo) -> &[T] { + self.index(RangeFull).index(index) + } } #[unstable(feature = "core")] impl<'a, T> ops::Index> for IterMut<'a, T> { type Output = [T]; + + #[cfg(stage0)] #[inline] fn index(&self, index: &ops::RangeFrom) -> &[T] { self.index(&RangeFull).index(index) } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, index: ops::RangeFrom) -> &[T] { + self.index(RangeFull).index(index) + } } #[unstable(feature = "core")] impl<'a, T> ops::Index for IterMut<'a, T> { type Output = [T]; + + #[cfg(stage0)] #[inline] fn index(&self, _index: &RangeFull) -> &[T] { make_slice!(T => &[T]: self.ptr, self.end) } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, _index: RangeFull) -> &[T] { + make_slice!(T => &[T]: self.ptr, self.end) + } } #[unstable(feature = "core")] impl<'a, T> ops::IndexMut> for IterMut<'a, T> { + #[cfg(stage0)] #[inline] fn index_mut(&mut self, index: &ops::Range) -> &mut [T] { self.index_mut(&RangeFull).index_mut(index) } + + #[cfg(not(stage0))] + #[inline] + fn index_mut(&mut self, index: ops::Range) -> &mut [T] { + self.index_mut(RangeFull).index_mut(index) + } } #[unstable(feature = "core")] impl<'a, T> ops::IndexMut> for IterMut<'a, T> { + + #[cfg(stage0)] #[inline] fn index_mut(&mut self, index: &ops::RangeTo) -> &mut [T] { self.index_mut(&RangeFull).index_mut(index) } + + #[cfg(not(stage0))] + #[inline] + fn index_mut(&mut self, index: ops::RangeTo) -> &mut [T] { + self.index_mut(RangeFull).index_mut(index) + } } #[unstable(feature = "core")] impl<'a, T> ops::IndexMut> for IterMut<'a, T> { + + #[cfg(stage0)] #[inline] fn index_mut(&mut self, index: &ops::RangeFrom) -> &mut [T] { self.index_mut(&RangeFull).index_mut(index) } + + #[cfg(not(stage0))] + #[inline] + fn index_mut(&mut self, index: ops::RangeFrom) -> &mut [T] { + self.index_mut(RangeFull).index_mut(index) + } } #[unstable(feature = "core")] impl<'a, T> ops::IndexMut for IterMut<'a, T> { + + #[cfg(stage0)] #[inline] fn index_mut(&mut self, _index: &RangeFull) -> &mut [T] { make_mut_slice!(T => &mut [T]: self.ptr, self.end) } + + #[cfg(not(stage0))] + #[inline] + fn index_mut(&mut self, _index: RangeFull) -> &mut [T] { + make_mut_slice!(T => &mut [T]: self.ptr, self.end) + } } diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index e8181395b5c..b9a655c6d4e 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -1203,6 +1203,7 @@ mod traits { /// // byte 100 is outside the string /// // &s[3 .. 100]; /// ``` + #[cfg(stage0)] #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index> for str { type Output = str; @@ -1219,6 +1220,49 @@ mod traits { } } + /// Returns a slice of the given string from the byte range + /// [`begin`..`end`). + /// + /// This operation is `O(1)`. + /// + /// Panics when `begin` and `end` do not point to valid characters + /// or point beyond the last character of the string. + /// + /// # Examples + /// + /// ``` + /// let s = "Löwe 老虎 Léopard"; + /// assert_eq!(&s[0 .. 1], "L"); + /// + /// assert_eq!(&s[1 .. 9], "öwe 老"); + /// + /// // these will panic: + /// // byte 2 lies within `ö`: + /// // &s[2 ..3]; + /// + /// // byte 8 lies within `老` + /// // &s[1 .. 8]; + /// + /// // byte 100 is outside the string + /// // &s[3 .. 100]; + /// ``` + #[cfg(not(stage0))] + #[stable(feature = "rust1", since = "1.0.0")] + impl ops::Index> for str { + type Output = str; + #[inline] + fn index(&self, index: ops::Range) -> &str { + // is_char_boundary checks that the index is in [0, .len()] + if index.start <= index.end && + self.is_char_boundary(index.start) && + self.is_char_boundary(index.end) { + unsafe { self.slice_unchecked(index.start, index.end) } + } else { + super::slice_error_fail(self, index.start, index.end) + } + } + } + /// Returns a slice of the string from the beginning to byte /// `end`. /// @@ -1229,6 +1273,8 @@ mod traits { #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index> for str { type Output = str; + + #[cfg(stage0)] #[inline] fn index(&self, index: &ops::RangeTo) -> &str { // is_char_boundary checks that the index is in [0, .len()] @@ -1238,6 +1284,17 @@ mod traits { super::slice_error_fail(self, 0, index.end) } } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, index: ops::RangeTo) -> &str { + // is_char_boundary checks that the index is in [0, .len()] + if self.is_char_boundary(index.end) { + unsafe { self.slice_unchecked(0, index.end) } + } else { + super::slice_error_fail(self, 0, index.end) + } + } } /// Returns a slice of the string from `begin` to its end. @@ -1249,6 +1306,8 @@ mod traits { #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index> for str { type Output = str; + + #[cfg(stage0)] #[inline] fn index(&self, index: &ops::RangeFrom) -> &str { // is_char_boundary checks that the index is in [0, .len()] @@ -1258,15 +1317,34 @@ mod traits { super::slice_error_fail(self, index.start, self.len()) } } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, index: ops::RangeFrom) -> &str { + // is_char_boundary checks that the index is in [0, .len()] + if self.is_char_boundary(index.start) { + unsafe { self.slice_unchecked(index.start, self.len()) } + } else { + super::slice_error_fail(self, index.start, self.len()) + } + } } #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index for str { type Output = str; + + #[cfg(stage0)] #[inline] fn index(&self, _index: &ops::RangeFull) -> &str { self } + + #[cfg(not(stage0))] + #[inline] + fn index(&self, _index: ops::RangeFull) -> &str { + self + } } } diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 096c72e6af2..abbfc82319f 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -1218,6 +1218,7 @@ impl Json { } } +#[cfg(stage0)] impl<'a> Index<&'a str> for Json { type Output = Json; @@ -1226,6 +1227,16 @@ impl<'a> Index<&'a str> for Json { } } +#[cfg(not(stage0))] +impl<'a> Index<&'a str> for Json { + type Output = Json; + + fn index(&self, idx: &'a str) -> &Json { + self.find(idx).unwrap() + } +} + +#[cfg(stage0)] impl Index for Json { type Output = Json; @@ -1237,6 +1248,18 @@ impl Index for Json { } } +#[cfg(not(stage0))] +impl Index for Json { + type Output = Json; + + fn index<'a>(&'a self, idx: uint) -> &'a Json { + match self { + &Json::Array(ref v) => &v[idx], + _ => panic!("can only index Json with uint if it is an array") + } + } +} + /// The output of the streaming parser. #[derive(PartialEq, Clone, Debug)] pub enum JsonEvent { diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 9139e182ce4..86664d7eb0c 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1088,7 +1088,7 @@ impl HashMap /// Some(x) => *x = "b", /// None => (), /// } - /// assert_eq!(map[1], "b"); + /// assert_eq!(map[&1], "b"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn get_mut(&mut self, k: &Q) -> Option<&mut V> @@ -1111,7 +1111,7 @@ impl HashMap /// /// map.insert(37, "b"); /// assert_eq!(map.insert(37, "c"), Some("b")); - /// assert_eq!(map[37], "c"); + /// assert_eq!(map[&37], "c"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn insert(&mut self, k: K, v: V) -> Option { @@ -1244,6 +1244,7 @@ impl Default for HashMap } } +#[cfg(stage0)] #[stable(feature = "rust1", since = "1.0.0")] impl Index for HashMap where K: Eq + Hash + Borrow, @@ -1258,6 +1259,21 @@ impl Index for HashMap } } +#[cfg(not(stage0))] +#[stable(feature = "rust1", since = "1.0.0")] +impl<'a, K, Q: ?Sized, V, S> Index<&'a Q> for HashMap + where K: Eq + Hash + Borrow, + Q: Eq + Hash, + S: HashState, +{ + type Output = V; + + #[inline] + fn index(&self, index: &Q) -> &V { + self.get(index).expect("no entry found for key") + } +} + /// HashMap iterator. #[stable(feature = "rust1", since = "1.0.0")] pub struct Iter<'a, K: 'a, V: 'a> { @@ -2185,7 +2201,7 @@ mod test_map { map.insert(2, 1); map.insert(3, 4); - assert_eq!(map[2], 1); + assert_eq!(map[&2], 1); } #[test] @@ -2197,7 +2213,7 @@ mod test_map { map.insert(2, 1); map.insert(3, 4); - map[4]; + map[&4]; } #[test] diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index feacbf1e98b..290c48b1310 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -103,6 +103,7 @@ impl OsString { } } +#[cfg(stage0)] #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index for OsString { type Output = OsStr; @@ -113,6 +114,17 @@ impl ops::Index for OsString { } } +#[cfg(not(stage0))] +#[stable(feature = "rust1", since = "1.0.0")] +impl ops::Index for OsString { + type Output = OsStr; + + #[inline] + fn index(&self, _index: ops::RangeFull) -> &OsStr { + unsafe { mem::transmute(self.inner.as_slice()) } + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl ops::Deref for OsString { type Target = OsStr; diff --git a/src/libstd/sys/common/wtf8.rs b/src/libstd/sys/common/wtf8.rs index 3cc91bf54b4..9f3dae34c7a 100644 --- a/src/libstd/sys/common/wtf8.rs +++ b/src/libstd/sys/common/wtf8.rs @@ -634,6 +634,7 @@ impl Wtf8 { /// /// Panics when `begin` and `end` do not point to code point boundaries, /// or point beyond the end of the string. +#[cfg(stage0)] impl ops::Index> for Wtf8 { type Output = Wtf8; @@ -650,12 +651,36 @@ impl ops::Index> for Wtf8 { } } +/// Return a slice of the given string for the byte range [`begin`..`end`). +/// +/// # Panics +/// +/// Panics when `begin` and `end` do not point to code point boundaries, +/// or point beyond the end of the string. +#[cfg(not(stage0))] +impl ops::Index> for Wtf8 { + type Output = Wtf8; + + #[inline] + fn index(&self, range: ops::Range) -> &Wtf8 { + // is_code_point_boundary checks that the index is in [0, .len()] + if range.start <= range.end && + is_code_point_boundary(self, range.start) && + is_code_point_boundary(self, range.end) { + unsafe { slice_unchecked(self, range.start, range.end) } + } else { + slice_error_fail(self, range.start, range.end) + } + } +} + /// Return a slice of the given string from byte `begin` to its end. /// /// # Panics /// /// Panics when `begin` is not at a code point boundary, /// or is beyond the end of the string. +#[cfg(stage0)] impl ops::Index> for Wtf8 { type Output = Wtf8; @@ -670,12 +695,34 @@ impl ops::Index> for Wtf8 { } } +/// Return a slice of the given string from byte `begin` to its end. +/// +/// # Panics +/// +/// Panics when `begin` is not at a code point boundary, +/// or is beyond the end of the string. +#[cfg(not(stage0))] +impl ops::Index> for Wtf8 { + type Output = Wtf8; + + #[inline] + fn index(&self, range: ops::RangeFrom) -> &Wtf8 { + // is_code_point_boundary checks that the index is in [0, .len()] + if is_code_point_boundary(self, range.start) { + unsafe { slice_unchecked(self, range.start, self.len()) } + } else { + slice_error_fail(self, range.start, self.len()) + } + } +} + /// Return a slice of the given string from its beginning to byte `end`. /// /// # Panics /// /// Panics when `end` is not at a code point boundary, /// or is beyond the end of the string. +#[cfg(stage0)] impl ops::Index> for Wtf8 { type Output = Wtf8; @@ -690,6 +737,28 @@ impl ops::Index> for Wtf8 { } } +/// Return a slice of the given string from its beginning to byte `end`. +/// +/// # Panics +/// +/// Panics when `end` is not at a code point boundary, +/// or is beyond the end of the string. +#[cfg(not(stage0))] +impl ops::Index> for Wtf8 { + type Output = Wtf8; + + #[inline] + fn index(&self, range: ops::RangeTo) -> &Wtf8 { + // is_code_point_boundary checks that the index is in [0, .len()] + if is_code_point_boundary(self, range.end) { + unsafe { slice_unchecked(self, 0, range.end) } + } else { + slice_error_fail(self, 0, range.end) + } + } +} + +#[cfg(stage0)] impl ops::Index for Wtf8 { type Output = Wtf8; @@ -699,6 +768,16 @@ impl ops::Index for Wtf8 { } } +#[cfg(not(stage0))] +impl ops::Index for Wtf8 { + type Output = Wtf8; + + #[inline] + fn index(&self, _range: ops::RangeFull) -> &Wtf8 { + self + } +} + #[inline] fn decode_surrogate(second_byte: u8, third_byte: u8) -> u16 { // The first byte is assumed to be 0xED -- cgit 1.4.1-3-g733a5 From 8e58af40044a69a9a88de86e222c287eb79a4dcc Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sat, 21 Mar 2015 21:15:47 -0400 Subject: Fallout in stdlib, rustdoc, rustc, etc. For most maps, converted uses of `[]` on maps to `get` in rustc, since stage0 and stage1+ disagree about how to use `[]`. --- src/libcollections/btree/map.rs | 4 +- src/libcollections/btree/node.rs | 61 ++++++++++++++++++++++ src/librustc/metadata/cstore.rs | 2 +- src/librustc/metadata/encoder.rs | 6 +-- src/librustc/middle/astencode.rs | 2 +- src/librustc/middle/check_match.rs | 4 +- src/librustc/middle/const_eval.rs | 2 +- src/librustc/middle/dead.rs | 4 +- src/librustc/middle/effect.rs | 2 +- src/librustc/middle/expr_use_visitor.rs | 2 +- src/librustc/middle/infer/region_inference/mod.rs | 2 +- src/librustc/middle/liveness.rs | 8 +-- src/librustc/middle/mem_categorization.rs | 2 +- src/librustc/middle/reachable.rs | 2 +- src/librustc/middle/stability.rs | 2 +- src/librustc/middle/traits/project.rs | 4 +- src/librustc/middle/ty.rs | 8 +-- src/librustc_borrowck/borrowck/move_data.rs | 2 +- src/librustc_lint/builtin.rs | 2 +- src/librustc_privacy/lib.rs | 18 +++---- src/librustc_trans/back/link.rs | 4 +- src/librustc_trans/save/mod.rs | 31 ++++++----- src/librustc_trans/trans/_match.rs | 2 +- src/librustc_trans/trans/base.rs | 4 +- src/librustc_trans/trans/callee.rs | 2 +- src/librustc_trans/trans/common.rs | 4 +- src/librustc_trans/trans/consts.rs | 6 +-- src/librustc_trans/trans/expr.rs | 18 ++++--- src/librustc_typeck/astconv.rs | 2 +- src/librustc_typeck/check/_match.rs | 8 +-- src/librustc_typeck/check/mod.rs | 10 ++-- src/librustc_typeck/check/upvar.rs | 2 +- src/librustc_typeck/coherence/mod.rs | 4 +- src/librustc_typeck/collect.rs | 14 +++-- src/librustdoc/html/format.rs | 6 +-- src/librustdoc/html/render.rs | 6 +-- src/librustdoc/visit_ast.rs | 2 +- src/libstd/thread_local/mod.rs | 2 +- src/libsyntax/ext/format.rs | 2 +- src/libsyntax/ext/tt/macro_rules.rs | 4 +- src/test/auxiliary/issue-2631-a.rs | 2 +- src/test/auxiliary/procedural_mbe_matching.rs | 2 +- ...rrowck-overloaded-index-and-overloaded-deref.rs | 2 +- .../borrowck-overloaded-index-autoderef.rs | 45 ++++++++++------ src/test/compile-fail/dst-index.rs | 4 +- src/test/run-pass/dst-index.rs | 4 +- src/test/run-pass/issue-15734.rs | 10 ++-- src/test/run-pass/issue-2804-2.rs | 2 +- src/test/run-pass/issue-2804.rs | 5 +- src/test/run-pass/issue-5521.rs | 2 +- src/test/run-pass/issue-7660.rs | 4 +- src/test/run-pass/operator-overloading.rs | 4 +- src/test/run-pass/overloaded-index-assoc-list.rs | 10 ++-- src/test/run-pass/overloaded-index-autoderef.rs | 8 +-- src/test/run-pass/overloaded-index-in-field.rs | 4 +- src/test/run-pass/overloaded-index.rs | 8 +-- src/test/run-pass/slice.rs | 16 +++--- 57 files changed, 245 insertions(+), 159 deletions(-) (limited to 'src/libstd') diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index 0a72f24b437..755f564621a 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -264,7 +264,7 @@ impl BTreeMap { /// Some(x) => *x = "b", /// None => (), /// } - /// assert_eq!(map[1], "b"); + /// assert_eq!(map[&1], "b"); /// ``` // See `get` for implementation notes, this is basically a copy-paste with mut's added #[stable(feature = "rust1", since = "1.0.0")] @@ -326,7 +326,7 @@ impl BTreeMap { /// /// map.insert(37, "b"); /// assert_eq!(map.insert(37, "c"), Some("b")); - /// assert_eq!(map[37], "c"); + /// assert_eq!(map[&37], "c"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn insert(&mut self, mut key: K, mut value: V) -> Option { diff --git a/src/libcollections/btree/node.rs b/src/libcollections/btree/node.rs index bfac3b2df5a..5b8a5f02976 100644 --- a/src/libcollections/btree/node.rs +++ b/src/libcollections/btree/node.rs @@ -1522,6 +1522,7 @@ macro_rules! node_slice_impl { } /// Returns a sub-slice with elements starting with `min_key`. + #[cfg(stage0)] pub fn slice_from(self, min_key: &K) -> $NodeSlice<'a, K, V> { // _______________ // |_1_|_3_|_5_|_7_| @@ -1549,7 +1550,37 @@ macro_rules! node_slice_impl { } } + /// Returns a sub-slice with elements starting with `min_key`. + #[cfg(not(stage0))] + pub fn slice_from(self, min_key: &K) -> $NodeSlice<'a, K, V> { + // _______________ + // |_1_|_3_|_5_|_7_| + // | | | | | + // 0 0 1 1 2 2 3 3 4 index + // | | | | | + // \___|___|___|___/ slice_from(&0); pos = 0 + // \___|___|___/ slice_from(&2); pos = 1 + // |___|___|___/ slice_from(&3); pos = 1; result.head_is_edge = false + // \___|___/ slice_from(&4); pos = 2 + // \___/ slice_from(&6); pos = 3 + // \|/ slice_from(&999); pos = 4 + let (pos, pos_is_kv) = self.search_linear(min_key); + $NodeSlice { + has_edges: self.has_edges, + edges: if !self.has_edges { + self.edges + } else { + self.edges.$index(pos ..) + }, + keys: &self.keys[pos ..], + vals: self.vals.$index(pos ..), + head_is_edge: !pos_is_kv, + tail_is_edge: self.tail_is_edge, + } + } + /// Returns a sub-slice with elements up to and including `max_key`. + #[cfg(stage0)] pub fn slice_to(self, max_key: &K) -> $NodeSlice<'a, K, V> { // _______________ // |_1_|_3_|_5_|_7_| @@ -1577,6 +1608,36 @@ macro_rules! node_slice_impl { tail_is_edge: !pos_is_kv, } } + + /// Returns a sub-slice with elements up to and including `max_key`. + #[cfg(not(stage0))] + pub fn slice_to(self, max_key: &K) -> $NodeSlice<'a, K, V> { + // _______________ + // |_1_|_3_|_5_|_7_| + // | | | | | + // 0 0 1 1 2 2 3 3 4 index + // | | | | | + //\|/ | | | | slice_to(&0); pos = 0 + // \___/ | | | slice_to(&2); pos = 1 + // \___|___| | | slice_to(&3); pos = 1; result.tail_is_edge = false + // \___|___/ | | slice_to(&4); pos = 2 + // \___|___|___/ | slice_to(&6); pos = 3 + // \___|___|___|___/ slice_to(&999); pos = 4 + let (pos, pos_is_kv) = self.search_linear(max_key); + let pos = pos + if pos_is_kv { 1 } else { 0 }; + $NodeSlice { + has_edges: self.has_edges, + edges: if !self.has_edges { + self.edges + } else { + self.edges.$index(.. (pos + 1)) + }, + keys: &self.keys[..pos], + vals: self.vals.$index(.. pos), + head_is_edge: self.head_is_edge, + tail_is_edge: !pos_is_kv, + } + } } impl<'a, K: 'a, V: 'a> $NodeSlice<'a, K, V> { diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs index 47ec31c0f1a..2499853ace1 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc/metadata/cstore.rs @@ -111,7 +111,7 @@ impl CStore { } pub fn get_crate_data(&self, cnum: ast::CrateNum) -> Rc { - (*self.metas.borrow())[cnum].clone() + self.metas.borrow().get(&cnum).unwrap().clone() } pub fn get_crate_hash(&self, cnum: ast::CrateNum) -> Svh { diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 10461e3d2ae..fa8d0b2a56e 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -375,7 +375,7 @@ fn encode_reexported_static_base_methods(ecx: &EncodeContext, match ecx.tcx.inherent_impls.borrow().get(&exp.def_id) { Some(implementations) => { for base_impl_did in &**implementations { - for &method_did in &*(*impl_items)[*base_impl_did] { + for &method_did in impl_items.get(base_impl_did).unwrap() { let impl_item = ty::impl_or_trait_item( ecx.tcx, method_did.def_id()); @@ -1175,7 +1175,7 @@ fn encode_info_for_item(ecx: &EncodeContext, // We need to encode information about the default methods we // have inherited, so we drive this based on the impl structure. let impl_items = tcx.impl_items.borrow(); - let items = &(*impl_items)[def_id]; + let items = impl_items.get(&def_id).unwrap(); add_to_index(item, rbml_w, index); rbml_w.start_tag(tag_items_data_item); @@ -1816,7 +1816,7 @@ struct ImplVisitor<'a, 'b:'a, 'c:'a, 'tcx:'b> { impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for ImplVisitor<'a, 'b, 'c, 'tcx> { fn visit_item(&mut self, item: &ast::Item) { if let ast::ItemImpl(_, _, _, Some(ref trait_ref), _, _) = item.node { - let def_id = self.ecx.tcx.def_map.borrow()[trait_ref.ref_id].def_id(); + let def_id = self.ecx.tcx.def_map.borrow().get(&trait_ref.ref_id).unwrap().def_id(); // Load eagerly if this is an implementation of the Drop trait // or if the trait is not defined in this crate. diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index bffcb93bc6d..801350e8a1e 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -1228,7 +1228,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, var_id: var_id, closure_expr_id: id }; - let upvar_capture = tcx.upvar_capture_map.borrow()[upvar_id].clone(); + let upvar_capture = tcx.upvar_capture_map.borrow().get(&upvar_id).unwrap().clone(); var_id.encode(rbml_w); upvar_capture.encode(rbml_w); }) diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 496c96c7c8a..97cd9456098 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -874,7 +874,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], } ast::PatEnum(_, ref args) => { - let def = cx.tcx.def_map.borrow()[pat_id].full_def(); + let def = cx.tcx.def_map.borrow().get(&pat_id).unwrap().full_def(); match def { DefConst(..) => cx.tcx.sess.span_bug(pat_span, "const pattern should've \ @@ -892,7 +892,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat], ast::PatStruct(_, ref pattern_fields, _) => { // Is this a struct or an enum variant? - let def = cx.tcx.def_map.borrow()[pat_id].full_def(); + let def = cx.tcx.def_map.borrow().get(&pat_id).unwrap().full_def(); let class_id = match def { DefConst(..) => cx.tcx.sess.span_bug(pat_span, "const pattern should've \ diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 96433729a9b..f9598237ff4 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -150,7 +150,7 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P ast::PatTup(exprs.iter().map(|expr| const_expr_to_pat(tcx, &**expr, span)).collect()), ast::ExprCall(ref callee, ref args) => { - let def = tcx.def_map.borrow()[callee.id]; + let def = *tcx.def_map.borrow().get(&callee.id).unwrap(); if let Vacant(entry) = tcx.def_map.borrow_mut().entry(expr.id) { entry.insert(def); } diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 5efea66ab0c..6d4d759476e 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -158,7 +158,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { fn handle_field_pattern_match(&mut self, lhs: &ast::Pat, pats: &[codemap::Spanned]) { - let id = match self.tcx.def_map.borrow()[lhs.id].full_def() { + let id = match self.tcx.def_map.borrow().get(&lhs.id).unwrap().full_def() { def::DefVariant(_, id, _) => id, _ => { match ty::ty_to_def_id(ty::node_id_to_type(self.tcx, @@ -496,7 +496,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> { None => (), Some(impl_list) => { for impl_did in &**impl_list { - for item_did in &(*impl_items)[*impl_did] { + for item_did in &*impl_items.get(impl_did).unwrap() { if self.live_symbols.contains(&item_did.def_id() .node) { return true; diff --git a/src/librustc/middle/effect.rs b/src/librustc/middle/effect.rs index 378f3db0823..5d970c59f63 100644 --- a/src/librustc/middle/effect.rs +++ b/src/librustc/middle/effect.rs @@ -141,7 +141,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> { match expr.node { ast::ExprMethodCall(_, _, _) => { let method_call = MethodCall::expr(expr.id); - let base_type = (*self.tcx.method_map.borrow())[method_call].ty; + let base_type = self.tcx.method_map.borrow().get(&method_call).unwrap().ty; debug!("effect: method call case, base type is {}", ppaux::ty_to_string(self.tcx, base_type)); if type_is_unsafe_function(base_type) { diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 975bf01fdef..97314b57ef6 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -1012,7 +1012,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> { // Each match binding is effectively an assignment to the // binding being produced. - let def = def_map.borrow()[pat.id].full_def(); + let def = def_map.borrow().get(&pat.id).unwrap().full_def(); match mc.cat_def(pat.id, pat.span, pat_ty, def) { Ok(binding_cmt) => { delegate.mutate(pat.id, pat.span, binding_cmt, Init); diff --git a/src/librustc/middle/infer/region_inference/mod.rs b/src/librustc/middle/infer/region_inference/mod.rs index 759d7357df1..553e3601806 100644 --- a/src/librustc/middle/infer/region_inference/mod.rs +++ b/src/librustc/middle/infer/region_inference/mod.rs @@ -1533,7 +1533,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { ConstrainVarSubReg(_, region) => { state.result.push(RegionAndOrigin { region: region, - origin: this.constraints.borrow()[edge.data].clone() + origin: this.constraints.borrow().get(&edge.data).unwrap().clone() }); } } diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 932c9c61ef1..705f20559af 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -448,7 +448,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) { match expr.node { // live nodes required for uses or definitions of variables: ast::ExprPath(..) => { - let def = ir.tcx.def_map.borrow()[expr.id].full_def(); + let def = ir.tcx.def_map.borrow().get(&expr.id).unwrap().full_def(); debug!("expr {}: path that leads to {:?}", expr.id, def); if let DefLocal(..) = def { ir.add_live_node_for_node(expr.id, ExprNode(expr.span)); @@ -1302,7 +1302,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { fn access_path(&mut self, expr: &Expr, succ: LiveNode, acc: u32) -> LiveNode { - match self.ir.tcx.def_map.borrow()[expr.id].full_def() { + match self.ir.tcx.def_map.borrow().get(&expr.id).unwrap().full_def() { DefLocal(nid) => { let ln = self.live_node(expr.id, expr.span); if acc != 0 { @@ -1564,7 +1564,9 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { fn check_lvalue(&mut self, expr: &Expr) { match expr.node { ast::ExprPath(..) => { - if let DefLocal(nid) = self.ir.tcx.def_map.borrow()[expr.id].full_def() { + if let DefLocal(nid) = self.ir.tcx.def_map.borrow().get(&expr.id) + .unwrap() + .full_def() { // Assignment to an immutable variable or argument: only legal // if there is no later assignment. If this local is actually // mutable, then check for a reassignment to flag the mutability diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 5237a86ebb6..bdcfc67f92b 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -531,7 +531,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { } ast::ExprPath(..) => { - let def = self.tcx().def_map.borrow()[expr.id].full_def(); + let def = self.tcx().def_map.borrow().get(&expr.id).unwrap().full_def(); self.cat_def(expr.id, expr.span, expr_ty, def) } diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 7ded344414c..1bd45b5fc86 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -128,7 +128,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ReachableContext<'a, 'tcx> { } ast::ExprMethodCall(..) => { let method_call = ty::MethodCall::expr(expr.id); - match (*self.tcx.method_map.borrow())[method_call].origin { + match (*self.tcx.method_map.borrow()).get(&method_call).unwrap().origin { ty::MethodStatic(def_id) => { if is_local(def_id) { if self.def_id_represents_local_inlined_item(def_id) { diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 01766b0de08..d12b737619c 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -319,7 +319,7 @@ pub fn check_item(tcx: &ty::ctxt, item: &ast::Item, warn_about_defns: bool, // individually as it's possible to have a stable trait with unstable // items. ast::ItemImpl(_, _, _, Some(ref t), _, ref impl_items) => { - let trait_did = tcx.def_map.borrow()[t.ref_id].def_id(); + let trait_did = tcx.def_map.borrow().get(&t.ref_id).unwrap().def_id(); let trait_items = ty::trait_items(tcx, trait_did); for impl_item in impl_items { diff --git a/src/librustc/middle/traits/project.rs b/src/librustc/middle/traits/project.rs index 6b66d7227d3..a9504910ac1 100644 --- a/src/librustc/middle/traits/project.rs +++ b/src/librustc/middle/traits/project.rs @@ -854,10 +854,10 @@ fn confirm_impl_candidate<'cx,'tcx>( let impl_items_map = selcx.tcx().impl_items.borrow(); let impl_or_trait_items_map = selcx.tcx().impl_or_trait_items.borrow(); - let impl_items = &impl_items_map[impl_vtable.impl_def_id]; + let impl_items = impl_items_map.get(&impl_vtable.impl_def_id).unwrap(); let mut impl_ty = None; for impl_item in impl_items { - let assoc_type = match impl_or_trait_items_map[impl_item.def_id()] { + let assoc_type = match *impl_or_trait_items_map.get(&impl_item.def_id()).unwrap() { ty::TypeTraitItem(ref assoc_type) => assoc_type.clone(), ty::MethodTraitItem(..) => { continue; } }; diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 99c35c6e542..5088b733c4a 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -2667,7 +2667,7 @@ impl<'tcx> ctxt<'tcx> { } pub fn closure_kind(&self, def_id: ast::DefId) -> ty::ClosureKind { - self.closure_kinds.borrow()[def_id] + *self.closure_kinds.borrow().get(&def_id).unwrap() } pub fn closure_type(&self, @@ -2675,14 +2675,14 @@ impl<'tcx> ctxt<'tcx> { substs: &subst::Substs<'tcx>) -> ty::ClosureTy<'tcx> { - self.closure_tys.borrow()[def_id].subst(self, substs) + self.closure_tys.borrow().get(&def_id).unwrap().subst(self, substs) } pub fn type_parameter_def(&self, node_id: ast::NodeId) -> TypeParameterDef<'tcx> { - self.ty_param_defs.borrow()[node_id].clone() + self.ty_param_defs.borrow().get(&node_id).unwrap().clone() } } @@ -6540,7 +6540,7 @@ impl<'tcx> ctxt<'tcx> { } pub fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option { - Some(self.upvar_capture_map.borrow()[upvar_id].clone()) + Some(self.upvar_capture_map.borrow().get(&upvar_id).unwrap().clone()) } } diff --git a/src/librustc_borrowck/borrowck/move_data.rs b/src/librustc_borrowck/borrowck/move_data.rs index 8846f70fbd3..2834fce5278 100644 --- a/src/librustc_borrowck/borrowck/move_data.rs +++ b/src/librustc_borrowck/borrowck/move_data.rs @@ -486,7 +486,7 @@ impl<'tcx> MoveData<'tcx> { match path.loan_path.kind { LpVar(..) | LpUpvar(..) | LpDowncast(..) => { let kill_scope = path.loan_path.kill_scope(tcx); - let path = self.path_map.borrow()[path.loan_path]; + let path = *self.path_map.borrow().get(&path.loan_path).unwrap(); self.kill_moves(path, kill_scope.node_id(), dfcx_moves); } LpExtend(..) => {} diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index f6f82c65374..f788a02adc4 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -418,7 +418,7 @@ struct ImproperCTypesVisitor<'a, 'tcx: 'a> { impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { fn check_def(&mut self, sp: Span, id: ast::NodeId) { - match self.cx.tcx.def_map.borrow()[id].full_def() { + match self.cx.tcx.def_map.borrow().get(&id).unwrap().full_def() { def::DefPrimTy(ast::TyInt(ast::TyIs(_))) => { self.cx.span_lint(IMPROPER_CTYPES, sp, "found rust type `isize` in foreign module, while \ diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index bfce2f0062d..2e7fe91365a 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -253,7 +253,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> { ast::ItemImpl(_, _, _, _, ref ty, ref impl_items) => { let public_ty = match ty.node { ast::TyPath(..) => { - match self.tcx.def_map.borrow()[ty.id].full_def() { + match self.tcx.def_map.borrow().get(&ty.id).unwrap().full_def() { def::DefPrimTy(..) => true, def => { let did = def.def_id(); @@ -317,7 +317,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> { ast::ItemTy(ref ty, _) if public_first => { if let ast::TyPath(..) = ty.node { - match self.tcx.def_map.borrow()[ty.id].full_def() { + match self.tcx.def_map.borrow().get(&ty.id).unwrap().full_def() { def::DefPrimTy(..) | def::DefTyParam(..) => {}, def => { let did = def.def_id(); @@ -349,7 +349,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> { // crate module gets processed as well. if self.prev_exported { assert!(self.export_map.contains_key(&id), "wut {}", id); - for export in &self.export_map[id] { + for export in self.export_map.get(&id).unwrap() { if is_local(export.def_id) { self.reexports.insert(export.def_id.node); } @@ -525,7 +525,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> { // if we've reached the root, then everything was allowable and this // access is public. if closest_private_id == ast::CRATE_NODE_ID { return Allowable } - closest_private_id = self.parents[closest_private_id]; + closest_private_id = *self.parents.get(&closest_private_id).unwrap(); // If we reached the top, then we were public all the way down and // we can allow this access. @@ -543,7 +543,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> { /// whether the node is accessible by the current module that iteration is /// inside. fn private_accessible(&self, id: ast::NodeId) -> bool { - let parent = self.parents[id]; + let parent = *self.parents.get(&id).unwrap(); debug!("privacy - accessible parent {}", self.nodestr(parent)); // After finding `did`'s closest private member, we roll ourselves back @@ -567,7 +567,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> { _ => {} } - cur = self.parents[cur]; + cur = *self.parents.get(&cur).unwrap(); } } @@ -622,7 +622,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> { ast::TyPath(..) => {} _ => return Some((err_span, err_msg, None)), }; - let def = self.tcx.def_map.borrow()[ty.id].full_def(); + let def = self.tcx.def_map.borrow().get(&ty.id).unwrap().full_def(); let did = def.def_id(); assert!(is_local(did)); match self.tcx.map.get(did.node) { @@ -708,7 +708,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> { // Checks that a path is in scope. fn check_path(&mut self, span: Span, path_id: ast::NodeId, last: ast::Ident) { debug!("privacy - path {}", self.nodestr(path_id)); - let path_res = self.tcx.def_map.borrow()[path_id]; + let path_res = *self.tcx.def_map.borrow().get(&path_id).unwrap(); let ck = |tyname: &str| { let ck_public = |def: ast::DefId| { debug!("privacy - ck_public {:?}", def); @@ -881,7 +881,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> { } } ty::ty_enum(_, _) => { - match self.tcx.def_map.borrow()[expr.id].full_def() { + match self.tcx.def_map.borrow().get(&expr.id).unwrap().full_def() { def::DefVariant(_, variant_id, _) => { for field in fields { self.check_field(expr.span, variant_id, diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index 34a23f3efac..679f1ce79b2 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -1141,9 +1141,9 @@ fn add_upstream_rust_crates(cmd: &mut Command, sess: &Session, // involves just passing the right -l flag. let data = if dylib { - &trans.crate_formats[config::CrateTypeDylib] + trans.crate_formats.get(&config::CrateTypeDylib).unwrap() } else { - &trans.crate_formats[config::CrateTypeExecutable] + trans.crate_formats.get(&config::CrateTypeExecutable).unwrap() }; // Invoke get_used_crates to ensure that we get a topological sorting of diff --git a/src/librustc_trans/save/mod.rs b/src/librustc_trans/save/mod.rs index 83bb5efb425..6a55d6d4adf 100644 --- a/src/librustc_trans/save/mod.rs +++ b/src/librustc_trans/save/mod.rs @@ -219,7 +219,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { self.sess.bug(&format!("def_map has no key for {} in lookup_type_ref", ref_id)); } - let def = self.analysis.ty_cx.def_map.borrow()[ref_id].full_def(); + let def = self.analysis.ty_cx.def_map.borrow().get(&ref_id).unwrap().full_def(); match def { def::DefPrimTy(_) => None, _ => Some(def.def_id()), @@ -232,7 +232,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { self.sess.span_bug(span, &format!("def_map has no key for {} in lookup_def_kind", ref_id)); } - let def = def_map[ref_id].full_def(); + let def = def_map.get(&ref_id).unwrap().full_def(); match def { def::DefMod(_) | def::DefForeignMod(_) => Some(recorder::ModRef), @@ -269,8 +269,10 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { self.collecting = false; let span_utils = self.span.clone(); for &(id, ref p, _, _) in &self.collected_paths { - let typ = ppaux::ty_to_string(&self.analysis.ty_cx, - (*self.analysis.ty_cx.node_types.borrow())[id]); + let typ = + ppaux::ty_to_string( + &self.analysis.ty_cx, + *self.analysis.ty_cx.node_types.borrow().get(&id).unwrap()); // get the span only for the name of the variable (I hope the path is only ever a // variable name, but who knows?) self.fmt.formal_str(p.span, @@ -431,8 +433,10 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { ast::NamedField(ident, _) => { let name = get_ident(ident); let qualname = format!("{}::{}", qualname, name); - let typ = ppaux::ty_to_string(&self.analysis.ty_cx, - (*self.analysis.ty_cx.node_types.borrow())[field.node.id]); + let typ = + ppaux::ty_to_string( + &self.analysis.ty_cx, + *self.analysis.ty_cx.node_types.borrow().get(&field.node.id).unwrap()); match self.span.sub_span_before_token(field.span, token::Colon) { Some(sub_span) => self.fmt.field_str(field.span, Some(sub_span), @@ -789,7 +793,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { self.sess.span_bug(span, &format!("def_map has no key for {} in visit_expr", id)); } - let def = def_map[id].full_def(); + let def = def_map.get(&id).unwrap().full_def(); let sub_span = self.span.span_for_last_ident(span); match def { def::DefUpvar(..) | @@ -832,7 +836,8 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { .ty_cx .impl_items .borrow(); - Some((*impl_items)[def_id] + Some(impl_items.get(&def_id) + .unwrap() .iter() .find(|mr| { ty::impl_or_trait_item( @@ -941,7 +946,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { ex: &ast::Expr, args: &Vec>) { let method_map = self.analysis.ty_cx.method_map.borrow(); - let method_callee = &(*method_map)[ty::MethodCall::expr(ex.id)]; + let method_callee = method_map.get(&ty::MethodCall::expr(ex.id)).unwrap(); let (def_id, decl_id) = match method_callee.origin { ty::MethodStatic(def_id) | ty::MethodStaticClosure(def_id) => { @@ -1001,7 +1006,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { self.collected_paths.push((p.id, path.clone(), false, recorder::StructRef)); visit::walk_path(self, path); - let def = self.analysis.ty_cx.def_map.borrow()[p.id].full_def(); + let def = self.analysis.ty_cx.def_map.borrow().get(&p.id).unwrap().full_def(); let struct_def = match def { def::DefConst(..) => None, def::DefVariant(_, variant_id, _) => Some(variant_id), @@ -1113,7 +1118,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { let glob_map = &self.analysis.glob_map; let glob_map = glob_map.as_ref().unwrap(); if glob_map.contains_key(&item.id) { - for n in &glob_map[item.id] { + for n in glob_map.get(&item.id).unwrap() { if name_string.len() > 0 { name_string.push_str(", "); } @@ -1406,7 +1411,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { &format!("def_map has no key for {} in visit_arm", id)); } - let def = def_map[id].full_def(); + let def = def_map.get(&id).unwrap().full_def(); match def { def::DefLocal(id) => { let value = if *immut { @@ -1467,7 +1472,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { for &(id, ref p, ref immut, _) in &self.collected_paths { let value = if *immut { value.to_string() } else { "".to_string() }; let types = self.analysis.ty_cx.node_types.borrow(); - let typ = ppaux::ty_to_string(&self.analysis.ty_cx, (*types)[id]); + let typ = ppaux::ty_to_string(&self.analysis.ty_cx, *types.get(&id).unwrap()); // Get the span only for the name of the variable (I hope the path // is only ever a variable name, but who knows?). let sub_span = self.span.span_for_last_ident(p.span); diff --git a/src/librustc_trans/trans/_match.rs b/src/librustc_trans/trans/_match.rs index c08d3b2be53..eb759393ac6 100644 --- a/src/librustc_trans/trans/_match.rs +++ b/src/librustc_trans/trans/_match.rs @@ -1017,7 +1017,7 @@ fn compile_submatch<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, None => { let data = &m[0].data; for &(ref ident, ref value_ptr) in &m[0].bound_ptrs { - let binfo = data.bindings_map[*ident]; + let binfo = *data.bindings_map.get(ident).unwrap(); call_lifetime_start(bcx, binfo.llmatch); if binfo.trmode == TrByRef && type_is_fat_ptr(bcx.tcx(), binfo.ty) { expr::copy_fat_ptr(bcx, *value_ptr, binfo.llmatch); diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index ebd92faaf0f..bdc810bd837 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -269,7 +269,7 @@ pub fn self_type_for_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, } pub fn kind_for_closure(ccx: &CrateContext, closure_id: ast::DefId) -> ty::ClosureKind { - ccx.tcx().closure_kinds.borrow()[closure_id] + *ccx.tcx().closure_kinds.borrow().get(&closure_id).unwrap() } pub fn decl_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, @@ -2322,7 +2322,7 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) { static"); } - let v = ccx.static_values().borrow()[item.id].clone(); + let v = ccx.static_values().borrow().get(&item.id).unwrap().clone(); unsafe { if !(llvm::LLVMConstIntGetZExtValue(v) != 0) { ccx.sess().span_fatal(expr.span, "static assertion failed"); diff --git a/src/librustc_trans/trans/callee.rs b/src/librustc_trans/trans/callee.rs index cf36ec1f3ed..088a34857e7 100644 --- a/src/librustc_trans/trans/callee.rs +++ b/src/librustc_trans/trans/callee.rs @@ -511,7 +511,7 @@ pub fn trans_fn_ref_with_substs<'a, 'tcx>( let ref_ty = match node { ExprId(id) => ty::node_id_to_type(tcx, id), MethodCallKey(method_call) => { - (*tcx.method_map.borrow())[method_call].ty + tcx.method_map.borrow().get(&method_call).unwrap().ty } }; let ref_ty = monomorphize::apply_param_substs(tcx, diff --git a/src/librustc_trans/trans/common.rs b/src/librustc_trans/trans/common.rs index 8f5dbfe2ec0..8754d50597b 100644 --- a/src/librustc_trans/trans/common.rs +++ b/src/librustc_trans/trans/common.rs @@ -709,7 +709,7 @@ impl<'blk, 'tcx> mc::Typer<'tcx> for BlockS<'blk, 'tcx> { } fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option { - Some(self.tcx().upvar_capture_map.borrow()[upvar_id].clone()) + Some(self.tcx().upvar_capture_map.borrow().get(&upvar_id).unwrap().clone()) } fn type_moves_by_default(&self, span: Span, ty: Ty<'tcx>) -> bool { @@ -1213,7 +1213,7 @@ pub fn node_id_substs<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty::node_id_item_substs(tcx, id).substs } MethodCallKey(method_call) => { - (*tcx.method_map.borrow())[method_call].substs.clone() + tcx.method_map.borrow().get(&method_call).unwrap().substs.clone() } }; diff --git a/src/librustc_trans/trans/consts.rs b/src/librustc_trans/trans/consts.rs index 2a3fcd66195..f0947cd4712 100644 --- a/src/librustc_trans/trans/consts.rs +++ b/src/librustc_trans/trans/consts.rs @@ -187,7 +187,7 @@ pub fn get_const_expr_as_global<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, // Special-case constants to cache a common global for all uses. match expr.node { ast::ExprPath(..) => { - let def = ccx.tcx().def_map.borrow()[expr.id].full_def(); + let def = ccx.tcx().def_map.borrow().get(&expr.id).unwrap().full_def(); match def { def::DefConst(def_id) => { if !ccx.tcx().adjustments.borrow().contains_key(&expr.id) { @@ -665,7 +665,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, } } ast::ExprPath(..) => { - let def = cx.tcx().def_map.borrow()[e.id].full_def(); + let def = cx.tcx().def_map.borrow().get(&e.id).unwrap().full_def(); match def { def::DefFn(..) | def::DefMethod(..) => { expr::trans_def_fn_unadjusted(cx, e, def, param_substs).val @@ -751,7 +751,7 @@ pub fn trans_static(ccx: &CrateContext, m: ast::Mutability, id: ast::NodeId) { let g = base::get_item_val(ccx, id); // At this point, get_item_val has already translated the // constant's initializer to determine its LLVM type. - let v = ccx.static_values().borrow()[id].clone(); + let v = ccx.static_values().borrow().get(&id).unwrap().clone(); // boolean SSA values are i1, but they have to be stored in i8 slots, // otherwise some LLVM optimization passes don't work as expected let v = if llvm::LLVMTypeOf(v) == Type::i1(ccx).to_ref() { diff --git a/src/librustc_trans/trans/expr.rs b/src/librustc_trans/trans/expr.rs index 4aff28122bb..28ac7da3cfc 100644 --- a/src/librustc_trans/trans/expr.rs +++ b/src/librustc_trans/trans/expr.rs @@ -126,7 +126,7 @@ pub fn trans_into<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, return datum.store_to_dest(bcx, dest, expr.id); } - let qualif = bcx.tcx().const_qualif_map.borrow()[expr.id]; + let qualif = *bcx.tcx().const_qualif_map.borrow().get(&expr.id).unwrap(); if !qualif.intersects(check_const::NOT_CONST | check_const::NEEDS_DROP) { if !qualif.intersects(check_const::PREFER_IN_PLACE) { if let SaveIn(lldest) = dest { @@ -209,7 +209,7 @@ pub fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, let mut bcx = bcx; let fcx = bcx.fcx; - let qualif = bcx.tcx().const_qualif_map.borrow()[expr.id]; + let qualif = *bcx.tcx().const_qualif_map.borrow().get(&expr.id).unwrap(); let adjusted_global = !qualif.intersects(check_const::NON_STATIC_BORROWS); let global = if !qualif.intersects(check_const::NOT_CONST | check_const::NEEDS_DROP) { let global = consts::get_const_expr_as_global(bcx.ccx(), expr, qualif, @@ -1405,7 +1405,7 @@ pub fn with_field_tys<'tcx, R, F>(tcx: &ty::ctxt<'tcx>, ty.repr(tcx))); } Some(node_id) => { - let def = tcx.def_map.borrow()[node_id].full_def(); + let def = tcx.def_map.borrow().get(&node_id).unwrap().full_def(); match def { def::DefVariant(enum_id, variant_id, _) => { let variant_info = ty::enum_variant_with_id(tcx, enum_id, variant_id); @@ -1961,7 +1961,7 @@ fn trans_overloaded_op<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, dest: Option, autoref: bool) -> Result<'blk, 'tcx> { - let method_ty = (*bcx.tcx().method_map.borrow())[method_call].ty; + let method_ty = bcx.tcx().method_map.borrow().get(&method_call).unwrap().ty; callee::trans_call_inner(bcx, expr.debug_loc(), monomorphize_type(bcx, method_ty), @@ -1982,10 +1982,12 @@ fn trans_overloaded_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, dest: Option) -> Block<'blk, 'tcx> { let method_call = MethodCall::expr(expr.id); - let method_type = (*bcx.tcx() - .method_map - .borrow())[method_call] - .ty; + let method_type = bcx.tcx() + .method_map + .borrow() + .get(&method_call) + .unwrap() + .ty; let mut all_args = vec!(callee); all_args.extend(args.iter().map(|e| &**e)); unpack_result!(bcx, diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 28e7027b212..71900855266 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1046,7 +1046,7 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx>, return (tcx.types.err, ty_path_def); }; - let ty_param_name = tcx.ty_param_defs.borrow()[ty_param_node_id].name; + let ty_param_name = tcx.ty_param_defs.borrow().get(&ty_param_node_id).unwrap().name; let bounds = match this.get_type_parameter_bounds(span, ty_param_node_id) { Ok(v) => v, diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index 8e2f4dcefa0..e71386a9b42 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -119,7 +119,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, demand::eqtype(fcx, pat.span, expected, lhs_ty); } ast::PatEnum(..) | ast::PatIdent(..) if pat_is_const(&tcx.def_map, pat) => { - let const_did = tcx.def_map.borrow()[pat.id].def_id(); + let const_did = tcx.def_map.borrow().get(&pat.id).unwrap().def_id(); let const_scheme = ty::lookup_item_type(tcx, const_did); assert!(const_scheme.generics.is_empty()); let const_ty = pcx.fcx.instantiate_type_scheme(pat.span, @@ -163,7 +163,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, // if there are multiple arms, make sure they all agree on // what the type of the binding `x` ought to be - let canon_id = pcx.map[path.node]; + let canon_id = *pcx.map.get(&path.node).unwrap(); if canon_id != pat.id { let ct = fcx.local_ty(pat.span, canon_id); demand::eqtype(fcx, pat.span, ct, typ); @@ -449,7 +449,7 @@ pub fn check_pat_struct<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, pat: &'tcx ast::Pat, let fcx = pcx.fcx; let tcx = pcx.fcx.ccx.tcx; - let def = tcx.def_map.borrow()[pat.id].full_def(); + let def = tcx.def_map.borrow().get(&pat.id).unwrap().full_def(); let (enum_def_id, variant_def_id) = match def { def::DefTrait(_) => { let name = pprust::path_to_string(path); @@ -518,7 +518,7 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, let fcx = pcx.fcx; let tcx = pcx.fcx.ccx.tcx; - let def = tcx.def_map.borrow()[pat.id].full_def(); + let def = tcx.def_map.borrow().get(&pat.id).unwrap().full_def(); let enum_def = def.variant_def_ids() .map_or_else(|| def.def_id(), |(enum_def, _)| enum_def); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 45d4a1edc6b..f319adac1a1 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -368,7 +368,7 @@ impl<'a, 'tcx> ty::ClosureTyper<'tcx> for FnCtxt<'a, 'tcx> { substs: &subst::Substs<'tcx>) -> ty::ClosureTy<'tcx> { - self.inh.closure_tys.borrow()[def_id].subst(self.tcx(), substs) + self.inh.closure_tys.borrow().get(&def_id).unwrap().subst(self.tcx(), substs) } fn closure_upvars(&self, @@ -549,7 +549,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> { debug!("Local variable {} is assigned type {}", self.fcx.pat_to_string(&*local.pat), self.fcx.infcx().ty_to_string( - self.fcx.inh.locals.borrow()[local.id].clone())); + self.fcx.inh.locals.borrow().get(&local.id).unwrap().clone())); visit::walk_local(self, local); } @@ -565,7 +565,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> { debug!("Pattern binding {} is assigned to {} with type {}", token::get_ident(path1.node), self.fcx.infcx().ty_to_string( - self.fcx.inh.locals.borrow()[p.id].clone()), + self.fcx.inh.locals.borrow().get(&p.id).unwrap().clone()), var_ty.repr(self.fcx.tcx())); } } @@ -3327,7 +3327,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>, let mut missing_fields = Vec::new(); for class_field in field_types { let name = class_field.name; - let (_, seen) = class_field_map[name]; + let (_, seen) = *class_field_map.get(&name).unwrap(); if !seen { missing_fields.push( format!("`{}`", &token::get_name(name))) @@ -4428,7 +4428,7 @@ fn check_const<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, let inh = static_inherited_fields(ccx); let rty = ty::node_id_to_type(ccx.tcx, id); let fcx = blank_fn_ctxt(ccx, &inh, ty::FnConverging(rty), e.id); - let declty = (*fcx.ccx.tcx.tcache.borrow())[local_def(id)].ty; + let declty = fcx.ccx.tcx.tcache.borrow().get(&local_def(id)).unwrap().ty; check_const_with_ty(&fcx, sp, e, declty); } diff --git a/src/librustc_typeck/check/upvar.rs b/src/librustc_typeck/check/upvar.rs index ce4bb446551..340cca7d47e 100644 --- a/src/librustc_typeck/check/upvar.rs +++ b/src/librustc_typeck/check/upvar.rs @@ -448,7 +448,7 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx> { let closure_def_id = ast_util::local_def(closure_id); let mut closure_kinds = self.fcx.inh.closure_kinds.borrow_mut(); - let existing_kind = closure_kinds[closure_def_id]; + let existing_kind = *closure_kinds.get(&closure_def_id).unwrap(); debug!("adjust_closure_kind: closure_id={}, existing_kind={:?}, new_kind={:?}", closure_id, existing_kind, new_kind); diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index 6b0fb8ac71a..ffd99ff2eec 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -269,7 +269,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { fn get_self_type_for_implementation(&self, impl_did: DefId) -> TypeScheme<'tcx> { - self.crate_context.tcx.tcache.borrow()[impl_did].clone() + self.crate_context.tcx.tcache.borrow().get(&impl_did).unwrap().clone() } // Converts an implementation in the AST to a vector of items. @@ -387,7 +387,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { }; for &impl_did in &*trait_impls.borrow() { - let items = &(*impl_items)[impl_did]; + let items = impl_items.get(&impl_did).unwrap(); if items.len() < 1 { // We'll error out later. For now, just don't ICE. continue; diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 97cc3ac7c48..6be45b26751 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -194,7 +194,7 @@ impl<'a,'tcx> CrateCtxt<'a,'tcx> { fn method_ty(&self, method_id: ast::NodeId) -> Rc> { let def_id = local_def(method_id); - match self.tcx.impl_or_trait_items.borrow()[def_id] { + match *self.tcx.impl_or_trait_items.borrow().get(&def_id).unwrap() { ty::MethodTraitItem(ref mty) => mty.clone(), ty::TypeTraitItem(..) => { self.tcx.sess.bug(&format!("method with id {} has the wrong type", method_id)); @@ -545,7 +545,7 @@ fn is_param<'tcx>(tcx: &ty::ctxt<'tcx>, -> bool { if let ast::TyPath(None, _) = ast_ty.node { - let path_res = tcx.def_map.borrow()[ast_ty.id]; + let path_res = *tcx.def_map.borrow().get(&ast_ty.id).unwrap(); match path_res.base_def { def::DefSelfTy(node_id) => path_res.depth == 0 && node_id == param_id, @@ -1040,9 +1040,13 @@ fn convert_struct<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, tcx.predicates.borrow_mut().insert(local_def(ctor_id), predicates); } else if struct_def.fields[0].node.kind.is_unnamed() { // Tuple-like. - let inputs: Vec<_> = struct_def.fields.iter().map( - |field| (*tcx.tcache.borrow())[ - local_def(field.node.id)].ty).collect(); + let inputs: Vec<_> = + struct_def.fields + .iter() + .map(|field| tcx.tcache.borrow().get(&local_def(field.node.id)) + .unwrap() + .ty) + .collect(); let ctor_fn_ty = ty::mk_ctor_fn(tcx, local_def(ctor_id), &inputs[..], diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 03a2d708ee4..4d15abb91dc 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -290,7 +290,7 @@ fn resolved_path(w: &mut fmt::Formatter, did: ast::DefId, p: &clean::Path, if ast_util::is_local(did) || cache.inlined.contains(&did) { Some(repeat("../").take(loc.len()).collect::()) } else { - match cache.extern_locations[did.krate] { + match cache.extern_locations[&did.krate] { render::Remote(ref s) => Some(s.to_string()), render::Local => { Some(repeat("../").take(loc.len()).collect::()) @@ -404,11 +404,11 @@ fn primitive_link(f: &mut fmt::Formatter, needs_termination = true; } Some(&cnum) => { - let path = &m.paths[ast::DefId { + let path = &m.paths[&ast::DefId { krate: cnum, node: ast::CRATE_NODE_ID, }]; - let loc = match m.extern_locations[cnum] { + let loc = match m.extern_locations[&cnum] { render::Remote(ref s) => Some(s.to_string()), render::Local => { let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len()); diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 81daac7b90f..5ceb0238aa0 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1404,8 +1404,8 @@ impl<'a> Item<'a> { // located, then we return `None`. } else { let cache = cache(); - let path = &cache.external_paths[self.item.def_id]; - let root = match cache.extern_locations[self.item.def_id.krate] { + let path = &cache.external_paths[&self.item.def_id]; + let root = match cache.extern_locations[&self.item.def_id.krate] { Remote(ref s) => s.to_string(), Local => self.cx.root_path.clone(), Unknown => return None, @@ -1863,7 +1863,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, path = if ast_util::is_local(it.def_id) { cx.current.connect("/") } else { - let path = &cache.external_paths[it.def_id]; + let path = &cache.external_paths[&it.def_id]; path[..path.len() - 1].connect("/") }, ty = shortty(it).to_static_str(), diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index d53954b29b5..11e10cc2aa7 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -196,7 +196,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { Some(tcx) => tcx, None => return false }; - let def = tcx.def_map.borrow()[id].def_id(); + let def = tcx.def_map.borrow()[&id].def_id(); if !ast_util::is_local(def) { return false } let analysis = match self.analysis { Some(analysis) => analysis, None => return false diff --git a/src/libstd/thread_local/mod.rs b/src/libstd/thread_local/mod.rs index 08780292c88..b2fd8a8e616 100644 --- a/src/libstd/thread_local/mod.rs +++ b/src/libstd/thread_local/mod.rs @@ -745,7 +745,7 @@ mod dynamic_tests { thread_local!(static FOO: RefCell> = map()); FOO.with(|map| { - assert_eq!(map.borrow()[1], 2); + assert_eq!(map.borrow()[&1], 2); }); } diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index 0eaca9af4f0..2fe77bf7a54 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -513,7 +513,7 @@ impl<'a, 'b> Context<'a, 'b> { let lname = self.ecx.ident_of(&format!("__arg{}", *name)); pats.push(self.ecx.pat_ident(e.span, lname)); - names[self.name_positions[*name]] = + names[*self.name_positions.get(name).unwrap()] = Some(Context::format_arg(self.ecx, e.span, arg_ty, self.ecx.expr_ident(e.span, lname))); heads.push(self.ecx.expr_addr_of(e.span, e)); diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 7a2ae55e914..5940b791843 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -236,7 +236,7 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt, argument_gram); // Extract the arguments: - let lhses = match *argument_map[lhs_nm] { + let lhses = match **argument_map.get(&lhs_nm).unwrap() { MatchedSeq(ref s, _) => /* FIXME (#2543) */ (*s).clone(), _ => cx.span_bug(def.span, "wrong-structured lhs") }; @@ -245,7 +245,7 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt, check_lhs_nt_follows(cx, &**lhs, def.span); } - let rhses = match *argument_map[rhs_nm] { + let rhses = match **argument_map.get(&rhs_nm).unwrap() { MatchedSeq(ref s, _) => /* FIXME (#2543) */ (*s).clone(), _ => cx.span_bug(def.span, "wrong-structured rhs") }; diff --git a/src/test/auxiliary/issue-2631-a.rs b/src/test/auxiliary/issue-2631-a.rs index dd1ad413a3d..604a3e69a21 100644 --- a/src/test/auxiliary/issue-2631-a.rs +++ b/src/test/auxiliary/issue-2631-a.rs @@ -19,6 +19,6 @@ pub type header_map = HashMap>>>>; // the unused ty param is necessary so this gets monomorphized pub fn request(req: &header_map) { - let data = req["METHOD".to_string()].clone(); + let data = req[&"METHOD".to_string()].clone(); let _x = data.borrow().clone()[0].clone(); } diff --git a/src/test/auxiliary/procedural_mbe_matching.rs b/src/test/auxiliary/procedural_mbe_matching.rs index d9a2b06e039..18db50a831c 100644 --- a/src/test/auxiliary/procedural_mbe_matching.rs +++ b/src/test/auxiliary/procedural_mbe_matching.rs @@ -33,7 +33,7 @@ fn expand_mbe_matches(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree]) let mac_expr = match TokenTree::parse(cx, &mbe_matcher[..], args) { Success(map) => { - match (&*map[str_to_ident("matched")], &*map[str_to_ident("pat")]) { + match (&*map[&str_to_ident("matched")], &*map[&str_to_ident("pat")]) { (&MatchedNonterminal(NtExpr(ref matched_expr)), &MatchedSeq(ref pats, seq_sp)) => { let pats: Vec> = pats.iter().map(|pat_nt| diff --git a/src/test/compile-fail/borrowck-overloaded-index-and-overloaded-deref.rs b/src/test/compile-fail/borrowck-overloaded-index-and-overloaded-deref.rs index 430f2fcc13a..bee56c9bf39 100644 --- a/src/test/compile-fail/borrowck-overloaded-index-and-overloaded-deref.rs +++ b/src/test/compile-fail/borrowck-overloaded-index-and-overloaded-deref.rs @@ -19,7 +19,7 @@ struct MyVec { x: T } impl Index for MyVec { type Output = T; - fn index(&self, _: &usize) -> &T { + fn index(&self, _: usize) -> &T { &self.x } } diff --git a/src/test/compile-fail/borrowck-overloaded-index-autoderef.rs b/src/test/compile-fail/borrowck-overloaded-index-autoderef.rs index 99f396ef814..55a6e2ac7b8 100644 --- a/src/test/compile-fail/borrowck-overloaded-index-autoderef.rs +++ b/src/test/compile-fail/borrowck-overloaded-index-autoderef.rs @@ -18,6 +18,7 @@ struct Foo { y: isize, } +#[cfg(stage0)] impl Index for Foo { type Output = isize; @@ -30,8 +31,20 @@ impl Index for Foo { } } -impl IndexMut for Foo { - fn index_mut<'a>(&'a mut self, z: &String) -> &'a mut isize { +impl<'a> Index<&'a String> for Foo { + type Output = isize; + + fn index(&self, z: &String) -> &isize { + if *z == "x" { + &self.x + } else { + &self.y + } + } +} + +impl<'a> IndexMut<&'a String> for Foo { + fn index_mut(&mut self, z: &String) -> &mut isize { if *z == "x" { &mut self.x } else { @@ -41,13 +54,13 @@ impl IndexMut for Foo { } fn test1(mut f: Box, s: String) { - let _p = &mut f[s]; - let _q = &f[s]; //~ ERROR cannot borrow + let _p = &mut f[&s]; + let _q = &f[&s]; //~ ERROR cannot borrow } fn test2(mut f: Box, s: String) { - let _p = &mut f[s]; - let _q = &mut f[s]; //~ ERROR cannot borrow + let _p = &mut f[&s]; + let _q = &mut f[&s]; //~ ERROR cannot borrow } struct Bar { @@ -55,37 +68,37 @@ struct Bar { } fn test3(mut f: Box, s: String) { - let _p = &mut f.foo[s]; - let _q = &mut f.foo[s]; //~ ERROR cannot borrow + let _p = &mut f.foo[&s]; + let _q = &mut f.foo[&s]; //~ ERROR cannot borrow } fn test4(mut f: Box, s: String) { - let _p = &f.foo[s]; - let _q = &f.foo[s]; + let _p = &f.foo[&s]; + let _q = &f.foo[&s]; } fn test5(mut f: Box, s: String) { - let _p = &f.foo[s]; - let _q = &mut f.foo[s]; //~ ERROR cannot borrow + let _p = &f.foo[&s]; + let _q = &mut f.foo[&s]; //~ ERROR cannot borrow } fn test6(mut f: Box, g: Foo, s: String) { - let _p = &f.foo[s]; + let _p = &f.foo[&s]; f.foo = g; //~ ERROR cannot assign } fn test7(mut f: Box, g: Bar, s: String) { - let _p = &f.foo[s]; + let _p = &f.foo[&s]; *f = g; //~ ERROR cannot assign } fn test8(mut f: Box, g: Foo, s: String) { - let _p = &mut f.foo[s]; + let _p = &mut f.foo[&s]; f.foo = g; //~ ERROR cannot assign } fn test9(mut f: Box, g: Bar, s: String) { - let _p = &mut f.foo[s]; + let _p = &mut f.foo[&s]; *f = g; //~ ERROR cannot assign } diff --git a/src/test/compile-fail/dst-index.rs b/src/test/compile-fail/dst-index.rs index 91f34320482..021ef7343cb 100644 --- a/src/test/compile-fail/dst-index.rs +++ b/src/test/compile-fail/dst-index.rs @@ -20,7 +20,7 @@ struct S; impl Index for S { type Output = str; - fn index<'a>(&'a self, _: &usize) -> &'a str { + fn index(&self, _: usize) -> &str { "hello" } } @@ -31,7 +31,7 @@ struct T; impl Index for T { type Output = Debug + 'static; - fn index<'a>(&'a self, idx: &usize) -> &'a (Debug + 'static) { + fn index<'a>(&'a self, idx: usize) -> &'a (Debug + 'static) { static x: usize = 42; &x } diff --git a/src/test/run-pass/dst-index.rs b/src/test/run-pass/dst-index.rs index 0c7ecfcefff..9539486118b 100644 --- a/src/test/run-pass/dst-index.rs +++ b/src/test/run-pass/dst-index.rs @@ -19,7 +19,7 @@ struct S; impl Index for S { type Output = str; - fn index<'a>(&'a self, _: &uint) -> &'a str { + fn index<'a>(&'a self, _: uint) -> &'a str { "hello" } } @@ -29,7 +29,7 @@ struct T; impl Index for T { type Output = Debug + 'static; - fn index<'a>(&'a self, idx: &uint) -> &'a (Debug + 'static) { + fn index<'a>(&'a self, idx: uint) -> &'a (Debug + 'static) { static X: uint = 42; &X as &(Debug + 'static) } diff --git a/src/test/run-pass/issue-15734.rs b/src/test/run-pass/issue-15734.rs index 18e4190ee45..76a5b6488b5 100644 --- a/src/test/run-pass/issue-15734.rs +++ b/src/test/run-pass/issue-15734.rs @@ -29,7 +29,7 @@ impl Mat { impl Index<(uint, uint)> for Mat { type Output = T; - fn index<'a>(&'a self, &(row, col): &(uint, uint)) -> &'a T { + fn index<'a>(&'a self, (row, col): (uint, uint)) -> &'a T { &self.data[row * self.cols + col] } } @@ -37,7 +37,7 @@ impl Index<(uint, uint)> for Mat { impl<'a, T> Index<(uint, uint)> for &'a Mat { type Output = T; - fn index<'b>(&'b self, index: &(uint, uint)) -> &'b T { + fn index<'b>(&'b self, index: (uint, uint)) -> &'b T { (*self).index(index) } } @@ -47,8 +47,8 @@ struct Row { mat: M, row: uint, } impl> Index for Row { type Output = T; - fn index<'a>(&'a self, col: &uint) -> &'a T { - &self.mat[(self.row, *col)] + fn index<'a>(&'a self, col: uint) -> &'a T { + &self.mat[(self.row, col)] } } @@ -56,7 +56,7 @@ fn main() { let m = Mat::new(vec!(1, 2, 3, 4, 5, 6), 3); let r = m.row(1); - assert!(r.index(&2) == &6); + assert!(r.index(2) == &6); assert!(r[2] == 6); assert!(r[2] == 6); assert!(6 == r[2]); diff --git a/src/test/run-pass/issue-2804-2.rs b/src/test/run-pass/issue-2804-2.rs index 4f89d28332a..b04ae0edbed 100644 --- a/src/test/run-pass/issue-2804-2.rs +++ b/src/test/run-pass/issue-2804-2.rs @@ -16,7 +16,7 @@ extern crate collections; use std::collections::HashMap; fn add_interfaces(managed_ip: String, device: HashMap) { - println!("{}, {}", managed_ip, device["interfaces".to_string()]); + println!("{}, {}", managed_ip, device["interfaces"]); } pub fn main() {} diff --git a/src/test/run-pass/issue-2804.rs b/src/test/run-pass/issue-2804.rs index b9b5aec62fc..619bd08141f 100644 --- a/src/test/run-pass/issue-2804.rs +++ b/src/test/run-pass/issue-2804.rs @@ -56,8 +56,7 @@ fn add_interface(_store: int, managed_ip: String, data: json::Json) -> (String, fn add_interfaces(store: int, managed_ip: String, device: HashMap) -> Vec<(String, object)> { - match device["interfaces".to_string()] - { + match device["interfaces"] { Json::Array(ref interfaces) => { interfaces.iter().map(|interface| { @@ -67,7 +66,7 @@ fn add_interfaces(store: int, managed_ip: String, device: HashMap { println!("Expected list for {} interfaces, found {}", managed_ip, - device["interfaces".to_string()]); + device["interfaces"]); Vec::new() } } diff --git a/src/test/run-pass/issue-5521.rs b/src/test/run-pass/issue-5521.rs index fb0e8e599eb..7016e28f2ee 100644 --- a/src/test/run-pass/issue-5521.rs +++ b/src/test/run-pass/issue-5521.rs @@ -17,7 +17,7 @@ fn bar(a: foo::map) { if false { panic!(); } else { - let _b = &(*a)[2]; + let _b = &(*a)[&2]; } } diff --git a/src/test/run-pass/issue-7660.rs b/src/test/run-pass/issue-7660.rs index 9e36b1f5082..78318e083ba 100644 --- a/src/test/run-pass/issue-7660.rs +++ b/src/test/run-pass/issue-7660.rs @@ -21,6 +21,6 @@ pub fn main() { let mut m: HashMap = HashMap::new(); m.insert(1, A(0, 0)); - let A(ref _a, ref _b) = m[1]; - let (a, b) = match m[1] { A(ref _a, ref _b) => (_a, _b) }; + let A(ref _a, ref _b) = m[&1]; + let (a, b) = match m[&1] { A(ref _a, ref _b) => (_a, _b) }; } diff --git a/src/test/run-pass/operator-overloading.rs b/src/test/run-pass/operator-overloading.rs index 3ddc666cd38..801e71b3038 100644 --- a/src/test/run-pass/operator-overloading.rs +++ b/src/test/run-pass/operator-overloading.rs @@ -52,8 +52,8 @@ impl ops::Not for Point { impl ops::Index for Point { type Output = int; - fn index(&self, x: &bool) -> &int { - if *x { + fn index(&self, x: bool) -> &int { + if x { &self.x } else { &self.y diff --git a/src/test/run-pass/overloaded-index-assoc-list.rs b/src/test/run-pass/overloaded-index-assoc-list.rs index 0064748e883..b5c9962fe9c 100644 --- a/src/test/run-pass/overloaded-index-assoc-list.rs +++ b/src/test/run-pass/overloaded-index-assoc-list.rs @@ -28,7 +28,7 @@ impl AssociationList { } } -impl Index for AssociationList { +impl<'a, K: PartialEq + std::fmt::Debug, V:Clone> Index<&'a K> for AssociationList { type Output = V; fn index<'a>(&'a self, index: &K) -> &'a V { @@ -49,9 +49,9 @@ pub fn main() { list.push(foo.clone(), 22); list.push(bar.clone(), 44); - assert!(list[foo] == 22); - assert!(list[bar] == 44); + assert!(list[&foo] == 22); + assert!(list[&bar] == 44); - assert!(list[foo] == 22); - assert!(list[bar] == 44); + assert!(list[&foo] == 22); + assert!(list[&bar] == 44); } diff --git a/src/test/run-pass/overloaded-index-autoderef.rs b/src/test/run-pass/overloaded-index-autoderef.rs index 8f655f0517d..107f0fbc209 100644 --- a/src/test/run-pass/overloaded-index-autoderef.rs +++ b/src/test/run-pass/overloaded-index-autoderef.rs @@ -23,8 +23,8 @@ struct Foo { impl Index for Foo { type Output = int; - fn index(&self, z: &int) -> &int { - if *z == 0 { + fn index(&self, z: int) -> &int { + if z == 0 { &self.x } else { &self.y @@ -33,8 +33,8 @@ impl Index for Foo { } impl IndexMut for Foo { - fn index_mut(&mut self, z: &int) -> &mut int { - if *z == 0 { + fn index_mut(&mut self, z: int) -> &mut int { + if z == 0 { &mut self.x } else { &mut self.y diff --git a/src/test/run-pass/overloaded-index-in-field.rs b/src/test/run-pass/overloaded-index-in-field.rs index 487fb93c9fe..f01e5541c42 100644 --- a/src/test/run-pass/overloaded-index-in-field.rs +++ b/src/test/run-pass/overloaded-index-in-field.rs @@ -25,8 +25,8 @@ struct Bar { impl Index for Foo { type Output = int; - fn index(&self, z: &int) -> &int { - if *z == 0 { + fn index(&self, z: int) -> &int { + if z == 0 { &self.x } else { &self.y diff --git a/src/test/run-pass/overloaded-index.rs b/src/test/run-pass/overloaded-index.rs index 10ca3804eae..60e0ed9bfdd 100644 --- a/src/test/run-pass/overloaded-index.rs +++ b/src/test/run-pass/overloaded-index.rs @@ -18,8 +18,8 @@ struct Foo { impl Index for Foo { type Output = int; - fn index(&self, z: &int) -> &int { - if *z == 0 { + fn index(&self, z: int) -> &int { + if z == 0 { &self.x } else { &self.y @@ -28,8 +28,8 @@ impl Index for Foo { } impl IndexMut for Foo { - fn index_mut(&mut self, z: &int) -> &mut int { - if *z == 0 { + fn index_mut(&mut self, z: int) -> &mut int { + if z == 0 { &mut self.x } else { &mut self.y diff --git a/src/test/run-pass/slice.rs b/src/test/run-pass/slice.rs index 30b53dbb0ad..ee9bb803561 100644 --- a/src/test/run-pass/slice.rs +++ b/src/test/run-pass/slice.rs @@ -21,53 +21,53 @@ struct Foo; impl Index> for Foo { type Output = Foo; - fn index(&self, index: &Range) -> &Foo { + fn index(&self, index: Range) -> &Foo { unsafe { COUNT += 1; } self } } impl Index> for Foo { type Output = Foo; - fn index(&self, index: &RangeTo) -> &Foo { + fn index(&self, index: RangeTo) -> &Foo { unsafe { COUNT += 1; } self } } impl Index> for Foo { type Output = Foo; - fn index(&self, index: &RangeFrom) -> &Foo { + fn index(&self, index: RangeFrom) -> &Foo { unsafe { COUNT += 1; } self } } impl Index for Foo { type Output = Foo; - fn index(&self, _index: &RangeFull) -> &Foo { + fn index(&self, _index: RangeFull) -> &Foo { unsafe { COUNT += 1; } self } } impl IndexMut> for Foo { - fn index_mut(&mut self, index: &Range) -> &mut Foo { + fn index_mut(&mut self, index: Range) -> &mut Foo { unsafe { COUNT += 1; } self } } impl IndexMut> for Foo { - fn index_mut(&mut self, index: &RangeTo) -> &mut Foo { + fn index_mut(&mut self, index: RangeTo) -> &mut Foo { unsafe { COUNT += 1; } self } } impl IndexMut> for Foo { - fn index_mut(&mut self, index: &RangeFrom) -> &mut Foo { + fn index_mut(&mut self, index: RangeFrom) -> &mut Foo { unsafe { COUNT += 1; } self } } impl IndexMut for Foo { - fn index_mut(&mut self, _index: &RangeFull) -> &mut Foo { + fn index_mut(&mut self, _index: RangeFull) -> &mut Foo { unsafe { COUNT += 1; } self } -- cgit 1.4.1-3-g733a5 From 2df8830642fffa6c68aa6318985cfcd2e63db81b Mon Sep 17 00:00:00 2001 From: Tom Jakubowski Date: Mon, 23 Mar 2015 14:01:28 -0700 Subject: rustdoc: Support for "array" primitive Impls on `clean::Type::FixedVector` are now collected in the array primitive page instead of the slice primitive page. Also add a primitive docs for arrays to `std`. --- src/libcore/array.rs | 2 ++ src/librustdoc/clean/mod.rs | 6 +++++- src/librustdoc/html/format.rs | 2 +- src/librustdoc/html/render.rs | 19 ++++++++++++------- src/libstd/array.rs | 13 +++++++++++++ src/libstd/lib.rs | 6 +++++- 6 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 src/libstd/array.rs (limited to 'src/libstd') diff --git a/src/libcore/array.rs b/src/libcore/array.rs index edb11df5489..b2c23f051d5 100644 --- a/src/libcore/array.rs +++ b/src/libcore/array.rs @@ -14,6 +14,8 @@ #![unstable(feature = "core")] // not yet reviewed +#![doc(primitive = "array")] + use clone::Clone; use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering}; use fmt; diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 421549f8b7e..3db51ff86a3 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1322,7 +1322,8 @@ pub enum Type { /// For parameterized types, so the consumer of the JSON don't go /// looking for types which don't exist anywhere. Generic(String), - /// Primitives are just the fixed-size numeric types (plus int/uint/float), and char. + /// Primitives are the fixed-size numeric types (plus int/uint/float), char, + /// arrays, slices, and tuples. Primitive(PrimitiveType), /// extern "ABI" fn BareFunction(Box), @@ -1362,6 +1363,7 @@ pub enum PrimitiveType { Bool, Str, Slice, + Array, PrimitiveTuple, } @@ -1396,6 +1398,7 @@ impl PrimitiveType { "str" => Some(Str), "f32" => Some(F32), "f64" => Some(F64), + "array" => Some(Array), "slice" => Some(Slice), "tuple" => Some(PrimitiveTuple), _ => None, @@ -1440,6 +1443,7 @@ impl PrimitiveType { Str => "str", Bool => "bool", Char => "char", + Array => "array", Slice => "slice", PrimitiveTuple => "tuple", } diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 03a2d708ee4..0e6e008c616 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -486,7 +486,7 @@ impl fmt::Display for clean::Type { primitive_link(f, clean::Slice, &format!("[{}]", **t)) } clean::FixedVector(ref t, ref s) => { - primitive_link(f, clean::Slice, + primitive_link(f, clean::PrimitiveType::Array, &format!("[{}; {}]", **t, *s)) } clean::Bottom => f.write_str("!"), diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 81daac7b90f..2018de17e79 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1026,7 +1026,8 @@ impl DocFolder for Cache { match item { clean::Item{ attrs, inner: clean::ImplItem(i), .. } => { use clean::{Primitive, Vector, ResolvedPath, BorrowedRef}; - use clean::{FixedVector, Slice, Tuple, PrimitiveTuple}; + use clean::PrimitiveType::{Array, Slice, PrimitiveTuple}; + use clean::{FixedVector, Tuple}; // extract relevant documentation for this impl let dox = match attrs.into_iter().find(|a| { @@ -1056,12 +1057,16 @@ impl DocFolder for Cache { Some(ast_util::local_def(p.to_node_id())) } - // In a DST world, we may only need - // Vector/FixedVector, but for now we also pick up - // borrowed references - Vector(..) | FixedVector(..) | - BorrowedRef{ type_: box Vector(..), .. } | - BorrowedRef{ type_: box FixedVector(..), .. } => + FixedVector(..) | + BorrowedRef { type_: box FixedVector(..), .. } => + { + Some(ast_util::local_def(Array.to_node_id())) + } + + // In a DST world, we may only need Vector, but for now we + // also pick up borrowed references + Vector(..) | + BorrowedRef{ type_: box Vector(..), .. } => { Some(ast_util::local_def(Slice.to_node_id())) } diff --git a/src/libstd/array.rs b/src/libstd/array.rs new file mode 100644 index 00000000000..a6b8cd71a3b --- /dev/null +++ b/src/libstd/array.rs @@ -0,0 +1,13 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! The fixed-size array type (`[T; n]`). + +#![doc(primitive = "array")] diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index b055796ba54..5839e3fb638 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -212,6 +212,9 @@ pub mod prelude; /* Primitive types */ +// NB: slice and str are primitive types too, but their module docs + primitive doc pages +// are inlined from the public re-exports of core_collections::{slice, str} above. + #[path = "num/float_macros.rs"] #[macro_use] mod float_macros; @@ -285,8 +288,9 @@ pub mod sync; pub mod rt; mod panicking; -// Documentation for primitive types +// Modules that exist purely to document + host impl docs for primitive types +mod array; mod bool; mod unit; mod tuple; -- cgit 1.4.1-3-g733a5 From df290f127e923e0aacfe8223dd77f0fa222f0bc8 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 5 Mar 2015 18:33:58 -0800 Subject: Require feature attributes, and add them where necessary --- src/compiletest/compiletest.rs | 1 + src/libcollections/lib.rs | 2 +- src/libcollectionstest/lib.rs | 1 + src/libcoretest/lib.rs | 2 + src/libflate/lib.rs | 1 + src/librand/lib.rs | 2 +- src/librustc/lint/context.rs | 2 +- src/librustc/middle/stability.rs | 4 +- src/librustc_back/lib.rs | 1 + src/librustc_bitflags/lib.rs | 1 + src/libserialize/lib.rs | 2 +- src/libstd/lib.rs | 2 +- src/libtest/lib.rs | 1 + src/libunicode/char.rs | 4 + .../auxiliary/anon-extern-mod-cross-crate-1.rs | 1 + .../check_static_recursion_foreign_helper.rs | 2 + src/test/auxiliary/extern-crosscrate-source.rs | 1 + src/test/auxiliary/foreign_lib.rs | 1 + src/test/auxiliary/issue-3012-1.rs | 1 + src/test/auxiliary/issue13507.rs | 2 + .../issue_16723_multiple_items_syntax_ext.rs | 2 +- src/test/auxiliary/issue_3907.rs | 2 + src/test/auxiliary/issue_5844_aux.rs | 2 + src/test/auxiliary/linkage-visibility.rs | 2 + src/test/auxiliary/lint_for_crate.rs | 2 +- src/test/auxiliary/lint_group_plugin_test.rs | 2 +- src/test/auxiliary/lint_plugin_test.rs | 2 +- src/test/auxiliary/logging_right_crate.rs | 2 + src/test/auxiliary/macro_crate_MacroRulesTT.rs | 2 +- src/test/auxiliary/macro_crate_test.rs | 2 +- src/test/auxiliary/plugin_args.rs | 2 +- .../plugin_crate_outlive_expansion_phase.rs | 2 +- src/test/auxiliary/plugin_with_plugin_lib.rs | 2 +- src/test/auxiliary/private_trait_xc.rs | 2 + src/test/auxiliary/procedural_mbe_matching.rs | 2 +- src/test/auxiliary/rlib_crate_test.rs | 2 +- src/test/auxiliary/roman_numerals.rs | 2 +- src/test/auxiliary/svh-a-base.rs | 1 + src/test/auxiliary/svh-a-change-lit.rs | 1 + src/test/auxiliary/svh-a-change-significant-cfg.rs | 1 + src/test/auxiliary/svh-a-change-trait-bound.rs | 1 + src/test/auxiliary/svh-a-change-type-arg.rs | 1 + src/test/auxiliary/svh-a-change-type-ret.rs | 1 + src/test/auxiliary/svh-a-change-type-static.rs | 1 + src/test/auxiliary/svh-a-comment.rs | 1 + src/test/auxiliary/svh-a-doc.rs | 1 + src/test/auxiliary/svh-a-macro.rs | 1 + src/test/auxiliary/svh-a-no-change.rs | 1 + src/test/auxiliary/svh-a-redundant-cfg.rs | 1 + src/test/auxiliary/svh-a-whitespace.rs | 1 + .../auxiliary/syntax_extension_with_dll_deps_2.rs | 2 +- src/test/auxiliary/trait_impl_conflict.rs | 2 + ...default-trait-impl-cross-crate-coherence-lib.rs | 2 +- src/test/auxiliary/typeid-intrinsic.rs | 2 + src/test/auxiliary/typeid-intrinsic2.rs | 2 + src/test/auxiliary/weak-lang-items.rs | 2 +- src/test/bench/core-map.rs | 2 +- src/test/bench/core-set.rs | 2 +- src/test/bench/core-std.rs | 2 +- src/test/bench/msgsend-pipes-shared.rs | 2 + src/test/bench/msgsend-pipes.rs | 2 + src/test/bench/msgsend-ring-mutex-arcs.rs | 2 + src/test/bench/noise.rs | 2 + src/test/bench/shootout-binarytrees.rs | 2 + src/test/bench/shootout-fannkuch-redux.rs | 2 + src/test/bench/shootout-fasta-redux.rs | 2 + src/test/bench/shootout-fasta.rs | 2 + src/test/bench/shootout-k-nucleotide-pipes.rs | 2 +- src/test/bench/shootout-k-nucleotide.rs | 2 +- src/test/bench/shootout-mandelbrot.rs | 2 +- src/test/bench/shootout-meteor.rs | 2 + src/test/bench/shootout-nbody.rs | 2 + src/test/bench/shootout-pfib.rs | 2 + src/test/bench/shootout-reverse-complement.rs | 2 +- src/test/bench/shootout-spectralnorm.rs | 2 +- src/test/bench/std-smallintmap.rs | 2 + src/test/bench/sudoku.rs | 2 +- src/test/bench/task-perf-alloc-unwind.rs | 2 +- src/test/compile-fail/internal-unstable-noallow.rs | 3 - .../compile-fail/internal-unstable-thread-local.rs | 6 +- src/test/compile-fail/internal-unstable.rs | 15 +-- src/test/compile-fail/lint-output-format.rs | 4 +- src/test/compile-fail/lint-stability-fields.rs | 84 ++++++------ src/test/compile-fail/lint-stability.rs | 144 ++++++++++----------- src/test/debuginfo/constant-debug-locs.rs | 1 + src/test/debuginfo/function-arg-initialization.rs | 2 + .../function-prologue-stepping-no-stack-check.rs | 2 + src/test/debuginfo/issue13213.rs | 3 + src/test/debuginfo/simd.rs | 1 + src/test/run-fail/extern-panic.rs | 1 + src/test/run-fail/rt-set-exit-status-panic.rs | 2 + src/test/run-fail/rt-set-exit-status-panic2.rs | 2 + src/test/run-fail/rt-set-exit-status.rs | 2 + .../allow-warnings-cmdline-stability/foo.rs | 2 + .../create_and_compile.rs | 2 + src/test/run-make/extern-fn-reachable/main.rs | 2 + .../intrinsic-unreachable/exit-unreachable.rs | 2 +- src/test/run-make/issue-19371/foo.rs | 2 + src/test/run-make/link-path-order/main.rs | 2 + src/test/run-make/lto-syntax-extension/main.rs | 2 + src/test/run-make/no-duplicate-libs/bar.rs | 2 +- src/test/run-make/no-duplicate-libs/foo.rs | 2 +- src/test/run-make/rustdoc-default-impl/foo.rs | 2 + src/test/run-make/save-analysis/foo.rs | 2 +- src/test/run-make/unicode-input/multiple_files.rs | 2 + src/test/run-make/unicode-input/span_length.rs | 2 + src/test/run-make/volatile-intrinsics/main.rs | 2 + src/test/run-pass-fulldeps/compiler-calls.rs | 2 +- src/test/run-pass-fulldeps/issue-16992.rs | 2 +- .../issue-18763-quote-token-tree.rs | 2 +- src/test/run-pass-fulldeps/quote-tokens.rs | 2 +- .../quote-unused-sp-no-warning.rs | 2 +- .../syntax-extension-with-dll-deps.rs | 2 +- src/test/run-pass-valgrind/cleanup-stdin.rs | 2 + src/test/run-pass/anon-extern-mod.rs | 2 + src/test/run-pass/associated-types-basic.rs | 2 + src/test/run-pass/associated-types-issue-20371.rs | 2 + .../associated-types-nested-projections.rs | 2 + ...associated-types-normalize-in-bounds-binding.rs | 1 + ...ct-from-type-param-via-bound-in-where-clause.rs | 2 + src/test/run-pass/attr-before-view-item.rs | 2 +- src/test/run-pass/attr-before-view-item2.rs | 2 +- src/test/run-pass/backtrace.rs | 2 +- src/test/run-pass/bitv-perf-test.rs | 2 +- src/test/run-pass/c-stack-as-value.rs | 2 + src/test/run-pass/c-stack-returning-int64.rs | 2 + src/test/run-pass/capturing-logging.rs | 2 +- .../run-pass/check-static-recursion-foreign.rs | 2 +- src/test/run-pass/child-outlives-parent.rs | 2 + src/test/run-pass/cleanup-arm-conditional.rs | 2 +- src/test/run-pass/clone-with-exterior.rs | 2 +- src/test/run-pass/closure-reform.rs | 2 +- src/test/run-pass/comm.rs | 2 + src/test/run-pass/conditional-debug-macro-off.rs | 2 + src/test/run-pass/const-cast.rs | 2 + src/test/run-pass/core-run-destroy.rs | 1 + src/test/run-pass/derive-no-std.rs | 2 +- .../run-pass/deriving-encodable-decodable-box.rs | 2 +- .../deriving-encodable-decodable-cell-refcell.rs | 2 +- src/test/run-pass/deriving-global.rs | 2 +- src/test/run-pass/deriving-hash.rs | 2 + src/test/run-pass/deriving-primitive.rs | 2 + src/test/run-pass/deriving-rand.rs | 2 + src/test/run-pass/drop-with-type-ascription-1.rs | 2 + src/test/run-pass/drop-with-type-ascription-2.rs | 2 + src/test/run-pass/dropck_tarena_sound_drop.rs | 2 +- src/test/run-pass/dst-index.rs | 2 + src/test/run-pass/enum-null-pointer-opt.rs | 1 + src/test/run-pass/env-home-dir.rs | 2 + src/test/run-pass/exponential-notation.rs | 2 + src/test/run-pass/extern-call-deep.rs | 2 + src/test/run-pass/extern-call-deep2.rs | 2 + src/test/run-pass/extern-call-indirect.rs | 2 + src/test/run-pass/extern-call-scrub.rs | 2 + src/test/run-pass/extern-crosscrate.rs | 2 + src/test/run-pass/extern-methods.rs | 2 + src/test/run-pass/extern-mod-syntax.rs | 1 + src/test/run-pass/float-nan.rs | 2 + src/test/run-pass/for-loop-no-std.rs | 2 +- ...ach-external-iterators-hashmap-break-restart.rs | 2 + .../run-pass/foreach-external-iterators-hashmap.rs | 2 + src/test/run-pass/foreign-call-no-runtime.rs | 1 + src/test/run-pass/foreign-dupe.rs | 2 + src/test/run-pass/foreign-fn-linkname.rs | 2 + src/test/run-pass/foreign-mod-unused-const.rs | 2 + src/test/run-pass/foreign-no-abi.rs | 2 + src/test/run-pass/foreign2.rs | 2 + src/test/run-pass/format-no-std.rs | 2 +- src/test/run-pass/fsu-moves-and-copies.rs | 2 +- src/test/run-pass/generic-extern-mangle.rs | 2 + src/test/run-pass/getopts_ref.rs | 2 + src/test/run-pass/hashmap-memory.rs | 2 +- src/test/run-pass/init-large-type.rs | 2 +- .../run-pass/into-iterator-type-inference-shift.rs | 2 + src/test/run-pass/intrinsic-assume.rs | 2 + src/test/run-pass/intrinsic-unreachable.rs | 2 + src/test/run-pass/intrinsics-math.rs | 2 +- src/test/run-pass/issue-10626.rs | 2 + src/test/run-pass/issue-11709.rs | 2 + src/test/run-pass/issue-11736.rs | 2 + src/test/run-pass/issue-11881.rs | 2 +- src/test/run-pass/issue-11958.rs | 1 + src/test/run-pass/issue-1251.rs | 2 + src/test/run-pass/issue-12684.rs | 2 + src/test/run-pass/issue-12699.rs | 2 + src/test/run-pass/issue-12860.rs | 1 + src/test/run-pass/issue-13105.rs | 2 + src/test/run-pass/issue-13259-windows-tcb-trash.rs | 2 + src/test/run-pass/issue-13304.rs | 1 + src/test/run-pass/issue-13352.rs | 2 + src/test/run-pass/issue-13494.rs | 2 + src/test/run-pass/issue-13507-2.rs | 3 + src/test/run-pass/issue-13655.rs | 2 +- src/test/run-pass/issue-13763.rs | 2 + src/test/run-pass/issue-14021.rs | 2 +- src/test/run-pass/issue-14456.rs | 2 + src/test/run-pass/issue-14901.rs | 2 + src/test/run-pass/issue-14940.rs | 2 + src/test/run-pass/issue-14958.rs | 2 +- src/test/run-pass/issue-14959.rs | 2 +- src/test/run-pass/issue-15673.rs | 2 + src/test/run-pass/issue-15734.rs | 2 +- src/test/run-pass/issue-15924.rs | 2 +- src/test/run-pass/issue-16530.rs | 2 + src/test/run-pass/issue-16739.rs | 2 +- src/test/run-pass/issue-1696.rs | 2 + src/test/run-pass/issue-17322.rs | 2 +- src/test/run-pass/issue-17351.rs | 2 + .../run-pass/issue-17718-static-unsafe-interior.rs | 2 + src/test/run-pass/issue-17718.rs | 2 + src/test/run-pass/issue-17897.rs | 2 +- src/test/run-pass/issue-18188.rs | 2 +- src/test/run-pass/issue-18619.rs | 2 + src/test/run-pass/issue-18661.rs | 2 +- src/test/run-pass/issue-19098.rs | 2 +- src/test/run-pass/issue-19811-escape-unicode.rs | 2 + src/test/run-pass/issue-20091.rs | 1 + src/test/run-pass/issue-20454.rs | 2 + src/test/run-pass/issue-20644.rs | 2 + src/test/run-pass/issue-20797.rs | 2 + src/test/run-pass/issue-21058.rs | 1 + src/test/run-pass/issue-2190-1.rs | 2 + src/test/run-pass/issue-2214.rs | 2 + src/test/run-pass/issue-22577.rs | 2 + src/test/run-pass/issue-2383.rs | 2 + src/test/run-pass/issue-2718.rs | 2 +- src/test/run-pass/issue-2804-2.rs | 2 + src/test/run-pass/issue-2804.rs | 3 + src/test/run-pass/issue-2904.rs | 4 +- src/test/run-pass/issue-3012-2.rs | 2 +- src/test/run-pass/issue-3026.rs | 2 +- src/test/run-pass/issue-3424.rs | 2 +- src/test/run-pass/issue-3559.rs | 2 + src/test/run-pass/issue-3563-3.rs | 2 + src/test/run-pass/issue-3609.rs | 1 + src/test/run-pass/issue-3656.rs | 2 + src/test/run-pass/issue-3753.rs | 2 + src/test/run-pass/issue-4016.rs | 1 + src/test/run-pass/issue-4036.rs | 2 + src/test/run-pass/issue-4333.rs | 2 + src/test/run-pass/issue-4446.rs | 2 + src/test/run-pass/issue-4735.rs | 2 +- src/test/run-pass/issue-5791.rs | 2 + src/test/run-pass/issue-5988.rs | 2 + src/test/run-pass/issue-6128.rs | 2 +- src/test/run-pass/issue-6898.rs | 2 + src/test/run-pass/issue-7660.rs | 2 + src/test/run-pass/issue-8398.rs | 2 + src/test/run-pass/issue-8460.rs | 2 + src/test/run-pass/issue-8827.rs | 2 + src/test/run-pass/issue-9396.rs | 2 + src/test/run-pass/issue22346.rs | 2 + src/test/run-pass/istr.rs | 2 + src/test/run-pass/item-attributes.rs | 2 +- src/test/run-pass/ivec-tag.rs | 2 + .../run-pass/kindck-implicit-close-over-mut-var.rs | 2 + src/test/run-pass/last-use-in-cap-clause.rs | 2 +- src/test/run-pass/linkage-visibility.rs | 2 + src/test/run-pass/logging-enabled-debug.rs | 2 + src/test/run-pass/logging-enabled.rs | 2 + src/test/run-pass/logging-separate-lines.rs | 2 + .../run-pass/macro-with-braces-in-expr-position.rs | 2 + .../method-mut-self-modifies-mut-slice-lvalue.rs | 2 + ...od-two-traits-distinguished-via-where-clause.rs | 2 + .../monomorphized-callees-with-ty-params-3314.rs | 2 + .../run-pass/moves-based-on-type-capture-clause.rs | 2 + src/test/run-pass/new-box-syntax.rs | 2 +- src/test/run-pass/new-unicode-escapes.rs | 2 + src/test/run-pass/newtype-struct-with-dtor.rs | 2 + src/test/run-pass/numeric-method-autoexport.rs | 2 + src/test/run-pass/operator-overloading.rs | 2 + src/test/run-pass/option-ext.rs | 2 + src/test/run-pass/osx-frameworks.rs | 2 + .../run-pass/out-of-stack-new-thread-no-split.rs | 2 +- src/test/run-pass/out-of-stack.rs | 2 +- src/test/run-pass/overloaded-autoderef.rs | 2 +- .../run-pass/overloaded-calls-param-vtables.rs | 2 +- src/test/run-pass/overloaded-calls-simple.rs | 2 +- src/test/run-pass/overloaded-calls-zero-args.rs | 2 +- src/test/run-pass/overloaded-deref.rs | 2 + src/test/run-pass/overloaded-index-assoc-list.rs | 2 + src/test/run-pass/overloaded-index-autoderef.rs | 2 +- src/test/run-pass/overloaded-index-in-field.rs | 2 + src/test/run-pass/overloaded-index.rs | 2 + src/test/run-pass/placement-new-arena.rs | 2 + src/test/run-pass/process-remove-from-env.rs | 2 + .../run-pass/process-spawn-with-unicode-params.rs | 1 + src/test/run-pass/realloc-16687.rs | 2 + src/test/run-pass/regions-copy-closure.rs | 2 +- src/test/run-pass/regions-mock-tcx.rs | 2 + src/test/run-pass/regions-mock-trans.rs | 2 + src/test/run-pass/regions-static-closure.rs | 2 +- src/test/run-pass/rename-directory.rs | 2 + src/test/run-pass/running-with-no-runtime.rs | 2 +- src/test/run-pass/rust-log-filter.rs | 2 +- src/test/run-pass/segfault-no-out-of-stack.rs | 2 + src/test/run-pass/send-resource.rs | 2 + src/test/run-pass/send_str_hashmap.rs | 2 + src/test/run-pass/send_str_treemap.rs | 2 + src/test/run-pass/signal-exit-status.rs | 3 + src/test/run-pass/simd-binop.rs | 1 + src/test/run-pass/simd-issue-10604.rs | 2 +- src/test/run-pass/slice.rs | 2 +- src/test/run-pass/smallest-hello-world.rs | 2 +- src/test/run-pass/spawn-fn.rs | 2 + src/test/run-pass/stat.rs | 2 + src/test/run-pass/static-mut-foreign.rs | 2 + src/test/run-pass/std-sync-right-kind-impls.rs | 2 + src/test/run-pass/supported-cast.rs | 2 + src/test/run-pass/syntax-extension-source-utils.rs | 8 +- src/test/run-pass/syntax-trait-polarity.rs | 2 +- src/test/run-pass/task-comm-0.rs | 2 + src/test/run-pass/task-comm-1.rs | 2 + src/test/run-pass/task-comm-10.rs | 2 + src/test/run-pass/task-comm-11.rs | 2 + src/test/run-pass/task-comm-12.rs | 2 + src/test/run-pass/task-comm-13.rs | 2 + src/test/run-pass/task-comm-14.rs | 2 + src/test/run-pass/task-comm-15.rs | 2 + src/test/run-pass/task-comm-17.rs | 2 + src/test/run-pass/task-comm-3.rs | 2 + src/test/run-pass/task-comm-7.rs | 1 + src/test/run-pass/task-comm-9.rs | 2 + src/test/run-pass/task-life-0.rs | 2 + src/test/run-pass/task-spawn-move-and-copy.rs | 2 +- src/test/run-pass/task-stderr.rs | 2 +- src/test/run-pass/tcp-accept-stress.rs | 2 + src/test/run-pass/tcp-connect-timeouts.rs | 1 + src/test/run-pass/tempfile.rs | 2 + ...nature-verification-for-explicit-return-type.rs | 2 + src/test/run-pass/threads.rs | 2 + src/test/run-pass/trait-bounds-basic.rs | 1 + src/test/run-pass/trait-bounds-in-arc.rs | 2 +- .../run-pass/trait-bounds-on-structs-and-enums.rs | 2 + src/test/run-pass/trait-bounds-recursion.rs | 2 + src/test/run-pass/trait-coercion.rs | 3 +- src/test/run-pass/trait-inheritance-num.rs | 2 + src/test/run-pass/trait-inheritance-num0.rs | 2 + src/test/run-pass/trait-inheritance-num1.rs | 2 + src/test/run-pass/trait-inheritance-num2.rs | 2 + src/test/run-pass/trait-inheritance-num3.rs | 2 + src/test/run-pass/trait-inheritance-num5.rs | 2 + src/test/run-pass/trait-inheritance-static2.rs | 2 + src/test/run-pass/tydesc-name.rs | 1 + src/test/run-pass/type-id-higher-rank.rs | 2 +- src/test/run-pass/typeid-intrinsic.rs | 2 + src/test/run-pass/ufcs-polymorphic-paths.rs | 2 +- src/test/run-pass/unboxed-closures-extern-fn-hr.rs | 2 +- .../unboxed-closures-fn-as-fnmut-and-fnonce.rs | 3 +- .../run-pass/unboxed-closures-fnmut-as-fnonce.rs | 3 +- ...res-infer-argument-types-from-expected-bound.rs | 2 +- ...fer-argument-types-from-expected-object-type.rs | 2 +- ...types-with-bound-regions-from-expected-bound.rs | 2 +- src/test/run-pass/unboxed-closures-manual-impl.rs | 2 +- .../run-pass/unboxed-closures-monomorphization.rs | 2 +- src/test/run-pass/unboxed-closures-prelude.rs | 2 +- src/test/run-pass/unfold-cross-crate.rs | 2 + src/test/run-pass/unit-like-struct-drop-run.rs | 2 + src/test/run-pass/unsized3.rs | 2 +- src/test/run-pass/utf8_chars.rs | 2 + src/test/run-pass/variadic-ffi.rs | 2 + .../variance-intersection-of-ref-and-opt-ref.rs | 1 + src/test/run-pass/variance-vec-covariant.rs | 1 + src/test/run-pass/vec-concat.rs | 2 + src/test/run-pass/vec-macro-no-std.rs | 2 +- src/test/run-pass/vector-sort-panic-safe.rs | 2 + src/test/run-pass/wait-forked-but-failed-child.rs | 2 + src/test/run-pass/while-let.rs | 2 + src/test/run-pass/while-prelude-drop.rs | 2 + 369 files changed, 702 insertions(+), 253 deletions(-) (limited to 'src/libstd') diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 01c4e99b77c..1aa5564d0a1 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -20,6 +20,7 @@ #![feature(std_misc)] #![feature(test)] #![feature(path_ext)] +#![feature(str_char)] #![deny(warnings)] diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index c4a01496763..cf9f6a39a55 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -36,7 +36,7 @@ #![feature(unsafe_no_drop_flag)] #![feature(step_by)] #![feature(str_char)] -#![cfg_attr(test, feature(rand, rustc_private, test))] +#![cfg_attr(test, feature(rand, rustc_private, test, hash, collections))] #![cfg_attr(test, allow(deprecated))] // rand #![feature(no_std)] diff --git a/src/libcollectionstest/lib.rs b/src/libcollectionstest/lib.rs index 7f029340d25..365ef637a4c 100644 --- a/src/libcollectionstest/lib.rs +++ b/src/libcollectionstest/lib.rs @@ -20,6 +20,7 @@ #![feature(unboxed_closures)] #![feature(unicode)] #![feature(unsafe_destructor)] +#![cfg_attr(test, feature(str_char))] #[macro_use] extern crate log; diff --git a/src/libcoretest/lib.rs b/src/libcoretest/lib.rs index 536bce0d05f..33f9b63bc49 100644 --- a/src/libcoretest/lib.rs +++ b/src/libcoretest/lib.rs @@ -24,6 +24,8 @@ #![feature(io)] #![feature(collections)] #![feature(debug_builders)] +#![feature(unique)] +#![feature(step_by)] #![allow(deprecated)] // rand extern crate core; diff --git a/src/libflate/lib.rs b/src/libflate/lib.rs index 695c71c73ed..63d1fe968fe 100644 --- a/src/libflate/lib.rs +++ b/src/libflate/lib.rs @@ -28,6 +28,7 @@ #![feature(libc)] #![feature(staged_api)] #![feature(unique)] +#![cfg_attr(test, feature(rustc_private, rand, collections))] #[cfg(test)] #[macro_use] extern crate log; diff --git a/src/librand/lib.rs b/src/librand/lib.rs index 5e52a176c9e..8de773e9fec 100644 --- a/src/librand/lib.rs +++ b/src/librand/lib.rs @@ -34,7 +34,7 @@ #![deprecated(reason = "use the crates.io `rand` library instead", since = "1.0.0-alpha")] -#![cfg_attr(test, feature(test, rand))] +#![cfg_attr(test, feature(test, rand, rustc_private))] #![allow(deprecated)] diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 9aa6395b7b2..9688447dc04 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -212,7 +212,7 @@ impl LintStore { fn maybe_stage_features(&mut self, sess: &Session) { let lvl = match sess.opts.unstable_features { UnstableFeatures::Default => return, - UnstableFeatures::Disallow => Warn, + UnstableFeatures::Disallow => Forbid, UnstableFeatures::Cheat => Allow }; match self.by_name.get("unstable_features") { diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 01766b0de08..96657b1d261 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -26,7 +26,7 @@ use syntax::ast::{Item, Generics, StructField}; use syntax::ast_util::is_local; use syntax::attr::{Stability, AttrMetaMethods}; use syntax::visit::{FnKind, Visitor}; -use syntax::feature_gate::emit_feature_warn; +use syntax::feature_gate::emit_feature_err; use util::nodemap::{NodeMap, DefIdMap, FnvHashSet, FnvHashMap}; use util::ppaux::Repr; @@ -237,7 +237,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> { None => format!("use of unstable library feature '{}'", &feature) }; - emit_feature_warn(&self.tcx.sess.parse_sess.span_diagnostic, + emit_feature_err(&self.tcx.sess.parse_sess.span_diagnostic, &feature, span, &msg); } } diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs index 99d24a60130..acc17edaf2c 100644 --- a/src/librustc_back/lib.rs +++ b/src/librustc_back/lib.rs @@ -49,6 +49,7 @@ #![feature(std_misc)] #![feature(path_relative_from)] #![feature(step_by)] +#![cfg_attr(test, feature(test, rand))] extern crate syntax; extern crate serialize; diff --git a/src/librustc_bitflags/lib.rs b/src/librustc_bitflags/lib.rs index 2992ddbc4f4..054bfec7a20 100644 --- a/src/librustc_bitflags/lib.rs +++ b/src/librustc_bitflags/lib.rs @@ -18,6 +18,7 @@ #![feature(no_std)] #![no_std] #![unstable(feature = "rustc_private")] +#![cfg_attr(test, feature(hash))] //! A typesafe bitmask flag generator. diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index 90cb88046e5..ee257dd0ac9 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -37,7 +37,7 @@ Core encoding and decoding interfaces. #![feature(std_misc)] #![feature(unicode)] #![feature(str_char)] -#![cfg_attr(test, feature(test))] +#![cfg_attr(test, feature(test, old_io))] // test harness access #[cfg(test)] extern crate test; diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index b055796ba54..1aa2189d315 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -128,7 +128,7 @@ #![feature(unique)] #![feature(allow_internal_unstable)] #![feature(str_char)] -#![cfg_attr(test, feature(test, rustc_private))] +#![cfg_attr(test, feature(test, rustc_private, std_misc))] // Don't link to std. We are std. #![feature(no_std)] diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 51decbab858..34f1b68fa9b 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -45,6 +45,7 @@ #![feature(libc)] #![feature(set_stdio)] #![feature(os)] +#![cfg_attr(test, feature(old_io))] extern crate getopts; extern crate serialize; diff --git a/src/libunicode/char.rs b/src/libunicode/char.rs index 5e1070c6dc5..e0f013cbc80 100644 --- a/src/libunicode/char.rs +++ b/src/libunicode/char.rs @@ -653,6 +653,7 @@ impl char { /// In both of these examples, 'ß' takes two bytes to encode. /// /// ``` + /// # #![feature(unicode)] /// let mut b = [0; 2]; /// /// let result = 'ß'.encode_utf8(&mut b); @@ -663,6 +664,7 @@ impl char { /// A buffer that's too small: /// /// ``` + /// # #![feature(unicode)] /// let mut b = [0; 1]; /// /// let result = 'ß'.encode_utf8(&mut b); @@ -685,6 +687,7 @@ impl char { /// In both of these examples, 'ß' takes one `u16` to encode. /// /// ``` + /// # #![feature(unicode)] /// let mut b = [0; 1]; /// /// let result = 'ß'.encode_utf16(&mut b); @@ -695,6 +698,7 @@ impl char { /// A buffer that's too small: /// /// ``` + /// # #![feature(unicode)] /// let mut b = [0; 0]; /// /// let result = 'ß'.encode_utf8(&mut b); diff --git a/src/test/auxiliary/anon-extern-mod-cross-crate-1.rs b/src/test/auxiliary/anon-extern-mod-cross-crate-1.rs index 12ab62267a3..197fb9a6d01 100644 --- a/src/test/auxiliary/anon-extern-mod-cross-crate-1.rs +++ b/src/test/auxiliary/anon-extern-mod-cross-crate-1.rs @@ -9,6 +9,7 @@ // except according to those terms. #![crate_name="anonexternmod"] +#![feature(libc)] extern crate libc; diff --git a/src/test/auxiliary/check_static_recursion_foreign_helper.rs b/src/test/auxiliary/check_static_recursion_foreign_helper.rs index b5c2a4f135f..c0d81cd8e1b 100644 --- a/src/test/auxiliary/check_static_recursion_foreign_helper.rs +++ b/src/test/auxiliary/check_static_recursion_foreign_helper.rs @@ -10,6 +10,8 @@ // Helper definition for test/run-pass/check-static-recursion-foreign.rs. +#![feature(libc)] + #[crate_id = "check_static_recursion_foreign_helper"] #[crate_type = "lib"] diff --git a/src/test/auxiliary/extern-crosscrate-source.rs b/src/test/auxiliary/extern-crosscrate-source.rs index 0e3b531e458..fc2e328f686 100644 --- a/src/test/auxiliary/extern-crosscrate-source.rs +++ b/src/test/auxiliary/extern-crosscrate-source.rs @@ -10,6 +10,7 @@ #![crate_name="externcallback"] #![crate_type = "lib"] +#![feature(libc)] extern crate libc; diff --git a/src/test/auxiliary/foreign_lib.rs b/src/test/auxiliary/foreign_lib.rs index a5d672e3c0c..92239ce5598 100644 --- a/src/test/auxiliary/foreign_lib.rs +++ b/src/test/auxiliary/foreign_lib.rs @@ -9,6 +9,7 @@ // except according to those terms. #![crate_name="foreign_lib"] +#![feature(libc)] pub mod rustrt { extern crate libc; diff --git a/src/test/auxiliary/issue-3012-1.rs b/src/test/auxiliary/issue-3012-1.rs index 25eb67e0423..b6199f59ebe 100644 --- a/src/test/auxiliary/issue-3012-1.rs +++ b/src/test/auxiliary/issue-3012-1.rs @@ -10,6 +10,7 @@ #![crate_name="socketlib"] #![crate_type = "lib"] +#![feature(libc)] pub mod socket { extern crate libc; diff --git a/src/test/auxiliary/issue13507.rs b/src/test/auxiliary/issue13507.rs index f24721adb5d..4a8839abc7c 100644 --- a/src/test/auxiliary/issue13507.rs +++ b/src/test/auxiliary/issue13507.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + pub mod testtypes { use std::any::TypeId; diff --git a/src/test/auxiliary/issue_16723_multiple_items_syntax_ext.rs b/src/test/auxiliary/issue_16723_multiple_items_syntax_ext.rs index f5a9063e1de..58dee1216ee 100644 --- a/src/test/auxiliary/issue_16723_multiple_items_syntax_ext.rs +++ b/src/test/auxiliary/issue_16723_multiple_items_syntax_ext.rs @@ -11,7 +11,7 @@ // ignore-stage1 // force-host -#![feature(plugin_registrar, quote)] +#![feature(plugin_registrar, quote, rustc_private)] #![crate_type = "dylib"] extern crate syntax; diff --git a/src/test/auxiliary/issue_3907.rs b/src/test/auxiliary/issue_3907.rs index c118f7e4854..3d5e52d709d 100644 --- a/src/test/auxiliary/issue_3907.rs +++ b/src/test/auxiliary/issue_3907.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + use std::marker::MarkerTrait; pub trait Foo : MarkerTrait { diff --git a/src/test/auxiliary/issue_5844_aux.rs b/src/test/auxiliary/issue_5844_aux.rs index e12af579c57..5c878b1e667 100644 --- a/src/test/auxiliary/issue_5844_aux.rs +++ b/src/test/auxiliary/issue_5844_aux.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(libc)] + extern crate libc; extern "C" { diff --git a/src/test/auxiliary/linkage-visibility.rs b/src/test/auxiliary/linkage-visibility.rs index 03fe2fd94dd..fd3e9b9ac9d 100644 --- a/src/test/auxiliary/linkage-visibility.rs +++ b/src/test/auxiliary/linkage-visibility.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc, old_path)] + use std::dynamic_lib::DynamicLibrary; #[no_mangle] diff --git a/src/test/auxiliary/lint_for_crate.rs b/src/test/auxiliary/lint_for_crate.rs index 1be37ce1780..3b45b0ae701 100644 --- a/src/test/auxiliary/lint_for_crate.rs +++ b/src/test/auxiliary/lint_for_crate.rs @@ -10,7 +10,7 @@ // force-host -#![feature(plugin_registrar)] +#![feature(plugin_registrar, rustc_private)] #![feature(box_syntax)] extern crate syntax; diff --git a/src/test/auxiliary/lint_group_plugin_test.rs b/src/test/auxiliary/lint_group_plugin_test.rs index e9d98889ff8..ca5a7b75e06 100644 --- a/src/test/auxiliary/lint_group_plugin_test.rs +++ b/src/test/auxiliary/lint_group_plugin_test.rs @@ -11,7 +11,7 @@ // force-host #![feature(plugin_registrar)] -#![feature(box_syntax)] +#![feature(box_syntax, rustc_private)] extern crate syntax; diff --git a/src/test/auxiliary/lint_plugin_test.rs b/src/test/auxiliary/lint_plugin_test.rs index ffb234f70c8..20799ce5b46 100644 --- a/src/test/auxiliary/lint_plugin_test.rs +++ b/src/test/auxiliary/lint_plugin_test.rs @@ -11,7 +11,7 @@ // force-host #![feature(plugin_registrar)] -#![feature(box_syntax)] +#![feature(box_syntax, rustc_private)] extern crate syntax; diff --git a/src/test/auxiliary/logging_right_crate.rs b/src/test/auxiliary/logging_right_crate.rs index bf4ab975ced..974db7c9246 100644 --- a/src/test/auxiliary/logging_right_crate.rs +++ b/src/test/auxiliary/logging_right_crate.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(rustc_private)] + #[macro_use] extern crate log; pub fn foo() { diff --git a/src/test/auxiliary/macro_crate_MacroRulesTT.rs b/src/test/auxiliary/macro_crate_MacroRulesTT.rs index d50c27a4e75..03cd70d9494 100644 --- a/src/test/auxiliary/macro_crate_MacroRulesTT.rs +++ b/src/test/auxiliary/macro_crate_MacroRulesTT.rs @@ -10,7 +10,7 @@ // force-host -#![feature(plugin_registrar)] +#![feature(plugin_registrar, rustc_private)] extern crate syntax; extern crate rustc; diff --git a/src/test/auxiliary/macro_crate_test.rs b/src/test/auxiliary/macro_crate_test.rs index 36a34bc6c8b..5b7e52e9164 100644 --- a/src/test/auxiliary/macro_crate_test.rs +++ b/src/test/auxiliary/macro_crate_test.rs @@ -11,7 +11,7 @@ // force-host #![feature(plugin_registrar, quote)] -#![feature(box_syntax)] +#![feature(box_syntax, rustc_private)] extern crate syntax; extern crate rustc; diff --git a/src/test/auxiliary/plugin_args.rs b/src/test/auxiliary/plugin_args.rs index 30b18a3618f..5a615502a95 100644 --- a/src/test/auxiliary/plugin_args.rs +++ b/src/test/auxiliary/plugin_args.rs @@ -11,7 +11,7 @@ // force-host #![feature(plugin_registrar)] -#![feature(box_syntax)] +#![feature(box_syntax, rustc_private)] extern crate syntax; extern crate rustc; diff --git a/src/test/auxiliary/plugin_crate_outlive_expansion_phase.rs b/src/test/auxiliary/plugin_crate_outlive_expansion_phase.rs index 420151c471e..6f5f5047548 100644 --- a/src/test/auxiliary/plugin_crate_outlive_expansion_phase.rs +++ b/src/test/auxiliary/plugin_crate_outlive_expansion_phase.rs @@ -11,7 +11,7 @@ // force-host #![feature(plugin_registrar)] -#![feature(box_syntax)] +#![feature(box_syntax, rustc_private)] extern crate rustc; diff --git a/src/test/auxiliary/plugin_with_plugin_lib.rs b/src/test/auxiliary/plugin_with_plugin_lib.rs index cfc8c015324..75f404c96cd 100644 --- a/src/test/auxiliary/plugin_with_plugin_lib.rs +++ b/src/test/auxiliary/plugin_with_plugin_lib.rs @@ -10,7 +10,7 @@ // force-host -#![feature(plugin_registrar)] +#![feature(plugin_registrar, rustc_private)] #![deny(plugin_as_library)] // should have no effect in a plugin crate extern crate macro_crate_test; diff --git a/src/test/auxiliary/private_trait_xc.rs b/src/test/auxiliary/private_trait_xc.rs index 42691579491..dc08033602c 100644 --- a/src/test/auxiliary/private_trait_xc.rs +++ b/src/test/auxiliary/private_trait_xc.rs @@ -8,4 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + trait Foo : ::std::marker::MarkerTrait {} diff --git a/src/test/auxiliary/procedural_mbe_matching.rs b/src/test/auxiliary/procedural_mbe_matching.rs index d9a2b06e039..1adc794551e 100644 --- a/src/test/auxiliary/procedural_mbe_matching.rs +++ b/src/test/auxiliary/procedural_mbe_matching.rs @@ -11,7 +11,7 @@ // force-host #![crate_type="dylib"] -#![feature(plugin_registrar, quote)] +#![feature(plugin_registrar, quote, rustc_private)] extern crate syntax; extern crate rustc; diff --git a/src/test/auxiliary/rlib_crate_test.rs b/src/test/auxiliary/rlib_crate_test.rs index be03a36393e..86ce3df9ba6 100644 --- a/src/test/auxiliary/rlib_crate_test.rs +++ b/src/test/auxiliary/rlib_crate_test.rs @@ -11,7 +11,7 @@ // no-prefer-dynamic #![crate_type = "rlib"] -#![feature(plugin_registrar)] +#![feature(plugin_registrar, rustc_private)] extern crate rustc; diff --git a/src/test/auxiliary/roman_numerals.rs b/src/test/auxiliary/roman_numerals.rs index 0ea7c000570..a105cb7ae6c 100644 --- a/src/test/auxiliary/roman_numerals.rs +++ b/src/test/auxiliary/roman_numerals.rs @@ -11,7 +11,7 @@ // force-host #![crate_type="dylib"] -#![feature(plugin_registrar)] +#![feature(plugin_registrar, rustc_private)] extern crate syntax; extern crate rustc; diff --git a/src/test/auxiliary/svh-a-base.rs b/src/test/auxiliary/svh-a-base.rs index 04f1062c16f..6d4ea499b2b 100644 --- a/src/test/auxiliary/svh-a-base.rs +++ b/src/test/auxiliary/svh-a-base.rs @@ -14,6 +14,7 @@ //! (#14132). #![crate_name = "a"] +#![feature(core)] use std::marker::MarkerTrait; diff --git a/src/test/auxiliary/svh-a-change-lit.rs b/src/test/auxiliary/svh-a-change-lit.rs index fabd2289e9a..61e4aaf3258 100644 --- a/src/test/auxiliary/svh-a-change-lit.rs +++ b/src/test/auxiliary/svh-a-change-lit.rs @@ -14,6 +14,7 @@ //! (#14132). #![crate_name = "a"] +#![feature(core)] use std::marker::MarkerTrait; diff --git a/src/test/auxiliary/svh-a-change-significant-cfg.rs b/src/test/auxiliary/svh-a-change-significant-cfg.rs index 3fdb861bd40..cfdb0902b5d 100644 --- a/src/test/auxiliary/svh-a-change-significant-cfg.rs +++ b/src/test/auxiliary/svh-a-change-significant-cfg.rs @@ -14,6 +14,7 @@ //! (#14132). #![crate_name = "a"] +#![feature(core)] use std::marker::MarkerTrait; diff --git a/src/test/auxiliary/svh-a-change-trait-bound.rs b/src/test/auxiliary/svh-a-change-trait-bound.rs index 3116d24673d..e79738c0410 100644 --- a/src/test/auxiliary/svh-a-change-trait-bound.rs +++ b/src/test/auxiliary/svh-a-change-trait-bound.rs @@ -14,6 +14,7 @@ //! (#14132). #![crate_name = "a"] +#![feature(core)] use std::marker::MarkerTrait; diff --git a/src/test/auxiliary/svh-a-change-type-arg.rs b/src/test/auxiliary/svh-a-change-type-arg.rs index b49a1533628..b22d553c02b 100644 --- a/src/test/auxiliary/svh-a-change-type-arg.rs +++ b/src/test/auxiliary/svh-a-change-type-arg.rs @@ -14,6 +14,7 @@ //! (#14132). #![crate_name = "a"] +#![feature(core)] use std::marker::MarkerTrait; diff --git a/src/test/auxiliary/svh-a-change-type-ret.rs b/src/test/auxiliary/svh-a-change-type-ret.rs index 6562a93135f..78dbdc28b9f 100644 --- a/src/test/auxiliary/svh-a-change-type-ret.rs +++ b/src/test/auxiliary/svh-a-change-type-ret.rs @@ -14,6 +14,7 @@ //! (#14132). #![crate_name = "a"] +#![feature(core)] use std::marker::MarkerTrait; diff --git a/src/test/auxiliary/svh-a-change-type-static.rs b/src/test/auxiliary/svh-a-change-type-static.rs index c7b392c6ee8..30592827039 100644 --- a/src/test/auxiliary/svh-a-change-type-static.rs +++ b/src/test/auxiliary/svh-a-change-type-static.rs @@ -14,6 +14,7 @@ //! (#14132). #![crate_name = "a"] +#![feature(core)] use std::marker::MarkerTrait; diff --git a/src/test/auxiliary/svh-a-comment.rs b/src/test/auxiliary/svh-a-comment.rs index 450f6102026..4c457b099a4 100644 --- a/src/test/auxiliary/svh-a-comment.rs +++ b/src/test/auxiliary/svh-a-comment.rs @@ -14,6 +14,7 @@ //! (#14132). #![crate_name = "a"] +#![feature(core)] use std::marker::MarkerTrait; diff --git a/src/test/auxiliary/svh-a-doc.rs b/src/test/auxiliary/svh-a-doc.rs index c000737c854..cab25ac9e4f 100644 --- a/src/test/auxiliary/svh-a-doc.rs +++ b/src/test/auxiliary/svh-a-doc.rs @@ -14,6 +14,7 @@ //! (#14132). #![crate_name = "a"] +#![feature(core)] use std::marker::MarkerTrait; diff --git a/src/test/auxiliary/svh-a-macro.rs b/src/test/auxiliary/svh-a-macro.rs index 1e12659dc4b..01926dc8abc 100644 --- a/src/test/auxiliary/svh-a-macro.rs +++ b/src/test/auxiliary/svh-a-macro.rs @@ -14,6 +14,7 @@ //! (#14132). #![crate_name = "a"] +#![feature(core)] use std::marker::MarkerTrait; diff --git a/src/test/auxiliary/svh-a-no-change.rs b/src/test/auxiliary/svh-a-no-change.rs index 04f1062c16f..6d4ea499b2b 100644 --- a/src/test/auxiliary/svh-a-no-change.rs +++ b/src/test/auxiliary/svh-a-no-change.rs @@ -14,6 +14,7 @@ //! (#14132). #![crate_name = "a"] +#![feature(core)] use std::marker::MarkerTrait; diff --git a/src/test/auxiliary/svh-a-redundant-cfg.rs b/src/test/auxiliary/svh-a-redundant-cfg.rs index 1e82b74f1ef..f3a31df94b3 100644 --- a/src/test/auxiliary/svh-a-redundant-cfg.rs +++ b/src/test/auxiliary/svh-a-redundant-cfg.rs @@ -14,6 +14,7 @@ //! (#14132). #![crate_name = "a"] +#![feature(core)] use std::marker::MarkerTrait; diff --git a/src/test/auxiliary/svh-a-whitespace.rs b/src/test/auxiliary/svh-a-whitespace.rs index 3c3dac9cdab..bec6b207c07 100644 --- a/src/test/auxiliary/svh-a-whitespace.rs +++ b/src/test/auxiliary/svh-a-whitespace.rs @@ -14,6 +14,7 @@ //! (#14132). #![crate_name = "a"] +#![feature(core)] use std::marker::MarkerTrait; diff --git a/src/test/auxiliary/syntax_extension_with_dll_deps_2.rs b/src/test/auxiliary/syntax_extension_with_dll_deps_2.rs index 07f3b863af8..54da1a1e451 100644 --- a/src/test/auxiliary/syntax_extension_with_dll_deps_2.rs +++ b/src/test/auxiliary/syntax_extension_with_dll_deps_2.rs @@ -11,7 +11,7 @@ // force-host #![crate_type = "dylib"] -#![feature(plugin_registrar, quote)] +#![feature(plugin_registrar, quote, rustc_private)] extern crate "syntax_extension_with_dll_deps_1" as other; extern crate syntax; diff --git a/src/test/auxiliary/trait_impl_conflict.rs b/src/test/auxiliary/trait_impl_conflict.rs index 0982efbdbf4..4a4de2455e3 100644 --- a/src/test/auxiliary/trait_impl_conflict.rs +++ b/src/test/auxiliary/trait_impl_conflict.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + pub trait Foo : ::std::marker::MarkerTrait { } diff --git a/src/test/auxiliary/typeck-default-trait-impl-cross-crate-coherence-lib.rs b/src/test/auxiliary/typeck-default-trait-impl-cross-crate-coherence-lib.rs index 506e7a00c75..5a7a3e7bcc6 100644 --- a/src/test/auxiliary/typeck-default-trait-impl-cross-crate-coherence-lib.rs +++ b/src/test/auxiliary/typeck-default-trait-impl-cross-crate-coherence-lib.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(optin_builtin_traits)] +#![feature(optin_builtin_traits, core)] #![crate_type = "rlib"] use std::marker::MarkerTrait; diff --git a/src/test/auxiliary/typeid-intrinsic.rs b/src/test/auxiliary/typeid-intrinsic.rs index 82f613ee117..82d07a9df4e 100644 --- a/src/test/auxiliary/typeid-intrinsic.rs +++ b/src/test/auxiliary/typeid-intrinsic.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + use std::any::TypeId; pub struct A; diff --git a/src/test/auxiliary/typeid-intrinsic2.rs b/src/test/auxiliary/typeid-intrinsic2.rs index 82f613ee117..82d07a9df4e 100644 --- a/src/test/auxiliary/typeid-intrinsic2.rs +++ b/src/test/auxiliary/typeid-intrinsic2.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + use std::any::TypeId; pub struct A; diff --git a/src/test/auxiliary/weak-lang-items.rs b/src/test/auxiliary/weak-lang-items.rs index 85f49b4bb7f..ceffae79677 100644 --- a/src/test/auxiliary/weak-lang-items.rs +++ b/src/test/auxiliary/weak-lang-items.rs @@ -13,7 +13,7 @@ // This aux-file will require the eh_personality function to be codegen'd, but // it hasn't been defined just yet. Make sure we don't explode. -#![feature(no_std)] +#![feature(no_std, core)] #![no_std] #![crate_type = "rlib"] diff --git a/src/test/bench/core-map.rs b/src/test/bench/core-map.rs index 4909d84a34f..0cff90d61ed 100644 --- a/src/test/bench/core-map.rs +++ b/src/test/bench/core-map.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(unboxed_closures)] +#![feature(unboxed_closures, std_misc, rand)] use std::collections::{BTreeMap, HashMap, HashSet}; use std::env; diff --git a/src/test/bench/core-set.rs b/src/test/bench/core-set.rs index 994c9605fc3..aeedaa288fe 100644 --- a/src/test/bench/core-set.rs +++ b/src/test/bench/core-set.rs @@ -10,7 +10,7 @@ // ignore-pretty very bad with line comments -#![feature(unboxed_closures)] +#![feature(unboxed_closures, rand, std_misc, collections)] extern crate collections; extern crate rand; diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs index c2ea097ed75..0344d6a46ee 100644 --- a/src/test/bench/core-std.rs +++ b/src/test/bench/core-std.rs @@ -11,7 +11,7 @@ // ignore-lexer-test FIXME #15679 // Microbenchmarks for various functions in std and extra -#![feature(unboxed_closures)] +#![feature(unboxed_closures, rand, old_io, old_path, std_misc, collections)] use std::old_io::*; use std::old_path::{Path, GenericPath}; diff --git a/src/test/bench/msgsend-pipes-shared.rs b/src/test/bench/msgsend-pipes-shared.rs index b8d8f0cc9e6..fb95f92da77 100644 --- a/src/test/bench/msgsend-pipes-shared.rs +++ b/src/test/bench/msgsend-pipes-shared.rs @@ -18,6 +18,8 @@ // different scalability characteristics compared to the select // version. +#![feature(std_misc)] + use std::sync::mpsc::{channel, Sender, Receiver}; use std::env; use std::thread; diff --git a/src/test/bench/msgsend-pipes.rs b/src/test/bench/msgsend-pipes.rs index 3642eb82fdb..6d702242d76 100644 --- a/src/test/bench/msgsend-pipes.rs +++ b/src/test/bench/msgsend-pipes.rs @@ -14,6 +14,8 @@ // // I *think* it's the same, more or less. +#![feature(std_misc)] + use std::sync::mpsc::{channel, Sender, Receiver}; use std::env; use std::thread; diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs index a980b7ed9e7..6fb2c954e02 100644 --- a/src/test/bench/msgsend-ring-mutex-arcs.rs +++ b/src/test/bench/msgsend-ring-mutex-arcs.rs @@ -18,6 +18,8 @@ // no-pretty-expanded FIXME #15189 // ignore-lexer-test FIXME #15679 +#![feature(std_misc)] + use std::env; use std::sync::{Arc, Future, Mutex, Condvar}; use std::time::Duration; diff --git a/src/test/bench/noise.rs b/src/test/bench/noise.rs index de88c7733b3..6cd75836187 100644 --- a/src/test/bench/noise.rs +++ b/src/test/bench/noise.rs @@ -12,6 +12,8 @@ // See https://github.com/nsf/pnoise for timings and alternative implementations. // ignore-lexer-test FIXME #15679 +#![feature(rand, core)] + use std::f32::consts::PI; use std::num::Float; use std::rand::{Rng, StdRng}; diff --git a/src/test/bench/shootout-binarytrees.rs b/src/test/bench/shootout-binarytrees.rs index 38fc53ccd36..64c38722137 100644 --- a/src/test/bench/shootout-binarytrees.rs +++ b/src/test/bench/shootout-binarytrees.rs @@ -38,6 +38,8 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED // OF THE POSSIBILITY OF SUCH DAMAGE. +#![feature(rustc_private, core)] + extern crate arena; use std::iter::range_step; diff --git a/src/test/bench/shootout-fannkuch-redux.rs b/src/test/bench/shootout-fannkuch-redux.rs index 3688c224a7d..e23862f4286 100644 --- a/src/test/bench/shootout-fannkuch-redux.rs +++ b/src/test/bench/shootout-fannkuch-redux.rs @@ -38,6 +38,8 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED // OF THE POSSIBILITY OF SUCH DAMAGE. +#![feature(core)] + use std::{cmp, iter, mem}; use std::thread; diff --git a/src/test/bench/shootout-fasta-redux.rs b/src/test/bench/shootout-fasta-redux.rs index 289f05a299b..709b23ef9dd 100644 --- a/src/test/bench/shootout-fasta-redux.rs +++ b/src/test/bench/shootout-fasta-redux.rs @@ -38,6 +38,8 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED // OF THE POSSIBILITY OF SUCH DAMAGE. +#![feature(core, old_io, io, core)] + use std::cmp::min; use std::old_io::*; use std::iter::repeat; diff --git a/src/test/bench/shootout-fasta.rs b/src/test/bench/shootout-fasta.rs index df839fc27ee..78d31faeb51 100644 --- a/src/test/bench/shootout-fasta.rs +++ b/src/test/bench/shootout-fasta.rs @@ -38,6 +38,8 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED // OF THE POSSIBILITY OF SUCH DAMAGE. +#![feature(old_io, old_path, io, core)] + use std::cmp::min; use std::old_io::*; use std::old_io; diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index 88c9f43f6ec..ebdc60cdd2b 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -13,7 +13,7 @@ // multi tasking k-nucleotide -#![feature(box_syntax)] +#![feature(box_syntax, std_misc, old_io, collections, os)] use std::ascii::{AsciiExt, OwnedAsciiExt}; use std::cmp::Ordering::{self, Less, Greater, Equal}; diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index 9e5885041b6..ba4f2c9b1c5 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -40,7 +40,7 @@ // ignore-android see #10393 #13206 -#![feature(box_syntax)] +#![feature(box_syntax, std_misc, collections)] use std::ascii::OwnedAsciiExt; use std::env; diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index 128c92921fa..d248293103b 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -38,7 +38,7 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED // OF THE POSSIBILITY OF SUCH DAMAGE. -#![feature(simd)] +#![feature(simd, old_io, core, io)] // ignore-pretty very bad with line comments diff --git a/src/test/bench/shootout-meteor.rs b/src/test/bench/shootout-meteor.rs index 79a5245a408..150522fd02d 100644 --- a/src/test/bench/shootout-meteor.rs +++ b/src/test/bench/shootout-meteor.rs @@ -40,6 +40,8 @@ // no-pretty-expanded FIXME #15189 +#![feature(core)] + use std::iter::repeat; use std::sync::Arc; use std::sync::mpsc::channel; diff --git a/src/test/bench/shootout-nbody.rs b/src/test/bench/shootout-nbody.rs index 534dfe9548c..3748b65dacb 100644 --- a/src/test/bench/shootout-nbody.rs +++ b/src/test/bench/shootout-nbody.rs @@ -38,6 +38,8 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED // OF THE POSSIBILITY OF SUCH DAMAGE. +#![feature(core)] + use std::num::Float; const PI: f64 = 3.141592653589793; diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs index a542c81f239..4d9bc951fa3 100644 --- a/src/test/bench/shootout-pfib.rs +++ b/src/test/bench/shootout-pfib.rs @@ -18,6 +18,8 @@ */ +#![feature(std_misc, rustc_private)] + extern crate getopts; use std::sync::mpsc::{channel, Sender}; diff --git a/src/test/bench/shootout-reverse-complement.rs b/src/test/bench/shootout-reverse-complement.rs index 93aa5f2571b..875ec670d42 100644 --- a/src/test/bench/shootout-reverse-complement.rs +++ b/src/test/bench/shootout-reverse-complement.rs @@ -40,7 +40,7 @@ // ignore-android see #10393 #13206 -#![feature(unboxed_closures)] +#![feature(unboxed_closures, libc, old_io, collections, io, core)] extern crate libc; diff --git a/src/test/bench/shootout-spectralnorm.rs b/src/test/bench/shootout-spectralnorm.rs index f7514a3e884..3889b404d85 100644 --- a/src/test/bench/shootout-spectralnorm.rs +++ b/src/test/bench/shootout-spectralnorm.rs @@ -41,7 +41,7 @@ // no-pretty-expanded FIXME #15189 #![allow(non_snake_case)] -#![feature(unboxed_closures)] +#![feature(unboxed_closures, core, os)] use std::iter::{repeat, AdditiveIterator}; use std::thread; diff --git a/src/test/bench/std-smallintmap.rs b/src/test/bench/std-smallintmap.rs index a54a869412e..dd56b18c144 100644 --- a/src/test/bench/std-smallintmap.rs +++ b/src/test/bench/std-smallintmap.rs @@ -10,6 +10,8 @@ // Microbenchmark for the smallintmap library +#![feature(collections, std_misc)] + use std::collections::VecMap; use std::env; use std::time::Duration; diff --git a/src/test/bench/sudoku.rs b/src/test/bench/sudoku.rs index 9a82614510e..3913de3a3f9 100644 --- a/src/test/bench/sudoku.rs +++ b/src/test/bench/sudoku.rs @@ -10,7 +10,7 @@ // ignore-pretty very bad with line comments -#![feature(box_syntax)] +#![feature(box_syntax, core)] #![allow(non_snake_case)] use std::io::prelude::*; diff --git a/src/test/bench/task-perf-alloc-unwind.rs b/src/test/bench/task-perf-alloc-unwind.rs index 896b0ee57a0..d8f4603ab1a 100644 --- a/src/test/bench/task-perf-alloc-unwind.rs +++ b/src/test/bench/task-perf-alloc-unwind.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(unsafe_destructor, box_syntax)] +#![feature(unsafe_destructor, box_syntax, std_misc, collections)] use std::env; use std::thread; diff --git a/src/test/compile-fail/internal-unstable-noallow.rs b/src/test/compile-fail/internal-unstable-noallow.rs index 4e296198be8..2b48d47e940 100644 --- a/src/test/compile-fail/internal-unstable-noallow.rs +++ b/src/test/compile-fail/internal-unstable-noallow.rs @@ -16,13 +16,10 @@ // aux-build:internal_unstable.rs // error-pattern:use of unstable library feature 'function' // error-pattern:use of unstable library feature 'struct_field' -// error-pattern:compilation successful -#![feature(rustc_attrs)] #[macro_use] extern crate internal_unstable; -#[rustc_error] fn main() { call_unstable_noallow!(); diff --git a/src/test/compile-fail/internal-unstable-thread-local.rs b/src/test/compile-fail/internal-unstable-thread-local.rs index ff158497546..74526fb3d83 100644 --- a/src/test/compile-fail/internal-unstable-thread-local.rs +++ b/src/test/compile-fail/internal-unstable-thread-local.rs @@ -10,14 +10,12 @@ // aux-build:internal_unstable.rs -#![feature(rustc_attrs)] #![allow(dead_code)] extern crate internal_unstable; thread_local!(static FOO: () = ()); -thread_local!(static BAR: () = internal_unstable::unstable()); //~ WARN use of unstable +thread_local!(static BAR: () = internal_unstable::unstable()); //~ ERROR use of unstable -#[rustc_error] -fn main() {} //~ ERROR +fn main() {} diff --git a/src/test/compile-fail/internal-unstable.rs b/src/test/compile-fail/internal-unstable.rs index 8674e8ab5b2..accc898b8a8 100755 --- a/src/test/compile-fail/internal-unstable.rs +++ b/src/test/compile-fail/internal-unstable.rs @@ -10,7 +10,7 @@ // aux-build:internal_unstable.rs -#![feature(rustc_attrs, allow_internal_unstable)] +#![feature(allow_internal_unstable)] #[macro_use] extern crate internal_unstable; @@ -19,7 +19,7 @@ macro_rules! foo { ($e: expr, $f: expr) => {{ $e; $f; - internal_unstable::unstable(); //~ WARN use of unstable + internal_unstable::unstable(); //~ ERROR use of unstable }} } @@ -32,20 +32,19 @@ macro_rules! bar { }} } -#[rustc_error] -fn main() { //~ ERROR +fn main() { // ok, the instability is contained. call_unstable_allow!(); construct_unstable_allow!(0); // bad. - pass_through_allow!(internal_unstable::unstable()); //~ WARN use of unstable + pass_through_allow!(internal_unstable::unstable()); //~ ERROR use of unstable - pass_through_noallow!(internal_unstable::unstable()); //~ WARN use of unstable + pass_through_noallow!(internal_unstable::unstable()); //~ ERROR use of unstable - println!("{:?}", internal_unstable::unstable()); //~ WARN use of unstable + println!("{:?}", internal_unstable::unstable()); //~ ERROR use of unstable - bar!(internal_unstable::unstable()); //~ WARN use of unstable + bar!(internal_unstable::unstable()); //~ ERROR use of unstable } diff --git a/src/test/compile-fail/lint-output-format.rs b/src/test/compile-fail/lint-output-format.rs index ec4e3c774db..d95ed7f10bd 100644 --- a/src/test/compile-fail/lint-output-format.rs +++ b/src/test/compile-fail/lint-output-format.rs @@ -13,10 +13,10 @@ #![feature(foo)] //~ ERROR unused or unknown feature -extern crate lint_output_format; //~ WARNING: use of unstable library feature +extern crate lint_output_format; //~ ERROR use of unstable library feature use lint_output_format::{foo, bar}; fn main() { let _x = foo(); //~ WARNING #[warn(deprecated)] on by default - let _y = bar(); //~ WARNING: use of unstable library feature + let _y = bar(); //~ ERROR use of unstable library feature } diff --git a/src/test/compile-fail/lint-stability-fields.rs b/src/test/compile-fail/lint-stability-fields.rs index c43ff198925..716d7674b2d 100644 --- a/src/test/compile-fail/lint-stability-fields.rs +++ b/src/test/compile-fail/lint-stability-fields.rs @@ -22,24 +22,24 @@ mod cross_crate { pub fn foo() { let x = Stable { inherit: 1, - override1: 2, //~ WARN use of unstable + override1: 2, //~ ERROR use of unstable override2: 3, //~^ ERROR use of deprecated item - //~^^ WARN use of unstable + //~^^ ERROR use of unstable }; let _ = x.inherit; - let _ = x.override1; //~ WARN use of unstable + let _ = x.override1; //~ ERROR use of unstable let _ = x.override2; //~^ ERROR use of deprecated item - //~^^ WARN use of unstable + //~^^ ERROR use of unstable let Stable { inherit: _, - override1: _, //~ WARN use of unstable + override1: _, //~ ERROR use of unstable override2: _ //~^ ERROR use of deprecated item - //~^^ WARN use of unstable + //~^^ ERROR use of unstable } = x; // all fine let Stable { .. } = x; @@ -47,122 +47,122 @@ mod cross_crate { let x = Stable2(1, 2, 3); let _ = x.0; - let _ = x.1; //~ WARN use of unstable + let _ = x.1; //~ ERROR use of unstable let _ = x.2; //~^ ERROR use of deprecated item - //~^^ WARN use of unstable + //~^^ ERROR use of unstable let Stable2(_, - _, //~ WARN use of unstable + _, //~ ERROR use of unstable _) //~^ ERROR use of deprecated item - //~^^ WARN use of unstable + //~^^ ERROR use of unstable = x; // all fine let Stable2(..) = x; - let x = Unstable { //~ WARN use of unstable - inherit: 1, //~ WARN use of unstable + let x = Unstable { //~ ERROR use of unstable + inherit: 1, //~ ERROR use of unstable override1: 2, override2: 3, //~^ ERROR use of deprecated item - //~^^ WARN use of unstable + //~^^ ERROR use of unstable }; - let _ = x.inherit; //~ WARN use of unstable + let _ = x.inherit; //~ ERROR use of unstable let _ = x.override1; let _ = x.override2; //~^ ERROR use of deprecated item - //~^^ WARN use of unstable + //~^^ ERROR use of unstable - let Unstable { //~ WARN use of unstable - inherit: _, //~ WARN use of unstable + let Unstable { //~ ERROR use of unstable + inherit: _, //~ ERROR use of unstable override1: _, override2: _ //~^ ERROR use of deprecated item - //~^^ WARN use of unstable + //~^^ ERROR use of unstable } = x; - let Unstable //~ WARN use of unstable + let Unstable //~ ERROR use of unstable // the patterns are all fine: { .. } = x; - let x = Unstable2(1, 2, 3); //~ WARN use of unstable + let x = Unstable2(1, 2, 3); //~ ERROR use of unstable - let _ = x.0; //~ WARN use of unstable + let _ = x.0; //~ ERROR use of unstable let _ = x.1; let _ = x.2; //~^ ERROR use of deprecated item - //~^^ WARN use of unstable + //~^^ ERROR use of unstable - let Unstable2 //~ WARN use of unstable - (_, //~ WARN use of unstable + let Unstable2 //~ ERROR use of unstable + (_, //~ ERROR use of unstable _, _) //~^ ERROR use of deprecated item - //~^^ WARN use of unstable + //~^^ ERROR use of unstable = x; - let Unstable2 //~ WARN use of unstable + let Unstable2 //~ ERROR use of unstable // the patterns are all fine: (..) = x; let x = Deprecated { //~^ ERROR use of deprecated item - //~^^ WARN use of unstable + //~^^ ERROR use of unstable inherit: 1, //~^ ERROR use of deprecated item - //~^^ WARN use of unstable + //~^^ ERROR use of unstable override1: 2, - override2: 3, //~ WARN use of unstable + override2: 3, //~ ERROR use of unstable }; let _ = x.inherit; //~^ ERROR use of deprecated item - //~^^ WARN use of unstable + //~^^ ERROR use of unstable let _ = x.override1; - let _ = x.override2; //~ WARN use of unstable + let _ = x.override2; //~ ERROR use of unstable let Deprecated { //~^ ERROR use of deprecated item - //~^^ WARN use of unstable + //~^^ ERROR use of unstable inherit: _, //~^ ERROR use of deprecated item - //~^^ WARN use of unstable + //~^^ ERROR use of unstable override1: _, - override2: _ //~ WARN use of unstable + override2: _ //~ ERROR use of unstable } = x; let Deprecated //~^ ERROR use of deprecated item - //~^^ WARN use of unstable + //~^^ ERROR use of unstable // the patterns are all fine: { .. } = x; let x = Deprecated2(1, 2, 3); //~^ ERROR use of deprecated item - //~^^ WARN use of unstable + //~^^ ERROR use of unstable let _ = x.0; //~^ ERROR use of deprecated item - //~^^ WARN use of unstable + //~^^ ERROR use of unstable let _ = x.1; - let _ = x.2; //~ WARN use of unstable + let _ = x.2; //~ ERROR use of unstable let Deprecated2 //~^ ERROR use of deprecated item - //~^^ WARN use of unstable + //~^^ ERROR use of unstable (_, //~^ ERROR use of deprecated item - //~^^ WARN use of unstable + //~^^ ERROR use of unstable _, - _) //~ WARN use of unstable + _) //~ ERROR use of unstable = x; let Deprecated2 //~^ ERROR use of deprecated item - //~^^ WARN use of unstable + //~^^ ERROR use of unstable // the patterns are all fine: (..) = x; } diff --git a/src/test/compile-fail/lint-stability.rs b/src/test/compile-fail/lint-stability.rs index 12548c45396..391b49e1068 100644 --- a/src/test/compile-fail/lint-stability.rs +++ b/src/test/compile-fail/lint-stability.rs @@ -24,7 +24,7 @@ extern crate lint_stability; mod cross_crate { extern crate stability_cfg1; - extern crate stability_cfg2; //~ WARNING: use of unstable library feature + extern crate stability_cfg2; //~ ERROR use of unstable library feature use lint_stability::*; @@ -51,64 +51,64 @@ mod cross_crate { ::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text deprecated_unstable(); //~ ERROR use of deprecated item - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature foo.method_deprecated_unstable(); //~ ERROR use of deprecated item - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature Foo::method_deprecated_unstable(&foo); //~ ERROR use of deprecated item - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature ::method_deprecated_unstable(&foo); //~ ERROR use of deprecated item - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature foo.trait_deprecated_unstable(); //~ ERROR use of deprecated item - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature Trait::trait_deprecated_unstable(&foo); //~ ERROR use of deprecated item - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature ::trait_deprecated_unstable(&foo); //~ ERROR use of deprecated item - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature ::trait_deprecated_unstable(&foo); //~ ERROR use of deprecated item - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature deprecated_unstable_text(); //~ ERROR use of deprecated item: text - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature foo.method_deprecated_unstable_text(); //~ ERROR use of deprecated item: text - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature Foo::method_deprecated_unstable_text(&foo); //~ ERROR use of deprecated item: text - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature ::method_deprecated_unstable_text(&foo); //~ ERROR use of deprecated item: text - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature foo.trait_deprecated_unstable_text(); //~ ERROR use of deprecated item: text - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature Trait::trait_deprecated_unstable_text(&foo); //~ ERROR use of deprecated item: text - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature ::trait_deprecated_unstable_text(&foo); //~ ERROR use of deprecated item: text - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature ::trait_deprecated_unstable_text(&foo); //~ ERROR use of deprecated item: text - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature - unstable(); //~ WARNING use of unstable library feature - foo.method_unstable(); //~ WARNING use of unstable library feature - Foo::method_unstable(&foo); //~ WARNING use of unstable library feature - ::method_unstable(&foo); //~ WARNING use of unstable library feature - foo.trait_unstable(); //~ WARNING use of unstable library feature - Trait::trait_unstable(&foo); //~ WARNING use of unstable library feature - ::trait_unstable(&foo); //~ WARNING use of unstable library feature - ::trait_unstable(&foo); //~ WARNING use of unstable library feature + unstable(); //~ ERROR use of unstable library feature + foo.method_unstable(); //~ ERROR use of unstable library feature + Foo::method_unstable(&foo); //~ ERROR use of unstable library feature + ::method_unstable(&foo); //~ ERROR use of unstable library feature + foo.trait_unstable(); //~ ERROR use of unstable library feature + Trait::trait_unstable(&foo); //~ ERROR use of unstable library feature + ::trait_unstable(&foo); //~ ERROR use of unstable library feature + ::trait_unstable(&foo); //~ ERROR use of unstable library feature unstable_text(); - //~^ WARNING use of unstable library feature 'test_feature': text + //~^ ERROR use of unstable library feature 'test_feature': text foo.method_unstable_text(); - //~^ WARNING use of unstable library feature 'test_feature': text + //~^ ERROR use of unstable library feature 'test_feature': text Foo::method_unstable_text(&foo); - //~^ WARNING use of unstable library feature 'test_feature': text + //~^ ERROR use of unstable library feature 'test_feature': text ::method_unstable_text(&foo); - //~^ WARNING use of unstable library feature 'test_feature': text + //~^ ERROR use of unstable library feature 'test_feature': text foo.trait_unstable_text(); - //~^ WARNING use of unstable library feature 'test_feature': text + //~^ ERROR use of unstable library feature 'test_feature': text Trait::trait_unstable_text(&foo); - //~^ WARNING use of unstable library feature 'test_feature': text + //~^ ERROR use of unstable library feature 'test_feature': text ::trait_unstable_text(&foo); - //~^ WARNING use of unstable library feature 'test_feature': text + //~^ ERROR use of unstable library feature 'test_feature': text ::trait_unstable_text(&foo); - //~^ WARNING use of unstable library feature 'test_feature': text + //~^ ERROR use of unstable library feature 'test_feature': text stable(); foo.method_stable(); @@ -130,26 +130,26 @@ mod cross_crate { let _ = DeprecatedStruct { i: 0 }; //~ ERROR use of deprecated item let _ = DeprecatedUnstableStruct { i: 0 }; //~ ERROR use of deprecated item - //~^ WARNING use of unstable library feature - let _ = UnstableStruct { i: 0 }; //~ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature + let _ = UnstableStruct { i: 0 }; //~ ERROR use of unstable library feature let _ = StableStruct { i: 0 }; let _ = DeprecatedUnitStruct; //~ ERROR use of deprecated item let _ = DeprecatedUnstableUnitStruct; //~ ERROR use of deprecated item - //~^ WARNING use of unstable library feature - let _ = UnstableUnitStruct; //~ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature + let _ = UnstableUnitStruct; //~ ERROR use of unstable library feature let _ = StableUnitStruct; let _ = Enum::DeprecatedVariant; //~ ERROR use of deprecated item let _ = Enum::DeprecatedUnstableVariant; //~ ERROR use of deprecated item - //~^ WARNING use of unstable library feature - let _ = Enum::UnstableVariant; //~ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature + let _ = Enum::UnstableVariant; //~ ERROR use of unstable library feature let _ = Enum::StableVariant; let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated item let _ = DeprecatedUnstableTupleStruct (1); //~ ERROR use of deprecated item - //~^ WARNING use of unstable library feature - let _ = UnstableTupleStruct (1); //~ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature + let _ = UnstableTupleStruct (1); //~ ERROR use of unstable library feature let _ = StableTupleStruct (1); // At the moment, the lint checker only checks stability in @@ -159,7 +159,7 @@ mod cross_crate { // on macros themselves are not yet linted. macro_test_arg!(deprecated_text()); //~ ERROR use of deprecated item: text macro_test_arg!(deprecated_unstable_text()); //~ ERROR use of deprecated item: text - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature macro_test_arg!(macro_test_arg!(deprecated_text())); //~ ERROR use of deprecated item: text } @@ -173,33 +173,33 @@ mod cross_crate { ::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text ::trait_deprecated_text(&foo); //~ ERROR use of deprecated item: text foo.trait_deprecated_unstable(); //~ ERROR use of deprecated item - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature Trait::trait_deprecated_unstable(&foo); //~ ERROR use of deprecated item - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature ::trait_deprecated_unstable(&foo); //~ ERROR use of deprecated item - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature ::trait_deprecated_unstable(&foo); //~ ERROR use of deprecated item - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature foo.trait_deprecated_unstable_text(); //~ ERROR use of deprecated item: text - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature Trait::trait_deprecated_unstable_text(&foo); //~ ERROR use of deprecated item: text - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature ::trait_deprecated_unstable_text(&foo); //~ ERROR use of deprecated item: text - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature ::trait_deprecated_unstable_text(&foo); //~ ERROR use of deprecated item: text - //~^ WARNING use of unstable library feature - foo.trait_unstable(); //~ WARNING use of unstable library feature - Trait::trait_unstable(&foo); //~ WARNING use of unstable library feature - ::trait_unstable(&foo); //~ WARNING use of unstable library feature - ::trait_unstable(&foo); //~ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature + foo.trait_unstable(); //~ ERROR use of unstable library feature + Trait::trait_unstable(&foo); //~ ERROR use of unstable library feature + ::trait_unstable(&foo); //~ ERROR use of unstable library feature + ::trait_unstable(&foo); //~ ERROR use of unstable library feature foo.trait_unstable_text(); - //~^ WARNING use of unstable library feature 'test_feature': text + //~^ ERROR use of unstable library feature 'test_feature': text Trait::trait_unstable_text(&foo); - //~^ WARNING use of unstable library feature 'test_feature': text + //~^ ERROR use of unstable library feature 'test_feature': text ::trait_unstable_text(&foo); - //~^ WARNING use of unstable library feature 'test_feature': text + //~^ ERROR use of unstable library feature 'test_feature': text ::trait_unstable_text(&foo); - //~^ WARNING use of unstable library feature 'test_feature': text + //~^ ERROR use of unstable library feature 'test_feature': text foo.trait_stable(); Trait::trait_stable(&foo); ::trait_stable(&foo); @@ -210,46 +210,46 @@ mod cross_crate { foo.trait_deprecated(); //~ ERROR use of deprecated item foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text foo.trait_deprecated_unstable(); //~ ERROR use of deprecated item - //~^ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature foo.trait_deprecated_unstable_text(); //~ ERROR use of deprecated item: text - //~^ WARNING use of unstable library feature - foo.trait_unstable(); //~ WARNING use of unstable library feature + //~^ ERROR use of unstable library feature + foo.trait_unstable(); //~ ERROR use of unstable library feature foo.trait_unstable_text(); - //~^ WARNING use of unstable library feature 'test_feature': text + //~^ ERROR use of unstable library feature 'test_feature': text foo.trait_stable(); } struct S; - impl UnstableTrait for S { } //~ WARNING use of unstable library feature + impl UnstableTrait for S { } //~ ERROR use of unstable library feature - trait LocalTrait : UnstableTrait { } //~ WARNING use of unstable library feature + trait LocalTrait : UnstableTrait { } //~ ERROR use of unstable library feature impl Trait for S { fn trait_stable(&self) {} - fn trait_unstable(&self) {} //~ WARNING use of unstable library feature + fn trait_unstable(&self) {} //~ ERROR use of unstable library feature } } mod inheritance { - extern crate inherited_stability; //~ WARNING: use of unstable library feature - use self::inherited_stability::*; //~ WARNING: use of unstable library feature + extern crate inherited_stability; //~ ERROR use of unstable library feature + use self::inherited_stability::*; //~ ERROR use of unstable library feature fn test_inheritance() { - unstable(); //~ WARNING use of unstable library feature + unstable(); //~ ERROR use of unstable library feature stable(); - stable_mod::unstable(); //~ WARNING use of unstable library feature + stable_mod::unstable(); //~ ERROR use of unstable library feature stable_mod::stable(); unstable_mod::deprecated(); //~ ERROR use of deprecated item - unstable_mod::unstable(); //~ WARNING use of unstable library feature + unstable_mod::unstable(); //~ ERROR use of unstable library feature - let _ = Unstable::UnstableVariant; //~ WARNING use of unstable library feature + let _ = Unstable::UnstableVariant; //~ ERROR use of unstable library feature let _ = Unstable::StableVariant; let x: usize = 0; - x.unstable(); //~ WARNING use of unstable library feature + x.unstable(); //~ ERROR use of unstable library feature x.stable(); } } diff --git a/src/test/debuginfo/constant-debug-locs.rs b/src/test/debuginfo/constant-debug-locs.rs index 24332e31775..f150e84b9fd 100644 --- a/src/test/debuginfo/constant-debug-locs.rs +++ b/src/test/debuginfo/constant-debug-locs.rs @@ -16,6 +16,7 @@ #![allow(unused_variables)] #![allow(dead_code)] #![omit_gdb_pretty_printer_section] +#![feature(std_misc, core)] // This test makes sure that the compiler doesn't crash when trying to assign // debug locations to const-expressions. diff --git a/src/test/debuginfo/function-arg-initialization.rs b/src/test/debuginfo/function-arg-initialization.rs index 7cefb6044f6..c161600f2c3 100644 --- a/src/test/debuginfo/function-arg-initialization.rs +++ b/src/test/debuginfo/function-arg-initialization.rs @@ -17,6 +17,8 @@ // compile-flags:-g +#![feature(old_io)] + // === GDB TESTS =================================================================================== // gdb-command:run diff --git a/src/test/debuginfo/function-prologue-stepping-no-stack-check.rs b/src/test/debuginfo/function-prologue-stepping-no-stack-check.rs index 8d456f33432..99e31ab2302 100644 --- a/src/test/debuginfo/function-prologue-stepping-no-stack-check.rs +++ b/src/test/debuginfo/function-prologue-stepping-no-stack-check.rs @@ -20,6 +20,8 @@ // compile-flags:-g +#![feature(old_io)] + // === GDB TESTS =================================================================================== // gdb-command:rbreak immediate_args diff --git a/src/test/debuginfo/issue13213.rs b/src/test/debuginfo/issue13213.rs index a079ddbd0f5..38b149ef243 100644 --- a/src/test/debuginfo/issue13213.rs +++ b/src/test/debuginfo/issue13213.rs @@ -11,6 +11,9 @@ // min-lldb-version: 310 // aux-build:issue13213aux.rs + +#![feature(old_io)] + extern crate issue13213aux; // compile-flags:-g diff --git a/src/test/debuginfo/simd.rs b/src/test/debuginfo/simd.rs index 12c7b146342..16ae83ee8dc 100644 --- a/src/test/debuginfo/simd.rs +++ b/src/test/debuginfo/simd.rs @@ -42,6 +42,7 @@ #![allow(unused_variables)] #![omit_gdb_pretty_printer_section] +#![feature(core)] use std::simd::{i8x16, i16x8,i32x4,i64x2,u8x16,u16x8,u32x4,u64x2,f32x4,f64x2}; diff --git a/src/test/run-fail/extern-panic.rs b/src/test/run-fail/extern-panic.rs index 127700e963a..bddab59e3e4 100644 --- a/src/test/run-fail/extern-panic.rs +++ b/src/test/run-fail/extern-panic.rs @@ -12,6 +12,7 @@ // error-pattern:explicit failure // Testing that runtime failure doesn't cause callbacks to abort abnormally. // Instead the failure will be delivered after the callbacks return. +#![feature(std_misc, libc)] extern crate libc; use std::task; diff --git a/src/test/run-fail/rt-set-exit-status-panic.rs b/src/test/run-fail/rt-set-exit-status-panic.rs index fd7c3f8cc0e..0e72ab22dc8 100644 --- a/src/test/run-fail/rt-set-exit-status-panic.rs +++ b/src/test/run-fail/rt-set-exit-status-panic.rs @@ -10,6 +10,8 @@ // error-pattern:whatever +#![feature(os, rustc_private)] + #[macro_use] extern crate log; use std::os; diff --git a/src/test/run-fail/rt-set-exit-status-panic2.rs b/src/test/run-fail/rt-set-exit-status-panic2.rs index fb1e03c234d..2498b7c2be4 100644 --- a/src/test/run-fail/rt-set-exit-status-panic2.rs +++ b/src/test/run-fail/rt-set-exit-status-panic2.rs @@ -10,6 +10,8 @@ // error-pattern:whatever +#![feature(os, rustc_private)] + #[macro_use] extern crate log; use std::os; use std::thread; diff --git a/src/test/run-fail/rt-set-exit-status.rs b/src/test/run-fail/rt-set-exit-status.rs index 39ece8a464a..9425a1b1902 100644 --- a/src/test/run-fail/rt-set-exit-status.rs +++ b/src/test/run-fail/rt-set-exit-status.rs @@ -10,6 +10,8 @@ // error-pattern:whatever +#![feature(rustc_private, os)] + #[macro_use] extern crate log; use std::os; diff --git a/src/test/run-make/allow-warnings-cmdline-stability/foo.rs b/src/test/run-make/allow-warnings-cmdline-stability/foo.rs index fb23a214016..a36cc474c2b 100644 --- a/src/test/run-make/allow-warnings-cmdline-stability/foo.rs +++ b/src/test/run-make/allow-warnings-cmdline-stability/foo.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(test_feature)] + extern crate bar; pub fn main() { bar::baz() } diff --git a/src/test/run-make/cannot-read-embedded-idents/create_and_compile.rs b/src/test/run-make/cannot-read-embedded-idents/create_and_compile.rs index fd69d2786b8..02af5244b8a 100644 --- a/src/test/run-make/cannot-read-embedded-idents/create_and_compile.rs +++ b/src/test/run-make/cannot-read-embedded-idents/create_and_compile.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(old_io, old_path)] + use std::env; use std::fs::File; use std::process::Command; diff --git a/src/test/run-make/extern-fn-reachable/main.rs b/src/test/run-make/extern-fn-reachable/main.rs index 86eed9dbe0a..2e1fad5a044 100644 --- a/src/test/run-make/extern-fn-reachable/main.rs +++ b/src/test/run-make/extern-fn-reachable/main.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc, old_path, os)] + use std::dynamic_lib::DynamicLibrary; use std::os; use std::old_path::Path; diff --git a/src/test/run-make/intrinsic-unreachable/exit-unreachable.rs b/src/test/run-make/intrinsic-unreachable/exit-unreachable.rs index 835e068c15c..aec76fdf1b2 100644 --- a/src/test/run-make/intrinsic-unreachable/exit-unreachable.rs +++ b/src/test/run-make/intrinsic-unreachable/exit-unreachable.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(asm)] +#![feature(asm, core)] #![crate_type="lib"] use std::intrinsics; diff --git a/src/test/run-make/issue-19371/foo.rs b/src/test/run-make/issue-19371/foo.rs index 1ed816ed729..b089b9269a2 100644 --- a/src/test/run-make/issue-19371/foo.rs +++ b/src/test/run-make/issue-19371/foo.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(rustc_private, path)] + extern crate rustc; extern crate rustc_driver; extern crate rustc_lint; diff --git a/src/test/run-make/link-path-order/main.rs b/src/test/run-make/link-path-order/main.rs index cd286af602a..b1576ccd48e 100644 --- a/src/test/run-make/link-path-order/main.rs +++ b/src/test/run-make/link-path-order/main.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(libc, os)] + extern crate libc; #[link(name="foo")] diff --git a/src/test/run-make/lto-syntax-extension/main.rs b/src/test/run-make/lto-syntax-extension/main.rs index a38b2cfb962..c9395f557fd 100644 --- a/src/test/run-make/lto-syntax-extension/main.rs +++ b/src/test/run-make/lto-syntax-extension/main.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(rustc_private)] + extern crate lib; #[macro_use] extern crate log; diff --git a/src/test/run-make/no-duplicate-libs/bar.rs b/src/test/run-make/no-duplicate-libs/bar.rs index 0bec6148189..29f52f97a88 100644 --- a/src/test/run-make/no-duplicate-libs/bar.rs +++ b/src/test/run-make/no-duplicate-libs/bar.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(lang_items, no_std)] +#![feature(lang_items, no_std, libc)] #![no_std] #![crate_type = "dylib"] diff --git a/src/test/run-make/no-duplicate-libs/foo.rs b/src/test/run-make/no-duplicate-libs/foo.rs index 9e8afdc5696..ae424c6569d 100644 --- a/src/test/run-make/no-duplicate-libs/foo.rs +++ b/src/test/run-make/no-duplicate-libs/foo.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(lang_items, no_std)] +#![feature(lang_items, no_std, libc)] #![no_std] #![crate_type = "dylib"] diff --git a/src/test/run-make/rustdoc-default-impl/foo.rs b/src/test/run-make/rustdoc-default-impl/foo.rs index 08f3bd10e74..c2531bf4586 100644 --- a/src/test/run-make/rustdoc-default-impl/foo.rs +++ b/src/test/run-make/rustdoc-default-impl/foo.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + pub mod bar { use std::marker; diff --git a/src/test/run-make/save-analysis/foo.rs b/src/test/run-make/save-analysis/foo.rs index 2e2b8d2578e..74251c3c63e 100644 --- a/src/test/run-make/save-analysis/foo.rs +++ b/src/test/run-make/save-analysis/foo.rs @@ -10,7 +10,7 @@ #![ crate_name = "test" ] #![allow(unstable)] -#![feature(box_syntax)] +#![feature(box_syntax, old_io, rustc_private, core)] extern crate graphviz; // A simple rust project diff --git a/src/test/run-make/unicode-input/multiple_files.rs b/src/test/run-make/unicode-input/multiple_files.rs index 1826e035e24..aa2ce785771 100644 --- a/src/test/run-make/unicode-input/multiple_files.rs +++ b/src/test/run-make/unicode-input/multiple_files.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(rand)] + use std::fs::File; use std::io::prelude::*; use std::path::Path; diff --git a/src/test/run-make/unicode-input/span_length.rs b/src/test/run-make/unicode-input/span_length.rs index 9ed20ccaea5..ebf3226334c 100644 --- a/src/test/run-make/unicode-input/span_length.rs +++ b/src/test/run-make/unicode-input/span_length.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(rand, core)] + use std::fs::File; use std::io::prelude::*; use std::iter::repeat; diff --git a/src/test/run-make/volatile-intrinsics/main.rs b/src/test/run-make/volatile-intrinsics/main.rs index 6dffb53e4a3..bdd557b6cc2 100644 --- a/src/test/run-make/volatile-intrinsics/main.rs +++ b/src/test/run-make/volatile-intrinsics/main.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + use std::intrinsics::{volatile_load, volatile_store}; pub fn main() { diff --git a/src/test/run-pass-fulldeps/compiler-calls.rs b/src/test/run-pass-fulldeps/compiler-calls.rs index 8492424a145..7a3c32a45f9 100644 --- a/src/test/run-pass-fulldeps/compiler-calls.rs +++ b/src/test/run-pass-fulldeps/compiler-calls.rs @@ -12,7 +12,7 @@ // ignore-android -#![feature(rustc_private)] +#![feature(rustc_private, path)] #![feature(core)] extern crate getopts; diff --git a/src/test/run-pass-fulldeps/issue-16992.rs b/src/test/run-pass-fulldeps/issue-16992.rs index 9e3ad8ee283..40947b2e256 100644 --- a/src/test/run-pass-fulldeps/issue-16992.rs +++ b/src/test/run-pass-fulldeps/issue-16992.rs @@ -11,7 +11,7 @@ // ignore-pretty // ignore-android -#![feature(quote)] +#![feature(quote, rustc_private)] extern crate syntax; diff --git a/src/test/run-pass-fulldeps/issue-18763-quote-token-tree.rs b/src/test/run-pass-fulldeps/issue-18763-quote-token-tree.rs index aeb6a89a98e..d4dc5627044 100644 --- a/src/test/run-pass-fulldeps/issue-18763-quote-token-tree.rs +++ b/src/test/run-pass-fulldeps/issue-18763-quote-token-tree.rs @@ -11,7 +11,7 @@ // ignore-android // ignore-pretty: does not work well with `--test` -#![feature(quote)] +#![feature(quote, rustc_private)] extern crate syntax; diff --git a/src/test/run-pass-fulldeps/quote-tokens.rs b/src/test/run-pass-fulldeps/quote-tokens.rs index 020f5f562d2..0e2e1f2dd86 100644 --- a/src/test/run-pass-fulldeps/quote-tokens.rs +++ b/src/test/run-pass-fulldeps/quote-tokens.rs @@ -11,7 +11,7 @@ // ignore-android // ignore-pretty: does not work well with `--test` -#![feature(quote)] +#![feature(quote, rustc_private)] extern crate syntax; diff --git a/src/test/run-pass-fulldeps/quote-unused-sp-no-warning.rs b/src/test/run-pass-fulldeps/quote-unused-sp-no-warning.rs index 848ea738ed7..928368fabdf 100644 --- a/src/test/run-pass-fulldeps/quote-unused-sp-no-warning.rs +++ b/src/test/run-pass-fulldeps/quote-unused-sp-no-warning.rs @@ -11,7 +11,7 @@ // ignore-android // ignore-pretty: does not work well with `--test` -#![feature(quote)] +#![feature(quote, rustc_private)] #![deny(unused_variable)] extern crate syntax; diff --git a/src/test/run-pass-fulldeps/syntax-extension-with-dll-deps.rs b/src/test/run-pass-fulldeps/syntax-extension-with-dll-deps.rs index b7570eb0926..23096828c4b 100644 --- a/src/test/run-pass-fulldeps/syntax-extension-with-dll-deps.rs +++ b/src/test/run-pass-fulldeps/syntax-extension-with-dll-deps.rs @@ -12,7 +12,7 @@ // aux-build:syntax_extension_with_dll_deps_2.rs // ignore-stage1 -#![feature(plugin)] +#![feature(plugin, rustc_private)] #![plugin(syntax_extension_with_dll_deps_2)] fn main() { diff --git a/src/test/run-pass-valgrind/cleanup-stdin.rs b/src/test/run-pass-valgrind/cleanup-stdin.rs index 127be1f90d5..301c4b91781 100644 --- a/src/test/run-pass-valgrind/cleanup-stdin.rs +++ b/src/test/run-pass-valgrind/cleanup-stdin.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(old_io, io)] + fn main() { let _ = std::old_io::stdin(); let _ = std::io::stdin(); diff --git a/src/test/run-pass/anon-extern-mod.rs b/src/test/run-pass/anon-extern-mod.rs index 78e1cdabb47..cbef2850add 100644 --- a/src/test/run-pass/anon-extern-mod.rs +++ b/src/test/run-pass/anon-extern-mod.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(libc)] + extern crate libc; #[link(name = "rust_test_helpers")] diff --git a/src/test/run-pass/associated-types-basic.rs b/src/test/run-pass/associated-types-basic.rs index f5521f7da85..a5be906b159 100644 --- a/src/test/run-pass/associated-types-basic.rs +++ b/src/test/run-pass/associated-types-basic.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + use std::marker::MarkerTrait; trait Foo : MarkerTrait { diff --git a/src/test/run-pass/associated-types-issue-20371.rs b/src/test/run-pass/associated-types-issue-20371.rs index 40ef7f3531c..e1da26b5e29 100644 --- a/src/test/run-pass/associated-types-issue-20371.rs +++ b/src/test/run-pass/associated-types-issue-20371.rs @@ -11,6 +11,8 @@ // Test that we are able to have an impl that defines an associated type // before the actual trait. +#![feature(core)] + use std::marker::MarkerTrait; impl X for f64 { type Y = int; } diff --git a/src/test/run-pass/associated-types-nested-projections.rs b/src/test/run-pass/associated-types-nested-projections.rs index 2ee8ef0d3dd..2f36014f765 100644 --- a/src/test/run-pass/associated-types-nested-projections.rs +++ b/src/test/run-pass/associated-types-nested-projections.rs @@ -10,6 +10,8 @@ // Test that we can resolve nested projection types. Issue #20666. +#![feature(core)] + use std::marker::MarkerTrait; use std::slice; diff --git a/src/test/run-pass/associated-types-normalize-in-bounds-binding.rs b/src/test/run-pass/associated-types-normalize-in-bounds-binding.rs index de96af83f59..236601b9c16 100644 --- a/src/test/run-pass/associated-types-normalize-in-bounds-binding.rs +++ b/src/test/run-pass/associated-types-normalize-in-bounds-binding.rs @@ -11,6 +11,7 @@ // Test that we normalize associated types that appear in a bound that // contains a binding. Issue #21664. +#![feature(core)] #![allow(dead_code)] use std::marker::MarkerTrait; diff --git a/src/test/run-pass/associated-types-project-from-type-param-via-bound-in-where-clause.rs b/src/test/run-pass/associated-types-project-from-type-param-via-bound-in-where-clause.rs index 2243e00ffa1..7fa2030cfe1 100644 --- a/src/test/run-pass/associated-types-project-from-type-param-via-bound-in-where-clause.rs +++ b/src/test/run-pass/associated-types-project-from-type-param-via-bound-in-where-clause.rs @@ -12,6 +12,8 @@ // `Item` originates in a where-clause, not the declaration of // `T`. Issue #20300. +#![feature(core)] + use std::marker::{MarkerTrait, PhantomData}; use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT}; use std::sync::atomic::Ordering::SeqCst; diff --git a/src/test/run-pass/attr-before-view-item.rs b/src/test/run-pass/attr-before-view-item.rs index 951a716879f..f472a672be2 100644 --- a/src/test/run-pass/attr-before-view-item.rs +++ b/src/test/run-pass/attr-before-view-item.rs @@ -10,7 +10,7 @@ // error-pattern:expected item -#![feature(custom_attribute)] +#![feature(custom_attribute, test)] #[foo = "bar"] extern crate test; diff --git a/src/test/run-pass/attr-before-view-item2.rs b/src/test/run-pass/attr-before-view-item2.rs index ad8ce608bd0..5d91d0a41cf 100644 --- a/src/test/run-pass/attr-before-view-item2.rs +++ b/src/test/run-pass/attr-before-view-item2.rs @@ -10,7 +10,7 @@ // error-pattern:expected item -#![feature(custom_attribute)] +#![feature(custom_attribute, test)] mod m { #[foo = "bar"] diff --git a/src/test/run-pass/backtrace.rs b/src/test/run-pass/backtrace.rs index 879b3e920ab..226a7c12df9 100644 --- a/src/test/run-pass/backtrace.rs +++ b/src/test/run-pass/backtrace.rs @@ -12,7 +12,7 @@ // ignore-windows FIXME #13259 #![feature(unboxed_closures)] -#![feature(unsafe_destructor)] +#![feature(unsafe_destructor, old_io, collections)] use std::env; use std::old_io::process::Command; diff --git a/src/test/run-pass/bitv-perf-test.rs b/src/test/run-pass/bitv-perf-test.rs index e6982949501..6c88f350172 100644 --- a/src/test/run-pass/bitv-perf-test.rs +++ b/src/test/run-pass/bitv-perf-test.rs @@ -9,7 +9,7 @@ // except according to those terms. #![allow(unknown_features)] -#![feature(box_syntax)] +#![feature(box_syntax, collections)] extern crate collections; use std::collections::BitVec; diff --git a/src/test/run-pass/c-stack-as-value.rs b/src/test/run-pass/c-stack-as-value.rs index 6a1dde24d68..b81764e1de5 100644 --- a/src/test/run-pass/c-stack-as-value.rs +++ b/src/test/run-pass/c-stack-as-value.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(libc)] + mod rustrt { extern crate libc; diff --git a/src/test/run-pass/c-stack-returning-int64.rs b/src/test/run-pass/c-stack-returning-int64.rs index 1de7520d2b1..eceaa54b740 100644 --- a/src/test/run-pass/c-stack-returning-int64.rs +++ b/src/test/run-pass/c-stack-returning-int64.rs @@ -9,6 +9,8 @@ // except according to those terms. +#![feature(libc, std_misc)] + extern crate libc; use std::ffi::CString; diff --git a/src/test/run-pass/capturing-logging.rs b/src/test/run-pass/capturing-logging.rs index be5bb628b72..2a5ccb88aff 100644 --- a/src/test/run-pass/capturing-logging.rs +++ b/src/test/run-pass/capturing-logging.rs @@ -11,7 +11,7 @@ // exec-env:RUST_LOG=info #![allow(unknown_features)] -#![feature(box_syntax)] +#![feature(box_syntax, old_io, rustc_private, std_misc)] #[macro_use] extern crate log; diff --git a/src/test/run-pass/check-static-recursion-foreign.rs b/src/test/run-pass/check-static-recursion-foreign.rs index 4e05c263a48..ebaa1b55959 100644 --- a/src/test/run-pass/check-static-recursion-foreign.rs +++ b/src/test/run-pass/check-static-recursion-foreign.rs @@ -12,7 +12,7 @@ // aux-build:check_static_recursion_foreign_helper.rs -#![feature(custom_attribute)] +#![feature(custom_attribute, libc)] extern crate check_static_recursion_foreign_helper; extern crate libc; diff --git a/src/test/run-pass/child-outlives-parent.rs b/src/test/run-pass/child-outlives-parent.rs index 39af96a58e6..7a8b4770f95 100644 --- a/src/test/run-pass/child-outlives-parent.rs +++ b/src/test/run-pass/child-outlives-parent.rs @@ -10,6 +10,8 @@ // Reported as issue #126, child leaks the string. +#![feature(std_misc)] + use std::thread::Thread; fn child2(_s: String) { } diff --git a/src/test/run-pass/cleanup-arm-conditional.rs b/src/test/run-pass/cleanup-arm-conditional.rs index cb152f1c64e..66204ec9494 100644 --- a/src/test/run-pass/cleanup-arm-conditional.rs +++ b/src/test/run-pass/cleanup-arm-conditional.rs @@ -22,7 +22,7 @@ // arm is confined to the match arm itself. #![allow(unknown_features)] -#![feature(box_syntax)] +#![feature(box_syntax, os)] use std::os; diff --git a/src/test/run-pass/clone-with-exterior.rs b/src/test/run-pass/clone-with-exterior.rs index 5cc567cb14c..2c65dc7e2ac 100644 --- a/src/test/run-pass/clone-with-exterior.rs +++ b/src/test/run-pass/clone-with-exterior.rs @@ -9,7 +9,7 @@ // except according to those terms. #![allow(unknown_features)] -#![feature(box_syntax)] +#![feature(box_syntax, std_misc)] use std::thread::Thread; diff --git a/src/test/run-pass/closure-reform.rs b/src/test/run-pass/closure-reform.rs index af64553b913..fefab45714f 100644 --- a/src/test/run-pass/closure-reform.rs +++ b/src/test/run-pass/closure-reform.rs @@ -11,7 +11,7 @@ /* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ -#![feature(unboxed_closures)] +#![feature(unboxed_closures, old_io)] use std::mem; use std::old_io::stdio::println; diff --git a/src/test/run-pass/comm.rs b/src/test/run-pass/comm.rs index 16a21adc3fc..cf318c50cff 100644 --- a/src/test/run-pass/comm.rs +++ b/src/test/run-pass/comm.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + use std::thread::Thread; use std::sync::mpsc::{channel, Sender}; diff --git a/src/test/run-pass/conditional-debug-macro-off.rs b/src/test/run-pass/conditional-debug-macro-off.rs index 90142350772..1d1475d60d9 100644 --- a/src/test/run-pass/conditional-debug-macro-off.rs +++ b/src/test/run-pass/conditional-debug-macro-off.rs @@ -11,6 +11,8 @@ // compile-flags: -C debug-assertions=no // exec-env:RUST_LOG=conditional-debug-macro-off=4 +#![feature(rustc_private)] + #[macro_use] extern crate log; diff --git a/src/test/run-pass/const-cast.rs b/src/test/run-pass/const-cast.rs index b7e9c0338dd..1da88a6b2c4 100644 --- a/src/test/run-pass/const-cast.rs +++ b/src/test/run-pass/const-cast.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(libc)] + extern crate libc; struct TestStruct { diff --git a/src/test/run-pass/core-run-destroy.rs b/src/test/run-pass/core-run-destroy.rs index 88d5b74708e..a4413fa85d2 100644 --- a/src/test/run-pass/core-run-destroy.rs +++ b/src/test/run-pass/core-run-destroy.rs @@ -16,6 +16,7 @@ // instead of in std. #![reexport_test_harness_main = "test_main"] +#![feature(old_io, libc, std_misc)] extern crate libc; diff --git a/src/test/run-pass/derive-no-std.rs b/src/test/run-pass/derive-no-std.rs index d3034c2d485..4f48549d499 100644 --- a/src/test/run-pass/derive-no-std.rs +++ b/src/test/run-pass/derive-no-std.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(no_std)] +#![feature(no_std, core, rand, collections, rustc_private)] #![no_std] extern crate core; diff --git a/src/test/run-pass/deriving-encodable-decodable-box.rs b/src/test/run-pass/deriving-encodable-decodable-box.rs index 454156b4c9e..aa03e23b95f 100644 --- a/src/test/run-pass/deriving-encodable-decodable-box.rs +++ b/src/test/run-pass/deriving-encodable-decodable-box.rs @@ -10,7 +10,7 @@ #![allow(unknown_features)] #![feature(box_syntax)] -#![feature(old_orphan_check)] +#![feature(old_orphan_check, rustc_private)] extern crate serialize; diff --git a/src/test/run-pass/deriving-encodable-decodable-cell-refcell.rs b/src/test/run-pass/deriving-encodable-decodable-cell-refcell.rs index 7d581927c30..d4463207aa2 100644 --- a/src/test/run-pass/deriving-encodable-decodable-cell-refcell.rs +++ b/src/test/run-pass/deriving-encodable-decodable-cell-refcell.rs @@ -11,7 +11,7 @@ // This briefly tests the capability of `Cell` and `RefCell` to implement the // `Encodable` and `Decodable` traits via `#[derive(Encodable, Decodable)]` -#![feature(old_orphan_check)] +#![feature(old_orphan_check, rustc_private)] extern crate serialize; diff --git a/src/test/run-pass/deriving-global.rs b/src/test/run-pass/deriving-global.rs index 6777cbdab96..842de6e4984 100644 --- a/src/test/run-pass/deriving-global.rs +++ b/src/test/run-pass/deriving-global.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(old_orphan_check)] +#![feature(old_orphan_check, rand, rustc_private)] extern crate serialize; extern crate rand; diff --git a/src/test/run-pass/deriving-hash.rs b/src/test/run-pass/deriving-hash.rs index 5fe7c8bb94b..03361fbfd95 100644 --- a/src/test/run-pass/deriving-hash.rs +++ b/src/test/run-pass/deriving-hash.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(hash)] + use std::hash::{Hash, SipHasher}; #[derive(Hash)] diff --git a/src/test/run-pass/deriving-primitive.rs b/src/test/run-pass/deriving-primitive.rs index 6b365c348f7..4399d741cad 100644 --- a/src/test/run-pass/deriving-primitive.rs +++ b/src/test/run-pass/deriving-primitive.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + use std::num::FromPrimitive; use std::isize; diff --git a/src/test/run-pass/deriving-rand.rs b/src/test/run-pass/deriving-rand.rs index d6e5fedf182..71cae400602 100644 --- a/src/test/run-pass/deriving-rand.rs +++ b/src/test/run-pass/deriving-rand.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(rand)] + use std::rand; #[derive(Rand)] diff --git a/src/test/run-pass/drop-with-type-ascription-1.rs b/src/test/run-pass/drop-with-type-ascription-1.rs index 4f1fc91a53c..645548761e4 100644 --- a/src/test/run-pass/drop-with-type-ascription-1.rs +++ b/src/test/run-pass/drop-with-type-ascription-1.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(str_words)] + fn main() { let foo = "hello".to_string(); let foo: Vec<&str> = foo.words().collect(); diff --git a/src/test/run-pass/drop-with-type-ascription-2.rs b/src/test/run-pass/drop-with-type-ascription-2.rs index ec8de2a709e..c2edfc26105 100644 --- a/src/test/run-pass/drop-with-type-ascription-2.rs +++ b/src/test/run-pass/drop-with-type-ascription-2.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(collections)] + fn main() { let args = vec!("foobie", "asdf::asdf"); let arr: Vec<&str> = args[1].split_str("::").collect(); diff --git a/src/test/run-pass/dropck_tarena_sound_drop.rs b/src/test/run-pass/dropck_tarena_sound_drop.rs index ad71f725864..17aa1f04e5f 100644 --- a/src/test/run-pass/dropck_tarena_sound_drop.rs +++ b/src/test/run-pass/dropck_tarena_sound_drop.rs @@ -17,7 +17,7 @@ // is force-fed a lifetime equal to that of the borrowed arena. #![allow(unstable)] -#![feature(unsafe_destructor)] +#![feature(unsafe_destructor, rustc_private)] extern crate arena; diff --git a/src/test/run-pass/dst-index.rs b/src/test/run-pass/dst-index.rs index 0c7ecfcefff..64083a063b2 100644 --- a/src/test/run-pass/dst-index.rs +++ b/src/test/run-pass/dst-index.rs @@ -11,6 +11,8 @@ // Test that overloaded index expressions with DST result types // work and don't ICE. +#![feature(core)] + use std::ops::Index; use std::fmt::Debug; diff --git a/src/test/run-pass/enum-null-pointer-opt.rs b/src/test/run-pass/enum-null-pointer-opt.rs index 023376ce473..635c34ef85a 100644 --- a/src/test/run-pass/enum-null-pointer-opt.rs +++ b/src/test/run-pass/enum-null-pointer-opt.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] extern crate core; diff --git a/src/test/run-pass/env-home-dir.rs b/src/test/run-pass/env-home-dir.rs index 5d68a25a14a..c41486f660c 100644 --- a/src/test/run-pass/env-home-dir.rs +++ b/src/test/run-pass/env-home-dir.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(path)] + use std::env::*; use std::path::PathBuf; diff --git a/src/test/run-pass/exponential-notation.rs b/src/test/run-pass/exponential-notation.rs index bfe22712de8..3f451ee8d51 100644 --- a/src/test/run-pass/exponential-notation.rs +++ b/src/test/run-pass/exponential-notation.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + use std::num::strconv::ExponentFormat::{ExpBin, ExpDec}; use std::num::strconv::SignificantDigits::DigMax; use std::num::strconv::SignFormat::{SignAll, SignNeg}; diff --git a/src/test/run-pass/extern-call-deep.rs b/src/test/run-pass/extern-call-deep.rs index 93a5752d004..2138b12fb12 100644 --- a/src/test/run-pass/extern-call-deep.rs +++ b/src/test/run-pass/extern-call-deep.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(libc)] + extern crate libc; mod rustrt { diff --git a/src/test/run-pass/extern-call-deep2.rs b/src/test/run-pass/extern-call-deep2.rs index 3c4c1da52ea..7bbed563a99 100644 --- a/src/test/run-pass/extern-call-deep2.rs +++ b/src/test/run-pass/extern-call-deep2.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc, libc)] + extern crate libc; use std::thread::Thread; diff --git a/src/test/run-pass/extern-call-indirect.rs b/src/test/run-pass/extern-call-indirect.rs index 52697d96b32..4f1abbeb5c7 100644 --- a/src/test/run-pass/extern-call-indirect.rs +++ b/src/test/run-pass/extern-call-indirect.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(libc)] + extern crate libc; mod rustrt { diff --git a/src/test/run-pass/extern-call-scrub.rs b/src/test/run-pass/extern-call-scrub.rs index 0dca7514dc5..069ecd92a56 100644 --- a/src/test/run-pass/extern-call-scrub.rs +++ b/src/test/run-pass/extern-call-scrub.rs @@ -12,6 +12,8 @@ // make sure the stack pointers are maintained properly in both // directions +#![feature(libc, std_misc)] + extern crate libc; use std::thread::Thread; diff --git a/src/test/run-pass/extern-crosscrate.rs b/src/test/run-pass/extern-crosscrate.rs index 18e20332adc..7157d0658be 100644 --- a/src/test/run-pass/extern-crosscrate.rs +++ b/src/test/run-pass/extern-crosscrate.rs @@ -10,6 +10,8 @@ //aux-build:extern-crosscrate-source.rs +#![feature(libc)] + extern crate externcallback; extern crate libc; diff --git a/src/test/run-pass/extern-methods.rs b/src/test/run-pass/extern-methods.rs index 8fe69e40024..aab409e77cf 100644 --- a/src/test/run-pass/extern-methods.rs +++ b/src/test/run-pass/extern-methods.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + use std::marker::MarkerTrait; trait A : MarkerTrait { diff --git a/src/test/run-pass/extern-mod-syntax.rs b/src/test/run-pass/extern-mod-syntax.rs index 4d4f5036fc1..37404ee7e69 100644 --- a/src/test/run-pass/extern-mod-syntax.rs +++ b/src/test/run-pass/extern-mod-syntax.rs @@ -9,6 +9,7 @@ // except according to those terms. #![allow(unused_imports)] +#![feature(rustc_private)] extern crate serialize; use serialize::json::Object; diff --git a/src/test/run-pass/float-nan.rs b/src/test/run-pass/float-nan.rs index 4d9f7d507f0..b52f025fcbb 100644 --- a/src/test/run-pass/float-nan.rs +++ b/src/test/run-pass/float-nan.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + use std::num::Float; pub fn main() { diff --git a/src/test/run-pass/for-loop-no-std.rs b/src/test/run-pass/for-loop-no-std.rs index 30c2aec33ad..31ed4919778 100644 --- a/src/test/run-pass/for-loop-no-std.rs +++ b/src/test/run-pass/for-loop-no-std.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(lang_items, start, no_std)] +#![feature(lang_items, start, no_std, core, collections)] #![no_std] extern crate "std" as other; diff --git a/src/test/run-pass/foreach-external-iterators-hashmap-break-restart.rs b/src/test/run-pass/foreach-external-iterators-hashmap-break-restart.rs index a4988bf016c..1a60f22d145 100644 --- a/src/test/run-pass/foreach-external-iterators-hashmap-break-restart.rs +++ b/src/test/run-pass/foreach-external-iterators-hashmap-break-restart.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(collections)] + extern crate collections; use std::collections::HashMap; diff --git a/src/test/run-pass/foreach-external-iterators-hashmap.rs b/src/test/run-pass/foreach-external-iterators-hashmap.rs index ed4328d94fe..79d2d400080 100644 --- a/src/test/run-pass/foreach-external-iterators-hashmap.rs +++ b/src/test/run-pass/foreach-external-iterators-hashmap.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(collections)] + extern crate collections; use std::collections::HashMap; diff --git a/src/test/run-pass/foreign-call-no-runtime.rs b/src/test/run-pass/foreign-call-no-runtime.rs index 9e05f38af7a..3c5abba902d 100644 --- a/src/test/run-pass/foreign-call-no-runtime.rs +++ b/src/test/run-pass/foreign-call-no-runtime.rs @@ -9,6 +9,7 @@ // except according to those terms. // ignore-aarch64 +#![feature(libc)] extern crate libc; diff --git a/src/test/run-pass/foreign-dupe.rs b/src/test/run-pass/foreign-dupe.rs index 39c7d6dda0d..fe42b2a0558 100644 --- a/src/test/run-pass/foreign-dupe.rs +++ b/src/test/run-pass/foreign-dupe.rs @@ -10,6 +10,8 @@ // calling pin_task and that's having weird side-effects. +#![feature(libc)] + mod rustrt1 { extern crate libc; diff --git a/src/test/run-pass/foreign-fn-linkname.rs b/src/test/run-pass/foreign-fn-linkname.rs index 172ece0c4bf..a274a191449 100644 --- a/src/test/run-pass/foreign-fn-linkname.rs +++ b/src/test/run-pass/foreign-fn-linkname.rs @@ -9,6 +9,8 @@ // except according to those terms. +#![feature(std_misc, libc)] + extern crate libc; use std::ffi::CString; diff --git a/src/test/run-pass/foreign-mod-unused-const.rs b/src/test/run-pass/foreign-mod-unused-const.rs index 03023f03233..abf9f504b7d 100644 --- a/src/test/run-pass/foreign-mod-unused-const.rs +++ b/src/test/run-pass/foreign-mod-unused-const.rs @@ -9,6 +9,8 @@ // except according to those terms. +#![feature(libc)] + extern crate libc; mod foo { diff --git a/src/test/run-pass/foreign-no-abi.rs b/src/test/run-pass/foreign-no-abi.rs index 2af02feb21d..9305945b918 100644 --- a/src/test/run-pass/foreign-no-abi.rs +++ b/src/test/run-pass/foreign-no-abi.rs @@ -10,6 +10,8 @@ // ABI is cdecl by default +#![feature(libc)] + mod rustrt { extern crate libc; diff --git a/src/test/run-pass/foreign2.rs b/src/test/run-pass/foreign2.rs index 5ebc4effb37..749a5875b75 100644 --- a/src/test/run-pass/foreign2.rs +++ b/src/test/run-pass/foreign2.rs @@ -9,6 +9,8 @@ // except according to those terms. +#![feature(libc)] + extern crate libc; mod bar { diff --git a/src/test/run-pass/format-no-std.rs b/src/test/run-pass/format-no-std.rs index a15a176c223..4df6ed843af 100644 --- a/src/test/run-pass/format-no-std.rs +++ b/src/test/run-pass/format-no-std.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(lang_items, start, no_std)] +#![feature(lang_items, start, no_std, core, collections)] #![no_std] extern crate "std" as other; diff --git a/src/test/run-pass/fsu-moves-and-copies.rs b/src/test/run-pass/fsu-moves-and-copies.rs index 0f8d7c24360..cdf147aae10 100644 --- a/src/test/run-pass/fsu-moves-and-copies.rs +++ b/src/test/run-pass/fsu-moves-and-copies.rs @@ -12,7 +12,7 @@ // correctly and moves rather than copy when appropriate. #![allow(unknown_features)] -#![feature(box_syntax)] +#![feature(box_syntax, core)] use std::marker::NoCopy as NP; diff --git a/src/test/run-pass/generic-extern-mangle.rs b/src/test/run-pass/generic-extern-mangle.rs index 062ee507864..db5175f19cb 100644 --- a/src/test/run-pass/generic-extern-mangle.rs +++ b/src/test/run-pass/generic-extern-mangle.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + use std::num::Int; extern "C" fn foo(a: T, b: T) -> T { a.wrapping_add(b) } diff --git a/src/test/run-pass/getopts_ref.rs b/src/test/run-pass/getopts_ref.rs index 3c89900fe49..1ccd8a0640e 100644 --- a/src/test/run-pass/getopts_ref.rs +++ b/src/test/run-pass/getopts_ref.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(rustc_private)] + extern crate getopts; use getopts::{optopt, getopts}; diff --git a/src/test/run-pass/hashmap-memory.rs b/src/test/run-pass/hashmap-memory.rs index 81c4054d009..93ff1820734 100644 --- a/src/test/run-pass/hashmap-memory.rs +++ b/src/test/run-pass/hashmap-memory.rs @@ -9,7 +9,7 @@ // except according to those terms. #![allow(unknown_features)] -#![feature(unboxed_closures)] +#![feature(unboxed_closures, std_misc)] /** A somewhat reduced test case to expose some Valgrind issues. diff --git a/src/test/run-pass/init-large-type.rs b/src/test/run-pass/init-large-type.rs index 8ee6054f8ba..76927858ea1 100644 --- a/src/test/run-pass/init-large-type.rs +++ b/src/test/run-pass/init-large-type.rs @@ -12,7 +12,7 @@ // Doing it incorrectly causes massive slowdown in LLVM during // optimisation. -#![feature(intrinsics)] +#![feature(intrinsics, std_misc)] use std::thread::Thread; diff --git a/src/test/run-pass/into-iterator-type-inference-shift.rs b/src/test/run-pass/into-iterator-type-inference-shift.rs index 01e305581f1..a9aa5955d3d 100644 --- a/src/test/run-pass/into-iterator-type-inference-shift.rs +++ b/src/test/run-pass/into-iterator-type-inference-shift.rs @@ -13,6 +13,8 @@ // propagation yet, and so we just saw a type variable, yielding an // error. +#![feature(core)] + use std::u8; trait IntoIterator { diff --git a/src/test/run-pass/intrinsic-assume.rs b/src/test/run-pass/intrinsic-assume.rs index 837c2d21513..638b2e434a5 100644 --- a/src/test/run-pass/intrinsic-assume.rs +++ b/src/test/run-pass/intrinsic-assume.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + use std::intrinsics::assume; unsafe fn f(x: i32) -> i32 { diff --git a/src/test/run-pass/intrinsic-unreachable.rs b/src/test/run-pass/intrinsic-unreachable.rs index 5e8b758cdf6..ea9648a3e69 100644 --- a/src/test/run-pass/intrinsic-unreachable.rs +++ b/src/test/run-pass/intrinsic-unreachable.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + use std::intrinsics; // See also src/test/run-make/intrinsic-unreachable. diff --git a/src/test/run-pass/intrinsics-math.rs b/src/test/run-pass/intrinsics-math.rs index 028b2bfb0ec..4ca6b025803 100644 --- a/src/test/run-pass/intrinsics-math.rs +++ b/src/test/run-pass/intrinsics-math.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(intrinsics)] +#![feature(intrinsics, core)] macro_rules! assert_approx_eq { ($a:expr, $b:expr) => ({ diff --git a/src/test/run-pass/issue-10626.rs b/src/test/run-pass/issue-10626.rs index 29e4801d0a9..2c0811b69e0 100644 --- a/src/test/run-pass/issue-10626.rs +++ b/src/test/run-pass/issue-10626.rs @@ -12,6 +12,8 @@ // Make sure that if a process doesn't have its stdio/stderr descriptors set up // that we don't die in a large ball of fire +#![feature(old_io)] + use std::env; use std::old_io::process; diff --git a/src/test/run-pass/issue-11709.rs b/src/test/run-pass/issue-11709.rs index 4a07b5fc432..da3efb4fea8 100644 --- a/src/test/run-pass/issue-11709.rs +++ b/src/test/run-pass/issue-11709.rs @@ -15,6 +15,8 @@ // when this bug was opened. The cases where the compiler // panics before the fix have a comment. +#![feature(std_misc)] + use std::thunk::Thunk; struct S {x:()} diff --git a/src/test/run-pass/issue-11736.rs b/src/test/run-pass/issue-11736.rs index c6e0a5be763..87d5bf8ed0a 100644 --- a/src/test/run-pass/issue-11736.rs +++ b/src/test/run-pass/issue-11736.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(collections)] + extern crate collections; use std::collections::BitVec; diff --git a/src/test/run-pass/issue-11881.rs b/src/test/run-pass/issue-11881.rs index bc907787c7c..15c65259107 100644 --- a/src/test/run-pass/issue-11881.rs +++ b/src/test/run-pass/issue-11881.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(old_orphan_check)] +#![feature(old_orphan_check, rustc_private, old_io)] extern crate rbml; extern crate serialize; diff --git a/src/test/run-pass/issue-11958.rs b/src/test/run-pass/issue-11958.rs index bb34dae77b3..f3c6da7cfe4 100644 --- a/src/test/run-pass/issue-11958.rs +++ b/src/test/run-pass/issue-11958.rs @@ -9,6 +9,7 @@ // except according to those terms. #![forbid(warnings)] +#![feature(std_misc)] // Pretty printing tests complain about `use std::predule::*` #![allow(unused_imports)] diff --git a/src/test/run-pass/issue-1251.rs b/src/test/run-pass/issue-1251.rs index debb7df1125..d5f8200007f 100644 --- a/src/test/run-pass/issue-1251.rs +++ b/src/test/run-pass/issue-1251.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(libc)] + #![crate_id="rust_get_test_int"] mod rustrt { diff --git a/src/test/run-pass/issue-12684.rs b/src/test/run-pass/issue-12684.rs index e66b5d21e17..51268969d42 100644 --- a/src/test/run-pass/issue-12684.rs +++ b/src/test/run-pass/issue-12684.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(old_io, std_misc)] + use std::time::Duration; use std::thread; diff --git a/src/test/run-pass/issue-12699.rs b/src/test/run-pass/issue-12699.rs index b55d6477753..4ff17f297d7 100644 --- a/src/test/run-pass/issue-12699.rs +++ b/src/test/run-pass/issue-12699.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(old_io, std_misc)] + use std::old_io::timer; use std::time::Duration; diff --git a/src/test/run-pass/issue-12860.rs b/src/test/run-pass/issue-12860.rs index a05cc9c0f74..7f26d4d3713 100644 --- a/src/test/run-pass/issue-12860.rs +++ b/src/test/run-pass/issue-12860.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(collections)] extern crate collections; diff --git a/src/test/run-pass/issue-13105.rs b/src/test/run-pass/issue-13105.rs index 64807dc44e0..3886971a469 100644 --- a/src/test/run-pass/issue-13105.rs +++ b/src/test/run-pass/issue-13105.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + use std::marker::MarkerTrait; trait Foo : MarkerTrait { diff --git a/src/test/run-pass/issue-13259-windows-tcb-trash.rs b/src/test/run-pass/issue-13259-windows-tcb-trash.rs index 329ab7c921d..5c5282da06b 100644 --- a/src/test/run-pass/issue-13259-windows-tcb-trash.rs +++ b/src/test/run-pass/issue-13259-windows-tcb-trash.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(libc)] + extern crate libc; #[cfg(windows)] diff --git a/src/test/run-pass/issue-13304.rs b/src/test/run-pass/issue-13304.rs index bd2ddc6b9b2..876b329998e 100644 --- a/src/test/run-pass/issue-13304.rs +++ b/src/test/run-pass/issue-13304.rs @@ -9,6 +9,7 @@ // except according to those terms. // ignore-aarch64 +#![feature(io, process_capture)] use std::env; use std::io::prelude::*; diff --git a/src/test/run-pass/issue-13352.rs b/src/test/run-pass/issue-13352.rs index a8343712034..aed0022d9fa 100644 --- a/src/test/run-pass/issue-13352.rs +++ b/src/test/run-pass/issue-13352.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc, libc)] + extern crate libc; use std::thunk::Thunk; diff --git a/src/test/run-pass/issue-13494.rs b/src/test/run-pass/issue-13494.rs index 95562d75c3e..7692a31315b 100644 --- a/src/test/run-pass/issue-13494.rs +++ b/src/test/run-pass/issue-13494.rs @@ -11,6 +11,8 @@ // This test may not always fail, but it can be flaky if the race it used to // expose is still present. +#![feature(std_misc)] + use std::sync::mpsc::{channel, Sender, Receiver}; use std::thread::Thread; diff --git a/src/test/run-pass/issue-13507-2.rs b/src/test/run-pass/issue-13507-2.rs index 1c0283070a2..61ef9835752 100644 --- a/src/test/run-pass/issue-13507-2.rs +++ b/src/test/run-pass/issue-13507-2.rs @@ -9,6 +9,9 @@ // except according to those terms. // aux-build:issue13507.rs + +#![feature(core)] + extern crate issue13507; use issue13507::testtypes; diff --git a/src/test/run-pass/issue-13655.rs b/src/test/run-pass/issue-13655.rs index 81a8b29461c..cd5da3844e1 100644 --- a/src/test/run-pass/issue-13655.rs +++ b/src/test/run-pass/issue-13655.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(unboxed_closures)] +#![feature(unboxed_closures, core)] use std::ops::Fn; struct Foo(T); diff --git a/src/test/run-pass/issue-13763.rs b/src/test/run-pass/issue-13763.rs index 81b6892b0f9..3f4ade08d92 100644 --- a/src/test/run-pass/issue-13763.rs +++ b/src/test/run-pass/issue-13763.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + use std::u8; const NUM: uint = u8::BITS as uint; diff --git a/src/test/run-pass/issue-14021.rs b/src/test/run-pass/issue-14021.rs index e850ecbba6e..e773f03f212 100644 --- a/src/test/run-pass/issue-14021.rs +++ b/src/test/run-pass/issue-14021.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(old_orphan_check)] +#![feature(old_orphan_check, rustc_private)] extern crate serialize; diff --git a/src/test/run-pass/issue-14456.rs b/src/test/run-pass/issue-14456.rs index 7e4c464d9aa..ba769c2594a 100644 --- a/src/test/run-pass/issue-14456.rs +++ b/src/test/run-pass/issue-14456.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(io, process_capture)] + use std::env; use std::io::prelude::*; use std::io; diff --git a/src/test/run-pass/issue-14901.rs b/src/test/run-pass/issue-14901.rs index abb15dae00d..f8dd0cf1a82 100644 --- a/src/test/run-pass/issue-14901.rs +++ b/src/test/run-pass/issue-14901.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(old_io)] + use std::old_io::Reader; enum Wrapper<'a> { diff --git a/src/test/run-pass/issue-14940.rs b/src/test/run-pass/issue-14940.rs index 098fa54207f..fa4d10df7ea 100644 --- a/src/test/run-pass/issue-14940.rs +++ b/src/test/run-pass/issue-14940.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(old_io, io)] + use std::env; use std::process::Command; use std::io::{self, Write}; diff --git a/src/test/run-pass/issue-14958.rs b/src/test/run-pass/issue-14958.rs index 6335f79be6c..911d850b289 100644 --- a/src/test/run-pass/issue-14958.rs +++ b/src/test/run-pass/issue-14958.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(unboxed_closures)] +#![feature(unboxed_closures, core)] trait Foo { fn dummy(&self) { }} diff --git a/src/test/run-pass/issue-14959.rs b/src/test/run-pass/issue-14959.rs index 53d0f7dae05..6fd22f2efb7 100644 --- a/src/test/run-pass/issue-14959.rs +++ b/src/test/run-pass/issue-14959.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(unboxed_closures)] +#![feature(unboxed_closures, core)] use std::ops::Fn; diff --git a/src/test/run-pass/issue-15673.rs b/src/test/run-pass/issue-15673.rs index 227d8f7b8c8..020513121e6 100644 --- a/src/test/run-pass/issue-15673.rs +++ b/src/test/run-pass/issue-15673.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + use std::iter::AdditiveIterator; fn main() { let x: [u64; 3] = [1, 2, 3]; diff --git a/src/test/run-pass/issue-15734.rs b/src/test/run-pass/issue-15734.rs index 18e4190ee45..99c8d746b94 100644 --- a/src/test/run-pass/issue-15734.rs +++ b/src/test/run-pass/issue-15734.rs @@ -11,7 +11,7 @@ // If `Index` used an associated type for its output, this test would // work more smoothly. -#![feature(old_orphan_check)] +#![feature(old_orphan_check, core)] use std::ops::Index; diff --git a/src/test/run-pass/issue-15924.rs b/src/test/run-pass/issue-15924.rs index 88b250af1c0..d8ddec286e9 100644 --- a/src/test/run-pass/issue-15924.rs +++ b/src/test/run-pass/issue-15924.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(unsafe_destructor)] +#![feature(unsafe_destructor, rustc_private)] extern crate serialize; diff --git a/src/test/run-pass/issue-16530.rs b/src/test/run-pass/issue-16530.rs index 7e3b796235d..b34c760192d 100644 --- a/src/test/run-pass/issue-16530.rs +++ b/src/test/run-pass/issue-16530.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(hash)] + use std::hash::{SipHasher, hash}; #[derive(Hash)] diff --git a/src/test/run-pass/issue-16739.rs b/src/test/run-pass/issue-16739.rs index 389baecafd1..16c1b14fd87 100644 --- a/src/test/run-pass/issue-16739.rs +++ b/src/test/run-pass/issue-16739.rs @@ -10,7 +10,7 @@ #![allow(unknown_features)] #![feature(box_syntax)] -#![feature(unboxed_closures)] +#![feature(unboxed_closures, core)] // Test that unboxing shim for calling rust-call ABI methods through a // trait box works and does not cause an ICE. diff --git a/src/test/run-pass/issue-1696.rs b/src/test/run-pass/issue-1696.rs index 40e112d6fbf..4c6c200c716 100644 --- a/src/test/run-pass/issue-1696.rs +++ b/src/test/run-pass/issue-1696.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(collections)] + extern crate collections; use std::collections::HashMap; diff --git a/src/test/run-pass/issue-17322.rs b/src/test/run-pass/issue-17322.rs index d4c32f42188..410d6795c21 100644 --- a/src/test/run-pass/issue-17322.rs +++ b/src/test/run-pass/issue-17322.rs @@ -9,7 +9,7 @@ // except according to those terms. #![allow(unknown_features)] -#![feature(box_syntax)] +#![feature(box_syntax, io)] use std::io::{self, Write}; diff --git a/src/test/run-pass/issue-17351.rs b/src/test/run-pass/issue-17351.rs index 0966d4ea45e..945e1f220c5 100644 --- a/src/test/run-pass/issue-17351.rs +++ b/src/test/run-pass/issue-17351.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + fn main() { let _: &Str = &"x"; } diff --git a/src/test/run-pass/issue-17718-static-unsafe-interior.rs b/src/test/run-pass/issue-17718-static-unsafe-interior.rs index cdd03244df1..388408cbd4d 100644 --- a/src/test/run-pass/issue-17718-static-unsafe-interior.rs +++ b/src/test/run-pass/issue-17718-static-unsafe-interior.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + use std::marker; use std::cell::UnsafeCell; diff --git a/src/test/run-pass/issue-17718.rs b/src/test/run-pass/issue-17718.rs index e4782e28928..8eee4c9f216 100644 --- a/src/test/run-pass/issue-17718.rs +++ b/src/test/run-pass/issue-17718.rs @@ -10,6 +10,8 @@ // aux-build:issue-17718.rs +#![feature(core)] + extern crate "issue-17718" as other; use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; diff --git a/src/test/run-pass/issue-17897.rs b/src/test/run-pass/issue-17897.rs index 3774aaa1903..adc33e3eed0 100644 --- a/src/test/run-pass/issue-17897.rs +++ b/src/test/run-pass/issue-17897.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(unboxed_closures)] +#![feature(unboxed_closures, std_misc)] use std::thunk::Thunk; diff --git a/src/test/run-pass/issue-18188.rs b/src/test/run-pass/issue-18188.rs index a4b09eb08e0..270537591b7 100644 --- a/src/test/run-pass/issue-18188.rs +++ b/src/test/run-pass/issue-18188.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(unboxed_closures)] +#![feature(unboxed_closures, std_misc)] use std::thunk::Thunk; diff --git a/src/test/run-pass/issue-18619.rs b/src/test/run-pass/issue-18619.rs index 6b6296b0bd9..6caa96530f6 100644 --- a/src/test/run-pass/issue-18619.rs +++ b/src/test/run-pass/issue-18619.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(old_io)] + use std::old_io::FileType; pub fn main() { diff --git a/src/test/run-pass/issue-18661.rs b/src/test/run-pass/issue-18661.rs index bb2907241c2..bdc16533ea6 100644 --- a/src/test/run-pass/issue-18661.rs +++ b/src/test/run-pass/issue-18661.rs @@ -11,7 +11,7 @@ // Test that param substitutions from the correct environment are // used when translating unboxed closure calls. -#![feature(unboxed_closures)] +#![feature(unboxed_closures, core)] pub fn inside(c: F) { c.call(()); diff --git a/src/test/run-pass/issue-19098.rs b/src/test/run-pass/issue-19098.rs index ef95b4d4f00..05f3373dbd4 100644 --- a/src/test/run-pass/issue-19098.rs +++ b/src/test/run-pass/issue-19098.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(unboxed_closures)] +#![feature(unboxed_closures, core)] pub trait Handler { fn handle(&self, &mut String); diff --git a/src/test/run-pass/issue-19811-escape-unicode.rs b/src/test/run-pass/issue-19811-escape-unicode.rs index 23400859e54..9317f5ea6b1 100644 --- a/src/test/run-pass/issue-19811-escape-unicode.rs +++ b/src/test/run-pass/issue-19811-escape-unicode.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(collections)] + fn main() { let mut escaped = String::from_str(""); for c in '\u{10401}'.escape_unicode() { diff --git a/src/test/run-pass/issue-20091.rs b/src/test/run-pass/issue-20091.rs index fe9ae022d88..1fe44348466 100644 --- a/src/test/run-pass/issue-20091.rs +++ b/src/test/run-pass/issue-20091.rs @@ -9,6 +9,7 @@ // except according to those terms. // ignore-aarch64 +#![feature(std_misc, os)] #[cfg(unix)] fn main() { diff --git a/src/test/run-pass/issue-20454.rs b/src/test/run-pass/issue-20454.rs index fbc4cca8008..0e3d4e0e40d 100644 --- a/src/test/run-pass/issue-20454.rs +++ b/src/test/run-pass/issue-20454.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + use std::thread; fn main() { diff --git a/src/test/run-pass/issue-20644.rs b/src/test/run-pass/issue-20644.rs index 83b91c93a86..476267d9329 100644 --- a/src/test/run-pass/issue-20644.rs +++ b/src/test/run-pass/issue-20644.rs @@ -11,6 +11,8 @@ // A reduced version of the rustbook ice. The problem this encountered // had to do with trans ignoring binders. +#![feature(os)] + use std::iter; use std::os; use std::fs::File; diff --git a/src/test/run-pass/issue-20797.rs b/src/test/run-pass/issue-20797.rs index c5badb61494..2600c5f0afd 100644 --- a/src/test/run-pass/issue-20797.rs +++ b/src/test/run-pass/issue-20797.rs @@ -10,6 +10,8 @@ // Regression test for #20797. +#![feature(old_io, old_path)] + use std::default::Default; use std::io; use std::fs; diff --git a/src/test/run-pass/issue-21058.rs b/src/test/run-pass/issue-21058.rs index e53fe3c44a2..3da650469e8 100644 --- a/src/test/run-pass/issue-21058.rs +++ b/src/test/run-pass/issue-21058.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] struct NT(str); struct DST { a: u32, b: str } diff --git a/src/test/run-pass/issue-2190-1.rs b/src/test/run-pass/issue-2190-1.rs index 3025741694f..00f501d85a5 100644 --- a/src/test/run-pass/issue-2190-1.rs +++ b/src/test/run-pass/issue-2190-1.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + use std::thread::Builder; use std::thunk::Thunk; diff --git a/src/test/run-pass/issue-2214.rs b/src/test/run-pass/issue-2214.rs index 1dcbfd92fa0..202ea05b7f8 100644 --- a/src/test/run-pass/issue-2214.rs +++ b/src/test/run-pass/issue-2214.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(libc)] + extern crate libc; use std::mem; diff --git a/src/test/run-pass/issue-22577.rs b/src/test/run-pass/issue-22577.rs index f668cae66c6..f0b0b18e6bb 100644 --- a/src/test/run-pass/issue-22577.rs +++ b/src/test/run-pass/issue-22577.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(fs, net, fs_walk)] + use std::{fs, net}; fn assert_both() {} diff --git a/src/test/run-pass/issue-2383.rs b/src/test/run-pass/issue-2383.rs index 9599a908950..f017193bc76 100644 --- a/src/test/run-pass/issue-2383.rs +++ b/src/test/run-pass/issue-2383.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(collections)] + extern crate collections; use std::collections::VecDeque; diff --git a/src/test/run-pass/issue-2718.rs b/src/test/run-pass/issue-2718.rs index 3a1178c2824..8d0e0654933 100644 --- a/src/test/run-pass/issue-2718.rs +++ b/src/test/run-pass/issue-2718.rs @@ -10,7 +10,7 @@ // // ignore-lexer-test FIXME #15883 -#![feature(unsafe_destructor)] +#![feature(unsafe_destructor, std_misc)] pub type Task = int; diff --git a/src/test/run-pass/issue-2804-2.rs b/src/test/run-pass/issue-2804-2.rs index 4f89d28332a..c49dda9f1e5 100644 --- a/src/test/run-pass/issue-2804-2.rs +++ b/src/test/run-pass/issue-2804-2.rs @@ -11,6 +11,8 @@ // Minimized version of issue-2804.rs. Both check that callee IDs don't // clobber the previous node ID in a macro expr +#![feature(collections)] + extern crate collections; use std::collections::HashMap; diff --git a/src/test/run-pass/issue-2804.rs b/src/test/run-pass/issue-2804.rs index b9b5aec62fc..4fa491ab446 100644 --- a/src/test/run-pass/issue-2804.rs +++ b/src/test/run-pass/issue-2804.rs @@ -8,6 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(collections)] +#![feature(rustc_private)] + extern crate collections; extern crate serialize; diff --git a/src/test/run-pass/issue-2904.rs b/src/test/run-pass/issue-2904.rs index 3f954c3c918..b05baa24b7a 100644 --- a/src/test/run-pass/issue-2904.rs +++ b/src/test/run-pass/issue-2904.rs @@ -9,7 +9,9 @@ // except according to those terms. -/// Map representation +// Map representation + +#![feature(old_io)] use std::old_io; use std::fmt; diff --git a/src/test/run-pass/issue-3012-2.rs b/src/test/run-pass/issue-3012-2.rs index 6f107a37e9b..a679ff5f718 100644 --- a/src/test/run-pass/issue-3012-2.rs +++ b/src/test/run-pass/issue-3012-2.rs @@ -11,7 +11,7 @@ // aux-build:issue-3012-1.rs #![allow(unknown_features)] -#![feature(box_syntax)] +#![feature(box_syntax, libc)] extern crate socketlib; extern crate libc; diff --git a/src/test/run-pass/issue-3026.rs b/src/test/run-pass/issue-3026.rs index 8da15496844..1ce6d6d38d8 100644 --- a/src/test/run-pass/issue-3026.rs +++ b/src/test/run-pass/issue-3026.rs @@ -9,7 +9,7 @@ // except according to those terms. #![allow(unknown_features)] -#![feature(box_syntax)] +#![feature(box_syntax, collections)] extern crate collections; diff --git a/src/test/run-pass/issue-3424.rs b/src/test/run-pass/issue-3424.rs index e039be058de..ecce97a3013 100644 --- a/src/test/run-pass/issue-3424.rs +++ b/src/test/run-pass/issue-3424.rs @@ -11,7 +11,7 @@ // rustc --test ignores2.rs && ./ignores2 #![allow(unknown_features)] -#![feature(unboxed_closures)] +#![feature(unboxed_closures, old_path, std_misc)] use std::old_path::{Path}; use std::old_path; diff --git a/src/test/run-pass/issue-3559.rs b/src/test/run-pass/issue-3559.rs index 3f1a1c75d8a..c2ea24ac6ba 100644 --- a/src/test/run-pass/issue-3559.rs +++ b/src/test/run-pass/issue-3559.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(collections)] + extern crate collections; use std::collections::HashMap; diff --git a/src/test/run-pass/issue-3563-3.rs b/src/test/run-pass/issue-3563-3.rs index be4d4752295..5dfe02cc9ec 100644 --- a/src/test/run-pass/issue-3563-3.rs +++ b/src/test/run-pass/issue-3563-3.rs @@ -22,6 +22,8 @@ // that are already linked in. Using WriterUtil allows us to use the write_line // method. +#![feature(core)] + use std::fmt; use std::iter::repeat; use std::slice; diff --git a/src/test/run-pass/issue-3609.rs b/src/test/run-pass/issue-3609.rs index b51edcf8bec..2bd56e81687 100644 --- a/src/test/run-pass/issue-3609.rs +++ b/src/test/run-pass/issue-3609.rs @@ -9,6 +9,7 @@ // except according to those terms. #![allow(unknown_features)] +#![feature(std_misc)] use std::thread::Thread; use std::sync::mpsc::Sender; diff --git a/src/test/run-pass/issue-3656.rs b/src/test/run-pass/issue-3656.rs index 8a39676ca17..5be64522477 100644 --- a/src/test/run-pass/issue-3656.rs +++ b/src/test/run-pass/issue-3656.rs @@ -12,6 +12,8 @@ // Incorrect struct size computation in the FFI, because of not taking // the alignment of elements into account. +#![feature(libc)] + extern crate libc; use libc::{c_uint, uint32_t, c_void}; diff --git a/src/test/run-pass/issue-3753.rs b/src/test/run-pass/issue-3753.rs index 58d7aa276f1..bbfeb94cd9d 100644 --- a/src/test/run-pass/issue-3753.rs +++ b/src/test/run-pass/issue-3753.rs @@ -12,6 +12,8 @@ // Issue Name: pub method preceded by attribute can't be parsed // Abstract: Visibility parsing failed when compiler parsing +#![feature(core)] + use std::f64; #[derive(Copy)] diff --git a/src/test/run-pass/issue-4016.rs b/src/test/run-pass/issue-4016.rs index 220332f6354..a761345e1d9 100644 --- a/src/test/run-pass/issue-4016.rs +++ b/src/test/run-pass/issue-4016.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(rustc_private)] extern crate serialize; diff --git a/src/test/run-pass/issue-4036.rs b/src/test/run-pass/issue-4036.rs index 48e32922ce7..865f729a4d3 100644 --- a/src/test/run-pass/issue-4036.rs +++ b/src/test/run-pass/issue-4036.rs @@ -12,6 +12,8 @@ // Issue #4036: Test for an issue that arose around fixing up type inference // byproducts in vtable records. +#![feature(rustc_private)] + extern crate serialize; use serialize::{json, Decodable}; diff --git a/src/test/run-pass/issue-4333.rs b/src/test/run-pass/issue-4333.rs index 074bbf270fd..f92bed87ba6 100644 --- a/src/test/run-pass/issue-4333.rs +++ b/src/test/run-pass/issue-4333.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(io)] + use std::io; pub fn main() { diff --git a/src/test/run-pass/issue-4446.rs b/src/test/run-pass/issue-4446.rs index b40a726a2c3..8dd385b59c9 100644 --- a/src/test/run-pass/issue-4446.rs +++ b/src/test/run-pass/issue-4446.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(old_io)] + use std::old_io::println; use std::sync::mpsc::channel; use std::thread; diff --git a/src/test/run-pass/issue-4735.rs b/src/test/run-pass/issue-4735.rs index 196e9748b10..568b8bc89a0 100644 --- a/src/test/run-pass/issue-4735.rs +++ b/src/test/run-pass/issue-4735.rs @@ -10,7 +10,7 @@ #![allow(unknown_features)] -#![feature(box_syntax)] +#![feature(box_syntax, libc)] extern crate libc; diff --git a/src/test/run-pass/issue-5791.rs b/src/test/run-pass/issue-5791.rs index 468f420624a..c6017d7d650 100644 --- a/src/test/run-pass/issue-5791.rs +++ b/src/test/run-pass/issue-5791.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(libc)] + extern crate libc; extern { diff --git a/src/test/run-pass/issue-5988.rs b/src/test/run-pass/issue-5988.rs index 1ad48d326ea..dae4bc35c27 100644 --- a/src/test/run-pass/issue-5988.rs +++ b/src/test/run-pass/issue-5988.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(old_io)] + use std::old_io; trait B { fn f(&self); diff --git a/src/test/run-pass/issue-6128.rs b/src/test/run-pass/issue-6128.rs index 1746a6281dc..e1e71be72eb 100644 --- a/src/test/run-pass/issue-6128.rs +++ b/src/test/run-pass/issue-6128.rs @@ -9,7 +9,7 @@ // except according to those terms. #![allow(unknown_features)] -#![feature(box_syntax)] +#![feature(box_syntax, collections)] extern crate collections; diff --git a/src/test/run-pass/issue-6898.rs b/src/test/run-pass/issue-6898.rs index 9e6293216bc..f40c37b77a3 100644 --- a/src/test/run-pass/issue-6898.rs +++ b/src/test/run-pass/issue-6898.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + use std::intrinsics; /// Returns the size of a type diff --git a/src/test/run-pass/issue-7660.rs b/src/test/run-pass/issue-7660.rs index 9e36b1f5082..27c5796ece9 100644 --- a/src/test/run-pass/issue-7660.rs +++ b/src/test/run-pass/issue-7660.rs @@ -11,6 +11,8 @@ // Regression test for issue 7660 // rvalue lifetime too short when equivalent `match` works +#![feature(collections)] + extern crate collections; use std::collections::HashMap; diff --git a/src/test/run-pass/issue-8398.rs b/src/test/run-pass/issue-8398.rs index f8065d0bcd3..80863c3d6f6 100644 --- a/src/test/run-pass/issue-8398.rs +++ b/src/test/run-pass/issue-8398.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(old_io, io)] + use std::old_io; fn foo(a: &mut old_io::Writer) { diff --git a/src/test/run-pass/issue-8460.rs b/src/test/run-pass/issue-8460.rs index 00339a4e84b..929adbdab49 100644 --- a/src/test/run-pass/issue-8460.rs +++ b/src/test/run-pass/issue-8460.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + use std::num::Int; use std::thread; diff --git a/src/test/run-pass/issue-8827.rs b/src/test/run-pass/issue-8827.rs index d7a86749546..b2aa93d280c 100644 --- a/src/test/run-pass/issue-8827.rs +++ b/src/test/run-pass/issue-8827.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + use std::thread::Thread; use std::sync::mpsc::{channel, Receiver}; diff --git a/src/test/run-pass/issue-9396.rs b/src/test/run-pass/issue-9396.rs index a98d1aba04d..98fc79882c0 100644 --- a/src/test/run-pass/issue-9396.rs +++ b/src/test/run-pass/issue-9396.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(old_io, std_misc)] + use std::sync::mpsc::{TryRecvError, channel}; use std::old_io::timer::Timer; use std::thread::Thread; diff --git a/src/test/run-pass/issue22346.rs b/src/test/run-pass/issue22346.rs index d30a0be5fee..1c58765ef65 100644 --- a/src/test/run-pass/issue22346.rs +++ b/src/test/run-pass/issue22346.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + // This used to cause an ICE because the retslot for the "return" had the wrong type fn testcase<'a>() -> Box + 'a> { return Box::new((0..3).map(|i| { return i; })); diff --git a/src/test/run-pass/istr.rs b/src/test/run-pass/istr.rs index 15195482ed6..0013cb292e1 100644 --- a/src/test/run-pass/istr.rs +++ b/src/test/run-pass/istr.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(collections)] + use std::string::String; fn test_stack_assign() { diff --git a/src/test/run-pass/item-attributes.rs b/src/test/run-pass/item-attributes.rs index 6036af5c627..a262d0323c5 100644 --- a/src/test/run-pass/item-attributes.rs +++ b/src/test/run-pass/item-attributes.rs @@ -12,7 +12,7 @@ // for completeness since .rs files linked from .rc files support this // notation to specify their module's attributes -#![feature(custom_attribute)] +#![feature(custom_attribute, libc)] #![allow(unused_attribute)] #![attr1 = "val"] #![attr2 = "val"] diff --git a/src/test/run-pass/ivec-tag.rs b/src/test/run-pass/ivec-tag.rs index 121338823d2..f2895d7d7d1 100644 --- a/src/test/run-pass/ivec-tag.rs +++ b/src/test/run-pass/ivec-tag.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + use std::thread::Thread; use std::sync::mpsc::{channel, Sender}; diff --git a/src/test/run-pass/kindck-implicit-close-over-mut-var.rs b/src/test/run-pass/kindck-implicit-close-over-mut-var.rs index 9d6ca1e9cfb..ca405f54415 100644 --- a/src/test/run-pass/kindck-implicit-close-over-mut-var.rs +++ b/src/test/run-pass/kindck-implicit-close-over-mut-var.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + use std::thread::Thread; fn user(_i: int) {} diff --git a/src/test/run-pass/last-use-in-cap-clause.rs b/src/test/run-pass/last-use-in-cap-clause.rs index 45964efad97..1dddec32e38 100644 --- a/src/test/run-pass/last-use-in-cap-clause.rs +++ b/src/test/run-pass/last-use-in-cap-clause.rs @@ -12,7 +12,7 @@ #![allow(unknown_features)] #![feature(box_syntax)] -#![feature(unboxed_closures)] +#![feature(unboxed_closures, core)] struct A { a: Box } diff --git a/src/test/run-pass/linkage-visibility.rs b/src/test/run-pass/linkage-visibility.rs index 80a859c03bc..3c238d3fe78 100644 --- a/src/test/run-pass/linkage-visibility.rs +++ b/src/test/run-pass/linkage-visibility.rs @@ -12,6 +12,8 @@ // ignore-android: FIXME(#10379) // ignore-windows: std::dynamic_lib does not work on Windows well +#![feature(std_misc, old_path)] + extern crate "linkage-visibility" as foo; pub fn main() { diff --git a/src/test/run-pass/logging-enabled-debug.rs b/src/test/run-pass/logging-enabled-debug.rs index dfc92728270..d3b6c38da88 100644 --- a/src/test/run-pass/logging-enabled-debug.rs +++ b/src/test/run-pass/logging-enabled-debug.rs @@ -11,6 +11,8 @@ // compile-flags:-C debug-assertions=no // exec-env:RUST_LOG=logging-enabled-debug=debug +#![feature(rustc_private)] + #[macro_use] extern crate log; diff --git a/src/test/run-pass/logging-enabled.rs b/src/test/run-pass/logging-enabled.rs index 372cdc401b5..1dd9f72ab80 100644 --- a/src/test/run-pass/logging-enabled.rs +++ b/src/test/run-pass/logging-enabled.rs @@ -10,6 +10,8 @@ // exec-env:RUST_LOG=logging-enabled=info +#![feature(rustc_private)] + #[macro_use] extern crate log; diff --git a/src/test/run-pass/logging-separate-lines.rs b/src/test/run-pass/logging-separate-lines.rs index 82a155b1173..b27080b65b7 100644 --- a/src/test/run-pass/logging-separate-lines.rs +++ b/src/test/run-pass/logging-separate-lines.rs @@ -12,6 +12,8 @@ // exec-env:RUST_LOG=debug // compile-flags:-C debug-assertions=y +#![feature(old_io, rustc_private)] + #[macro_use] extern crate log; diff --git a/src/test/run-pass/macro-with-braces-in-expr-position.rs b/src/test/run-pass/macro-with-braces-in-expr-position.rs index cb52ba74bbd..80a3b8c9edd 100644 --- a/src/test/run-pass/macro-with-braces-in-expr-position.rs +++ b/src/test/run-pass/macro-with-braces-in-expr-position.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + use std::thread::Thread; macro_rules! expr { ($e: expr) => { $e } } diff --git a/src/test/run-pass/method-mut-self-modifies-mut-slice-lvalue.rs b/src/test/run-pass/method-mut-self-modifies-mut-slice-lvalue.rs index f1d41a0f422..826561bfddd 100644 --- a/src/test/run-pass/method-mut-self-modifies-mut-slice-lvalue.rs +++ b/src/test/run-pass/method-mut-self-modifies-mut-slice-lvalue.rs @@ -12,6 +12,8 @@ // type is `&mut [u8]`, passes in a pointer to the lvalue and not a // temporary. Issue #19147. +#![feature(core, old_io)] + use std::mem; use std::slice; use std::old_io::IoResult; diff --git a/src/test/run-pass/method-two-traits-distinguished-via-where-clause.rs b/src/test/run-pass/method-two-traits-distinguished-via-where-clause.rs index fbecb6851b6..d5950921190 100644 --- a/src/test/run-pass/method-two-traits-distinguished-via-where-clause.rs +++ b/src/test/run-pass/method-two-traits-distinguished-via-where-clause.rs @@ -11,6 +11,8 @@ // Test that we select between traits A and B. To do that, we must // consider the `Sized` bound. +#![feature(core)] + trait A { fn foo(self); } diff --git a/src/test/run-pass/monomorphized-callees-with-ty-params-3314.rs b/src/test/run-pass/monomorphized-callees-with-ty-params-3314.rs index 1164ef1a3c9..11f53f0a980 100644 --- a/src/test/run-pass/monomorphized-callees-with-ty-params-3314.rs +++ b/src/test/run-pass/monomorphized-callees-with-ty-params-3314.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + use std::marker::MarkerTrait; trait Serializer : MarkerTrait { diff --git a/src/test/run-pass/moves-based-on-type-capture-clause.rs b/src/test/run-pass/moves-based-on-type-capture-clause.rs index 3596fa1a006..f0eba366e71 100644 --- a/src/test/run-pass/moves-based-on-type-capture-clause.rs +++ b/src/test/run-pass/moves-based-on-type-capture-clause.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + use std::thread::Thread; pub fn main() { diff --git a/src/test/run-pass/new-box-syntax.rs b/src/test/run-pass/new-box-syntax.rs index 3d4847a119a..1595b677c8d 100644 --- a/src/test/run-pass/new-box-syntax.rs +++ b/src/test/run-pass/new-box-syntax.rs @@ -12,7 +12,7 @@ * http://creativecommons.org/publicdomain/zero/1.0/ */ #![allow(unknown_features)] -#![feature(box_syntax)] +#![feature(box_syntax, alloc)] // Tests that the new `box` syntax works with unique pointers. diff --git a/src/test/run-pass/new-unicode-escapes.rs b/src/test/run-pass/new-unicode-escapes.rs index 7430f730f3b..9e4654a13f0 100644 --- a/src/test/run-pass/new-unicode-escapes.rs +++ b/src/test/run-pass/new-unicode-escapes.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(collections)] + pub fn main() { let s = "\u{2603}"; assert_eq!(s, "☃"); diff --git a/src/test/run-pass/newtype-struct-with-dtor.rs b/src/test/run-pass/newtype-struct-with-dtor.rs index 15c4e8b0453..916ec01257f 100644 --- a/src/test/run-pass/newtype-struct-with-dtor.rs +++ b/src/test/run-pass/newtype-struct-with-dtor.rs @@ -9,6 +9,8 @@ // except according to those terms. +#![feature(libc)] + extern crate libc; use libc::c_int; diff --git a/src/test/run-pass/numeric-method-autoexport.rs b/src/test/run-pass/numeric-method-autoexport.rs index eccc2a41a8d..3e3391b0342 100644 --- a/src/test/run-pass/numeric-method-autoexport.rs +++ b/src/test/run-pass/numeric-method-autoexport.rs @@ -15,6 +15,8 @@ // necessary. Testing the methods of the impls is done within the source // file for each numeric type. +#![feature(core)] + use std::ops::Add; use std::num::ToPrimitive; diff --git a/src/test/run-pass/operator-overloading.rs b/src/test/run-pass/operator-overloading.rs index 3ddc666cd38..e8b0db44161 100644 --- a/src/test/run-pass/operator-overloading.rs +++ b/src/test/run-pass/operator-overloading.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + use std::cmp; use std::ops; diff --git a/src/test/run-pass/option-ext.rs b/src/test/run-pass/option-ext.rs index 7a816f91335..8f5a5e8ece7 100644 --- a/src/test/run-pass/option-ext.rs +++ b/src/test/run-pass/option-ext.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(collections)] + pub fn main() { let thing = "{{ f }}"; let f = thing.find_str("{{"); diff --git a/src/test/run-pass/osx-frameworks.rs b/src/test/run-pass/osx-frameworks.rs index aa4e91320f7..9ac67b4c783 100644 --- a/src/test/run-pass/osx-frameworks.rs +++ b/src/test/run-pass/osx-frameworks.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(libc)] + extern crate libc; #[cfg(target_os = "macos")] diff --git a/src/test/run-pass/out-of-stack-new-thread-no-split.rs b/src/test/run-pass/out-of-stack-new-thread-no-split.rs index 41bf7fe2dfa..3c322f72b75 100644 --- a/src/test/run-pass/out-of-stack-new-thread-no-split.rs +++ b/src/test/run-pass/out-of-stack-new-thread-no-split.rs @@ -14,7 +14,7 @@ //ignore-dragonfly //ignore-bitrig -#![feature(asm)] +#![feature(asm, old_io, std_misc)] use std::old_io::process::Command; use std::env; diff --git a/src/test/run-pass/out-of-stack.rs b/src/test/run-pass/out-of-stack.rs index cc5eb69bb87..47f83eab4c1 100644 --- a/src/test/run-pass/out-of-stack.rs +++ b/src/test/run-pass/out-of-stack.rs @@ -10,7 +10,7 @@ // ignore-android: FIXME (#20004) -#![feature(asm)] +#![feature(asm, old_io)] use std::old_io::process::Command; use std::env; diff --git a/src/test/run-pass/overloaded-autoderef.rs b/src/test/run-pass/overloaded-autoderef.rs index 6436165968d..7b956dc772f 100644 --- a/src/test/run-pass/overloaded-autoderef.rs +++ b/src/test/run-pass/overloaded-autoderef.rs @@ -9,7 +9,7 @@ // except according to those terms. #![allow(unknown_features)] -#![feature(box_syntax)] +#![feature(box_syntax, collections, core)] use std::cell::RefCell; use std::rc::Rc; diff --git a/src/test/run-pass/overloaded-calls-param-vtables.rs b/src/test/run-pass/overloaded-calls-param-vtables.rs index 0ac9c97532b..029a8eaad24 100644 --- a/src/test/run-pass/overloaded-calls-param-vtables.rs +++ b/src/test/run-pass/overloaded-calls-param-vtables.rs @@ -10,7 +10,7 @@ // Tests that nested vtables work with overloaded calls. -#![feature(unboxed_closures)] +#![feature(unboxed_closures, core)] use std::marker::PhantomData; use std::ops::Fn; diff --git a/src/test/run-pass/overloaded-calls-simple.rs b/src/test/run-pass/overloaded-calls-simple.rs index d18a91c5452..fc6540b6e3e 100644 --- a/src/test/run-pass/overloaded-calls-simple.rs +++ b/src/test/run-pass/overloaded-calls-simple.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(lang_items, unboxed_closures)] +#![feature(lang_items, unboxed_closures, core)] use std::ops::{Fn, FnMut, FnOnce}; diff --git a/src/test/run-pass/overloaded-calls-zero-args.rs b/src/test/run-pass/overloaded-calls-zero-args.rs index 78e84b9d55b..e75f217a2c6 100644 --- a/src/test/run-pass/overloaded-calls-zero-args.rs +++ b/src/test/run-pass/overloaded-calls-zero-args.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(unboxed_closures)] +#![feature(unboxed_closures, core)] use std::ops::{FnMut}; diff --git a/src/test/run-pass/overloaded-deref.rs b/src/test/run-pass/overloaded-deref.rs index bb1694be5e2..20e55de2f05 100644 --- a/src/test/run-pass/overloaded-deref.rs +++ b/src/test/run-pass/overloaded-deref.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(collections)] + use std::cell::RefCell; use std::rc::Rc; use std::string::String; diff --git a/src/test/run-pass/overloaded-index-assoc-list.rs b/src/test/run-pass/overloaded-index-assoc-list.rs index 0064748e883..7b059cb6a33 100644 --- a/src/test/run-pass/overloaded-index-assoc-list.rs +++ b/src/test/run-pass/overloaded-index-assoc-list.rs @@ -11,6 +11,8 @@ // Test overloading of the `[]` operator. In particular test that it // takes its argument *by reference*. +#![feature(core)] + use std::ops::Index; struct AssociationList { diff --git a/src/test/run-pass/overloaded-index-autoderef.rs b/src/test/run-pass/overloaded-index-autoderef.rs index 8f655f0517d..214817b0a15 100644 --- a/src/test/run-pass/overloaded-index-autoderef.rs +++ b/src/test/run-pass/overloaded-index-autoderef.rs @@ -11,7 +11,7 @@ // Test overloaded indexing combined with autoderef. #![allow(unknown_features)] -#![feature(box_syntax)] +#![feature(box_syntax, core)] use std::ops::{Index, IndexMut}; diff --git a/src/test/run-pass/overloaded-index-in-field.rs b/src/test/run-pass/overloaded-index-in-field.rs index 487fb93c9fe..66f8c5c4238 100644 --- a/src/test/run-pass/overloaded-index-in-field.rs +++ b/src/test/run-pass/overloaded-index-in-field.rs @@ -11,6 +11,8 @@ // Test using overloaded indexing when the "map" is stored in a // field. This caused problems at some point. +#![feature(core)] + use std::ops::Index; struct Foo { diff --git a/src/test/run-pass/overloaded-index.rs b/src/test/run-pass/overloaded-index.rs index 10ca3804eae..413cef86c5d 100644 --- a/src/test/run-pass/overloaded-index.rs +++ b/src/test/run-pass/overloaded-index.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + use std::ops::{Index, IndexMut}; struct Foo { diff --git a/src/test/run-pass/placement-new-arena.rs b/src/test/run-pass/placement-new-arena.rs index c4cf8357baa..7ac624e6814 100644 --- a/src/test/run-pass/placement-new-arena.rs +++ b/src/test/run-pass/placement-new-arena.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(rustc_private)] + extern crate arena; use arena::Arena; diff --git a/src/test/run-pass/process-remove-from-env.rs b/src/test/run-pass/process-remove-from-env.rs index 9eb7d624c99..68597fe48e5 100644 --- a/src/test/run-pass/process-remove-from-env.rs +++ b/src/test/run-pass/process-remove-from-env.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(old_io)] + use std::old_io::Command; use std::env; diff --git a/src/test/run-pass/process-spawn-with-unicode-params.rs b/src/test/run-pass/process-spawn-with-unicode-params.rs index 72998133af1..32448d100fb 100644 --- a/src/test/run-pass/process-spawn-with-unicode-params.rs +++ b/src/test/run-pass/process-spawn-with-unicode-params.rs @@ -17,6 +17,7 @@ // intact. // ignore-aarch64 +#![feature(path, fs, os, io, old_path)] use std::io::prelude::*; use std::io; diff --git a/src/test/run-pass/realloc-16687.rs b/src/test/run-pass/realloc-16687.rs index e8bcff38131..0b714578c66 100644 --- a/src/test/run-pass/realloc-16687.rs +++ b/src/test/run-pass/realloc-16687.rs @@ -13,6 +13,8 @@ // Ideally this would be revised to use no_std, but for now it serves // well enough to reproduce (and illustrate) the bug from #16687. +#![feature(alloc)] + extern crate alloc; use alloc::heap; diff --git a/src/test/run-pass/regions-copy-closure.rs b/src/test/run-pass/regions-copy-closure.rs index b39343b1f57..ac7c76ac544 100644 --- a/src/test/run-pass/regions-copy-closure.rs +++ b/src/test/run-pass/regions-copy-closure.rs @@ -9,7 +9,7 @@ // except according to those terms. #![allow(unknown_features)] -#![feature(unboxed_closures)] +#![feature(unboxed_closures, core)] struct closure_box<'a> { cl: Box, diff --git a/src/test/run-pass/regions-mock-tcx.rs b/src/test/run-pass/regions-mock-tcx.rs index bf789d53645..f2e0837c6ea 100644 --- a/src/test/run-pass/regions-mock-tcx.rs +++ b/src/test/run-pass/regions-mock-tcx.rs @@ -15,6 +15,8 @@ // - Multiple lifetime parameters // - Arenas +#![feature(rustc_private, libc, collections)] + extern crate arena; extern crate collections; extern crate libc; diff --git a/src/test/run-pass/regions-mock-trans.rs b/src/test/run-pass/regions-mock-trans.rs index e6b997f7588..b2584e2472b 100644 --- a/src/test/run-pass/regions-mock-trans.rs +++ b/src/test/run-pass/regions-mock-trans.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(libc)] + extern crate libc; use std::mem; diff --git a/src/test/run-pass/regions-static-closure.rs b/src/test/run-pass/regions-static-closure.rs index 1bcde77261b..ae39c266808 100644 --- a/src/test/run-pass/regions-static-closure.rs +++ b/src/test/run-pass/regions-static-closure.rs @@ -10,7 +10,7 @@ #![allow(unknown_features)] #![feature(box_syntax)] -#![feature(unboxed_closures)] +#![feature(unboxed_closures, core)] struct closure_box<'a> { cl: Box, diff --git a/src/test/run-pass/rename-directory.rs b/src/test/run-pass/rename-directory.rs index 656fe898969..33a53e44425 100644 --- a/src/test/run-pass/rename-directory.rs +++ b/src/test/run-pass/rename-directory.rs @@ -11,6 +11,8 @@ // This test can't be a unit test in std, // because it needs TempDir, which is in extra +#![feature(tempdir, path_ext)] + use std::ffi::CString; use std::fs::{self, TempDir, File, PathExt}; diff --git a/src/test/run-pass/running-with-no-runtime.rs b/src/test/run-pass/running-with-no-runtime.rs index abb16c39d11..75f66d5bf26 100644 --- a/src/test/run-pass/running-with-no-runtime.rs +++ b/src/test/run-pass/running-with-no-runtime.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(start)] +#![feature(start, os, std_misc, old_io)] use std::ffi; use std::old_io::process::{Command, ProcessOutput}; diff --git a/src/test/run-pass/rust-log-filter.rs b/src/test/run-pass/rust-log-filter.rs index 5d6657c7e12..44d8db075e8 100644 --- a/src/test/run-pass/rust-log-filter.rs +++ b/src/test/run-pass/rust-log-filter.rs @@ -11,7 +11,7 @@ // exec-env:RUST_LOG=rust-log-filter/foo #![allow(unknown_features)] -#![feature(box_syntax)] +#![feature(box_syntax, std_misc, rustc_private)] #[macro_use] extern crate log; diff --git a/src/test/run-pass/segfault-no-out-of-stack.rs b/src/test/run-pass/segfault-no-out-of-stack.rs index 492736c2252..d2842a99485 100644 --- a/src/test/run-pass/segfault-no-out-of-stack.rs +++ b/src/test/run-pass/segfault-no-out-of-stack.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(old_io)] + use std::old_io::process::Command; use std::env; diff --git a/src/test/run-pass/send-resource.rs b/src/test/run-pass/send-resource.rs index a920d76e7ca..a1e28b2b261 100644 --- a/src/test/run-pass/send-resource.rs +++ b/src/test/run-pass/send-resource.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + use std::thread::Thread; use std::sync::mpsc::channel; diff --git a/src/test/run-pass/send_str_hashmap.rs b/src/test/run-pass/send_str_hashmap.rs index 33e4fa85bcb..54214feee05 100644 --- a/src/test/run-pass/send_str_hashmap.rs +++ b/src/test/run-pass/send_str_hashmap.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(collections)] + extern crate collections; use std::collections::HashMap; diff --git a/src/test/run-pass/send_str_treemap.rs b/src/test/run-pass/send_str_treemap.rs index 3390369242d..9741d468bd2 100644 --- a/src/test/run-pass/send_str_treemap.rs +++ b/src/test/run-pass/send_str_treemap.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(collections)] + extern crate collections; use self::collections::BTreeMap; diff --git a/src/test/run-pass/signal-exit-status.rs b/src/test/run-pass/signal-exit-status.rs index 776d897938d..90bb36f25f7 100644 --- a/src/test/run-pass/signal-exit-status.rs +++ b/src/test/run-pass/signal-exit-status.rs @@ -10,6 +10,9 @@ // ignore-windows +#![feature(old_io)] +#![feature(os)] + use std::env; use std::old_io::process::{Command, ExitSignal, ExitStatus}; diff --git a/src/test/run-pass/simd-binop.rs b/src/test/run-pass/simd-binop.rs index 779e507f43d..45a91abe56c 100644 --- a/src/test/run-pass/simd-binop.rs +++ b/src/test/run-pass/simd-binop.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] use std::simd::{i32x4, f32x4, u32x4}; diff --git a/src/test/run-pass/simd-issue-10604.rs b/src/test/run-pass/simd-issue-10604.rs index 7f1be4b7d70..bd3f8f35352 100644 --- a/src/test/run-pass/simd-issue-10604.rs +++ b/src/test/run-pass/simd-issue-10604.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - +#![feature(core)] #![feature(simd)] pub fn main() { diff --git a/src/test/run-pass/slice.rs b/src/test/run-pass/slice.rs index 30b53dbb0ad..aaa4cb27f8d 100644 --- a/src/test/run-pass/slice.rs +++ b/src/test/run-pass/slice.rs @@ -10,7 +10,7 @@ // Test slicing sugar. -#![feature(associated_types)] +#![feature(core)] extern crate core; use core::ops::{Index, IndexMut, Range, RangeTo, RangeFrom, RangeFull}; diff --git a/src/test/run-pass/smallest-hello-world.rs b/src/test/run-pass/smallest-hello-world.rs index 61b2fc8b50f..c7db8068785 100644 --- a/src/test/run-pass/smallest-hello-world.rs +++ b/src/test/run-pass/smallest-hello-world.rs @@ -10,7 +10,7 @@ // Smallest "hello world" with a libc runtime -#![feature(intrinsics, lang_items, start, no_std)] +#![feature(intrinsics, lang_items, start, no_std, libc)] #![no_std] extern crate libc; diff --git a/src/test/run-pass/spawn-fn.rs b/src/test/run-pass/spawn-fn.rs index c8fe400c4c3..4f8ba7f655e 100644 --- a/src/test/run-pass/spawn-fn.rs +++ b/src/test/run-pass/spawn-fn.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + use std::thread::Thread; fn x(s: String, n: int) { diff --git a/src/test/run-pass/stat.rs b/src/test/run-pass/stat.rs index 1ccc189dc81..159081a0e97 100644 --- a/src/test/run-pass/stat.rs +++ b/src/test/run-pass/stat.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(tempdir, path_ext)] + use std::fs::{File, TempDir}; use std::io::prelude::*; diff --git a/src/test/run-pass/static-mut-foreign.rs b/src/test/run-pass/static-mut-foreign.rs index e5d4591361a..6d191ba1c58 100644 --- a/src/test/run-pass/static-mut-foreign.rs +++ b/src/test/run-pass/static-mut-foreign.rs @@ -12,6 +12,8 @@ // statics cannot. This ensures that there's some form of error if this is // attempted. +#![feature(libc)] + extern crate libc; #[link(name = "rust_test_helpers")] diff --git a/src/test/run-pass/std-sync-right-kind-impls.rs b/src/test/run-pass/std-sync-right-kind-impls.rs index d2d72ed1661..46b70f91e71 100644 --- a/src/test/run-pass/std-sync-right-kind-impls.rs +++ b/src/test/run-pass/std-sync-right-kind-impls.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc, alloc)] + use std::sync; fn assert_both() {} diff --git a/src/test/run-pass/supported-cast.rs b/src/test/run-pass/supported-cast.rs index 3fffef060a1..7f705146aaa 100644 --- a/src/test/run-pass/supported-cast.rs +++ b/src/test/run-pass/supported-cast.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(libc)] + extern crate libc; pub fn main() { diff --git a/src/test/run-pass/syntax-extension-source-utils.rs b/src/test/run-pass/syntax-extension-source-utils.rs index 684ca7fa2b6..b3f503aad34 100644 --- a/src/test/run-pass/syntax-extension-source-utils.rs +++ b/src/test/run-pass/syntax-extension-source-utils.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + // This test is brittle! // ignore-pretty - the pretty tests lose path information, breaking include! @@ -22,9 +24,9 @@ pub mod m1 { macro_rules! indirect_line { () => ( line!() ) } pub fn main() { - assert_eq!(line!(), 25); + assert_eq!(line!(), 27); assert!((column!() == 4)); - assert_eq!(indirect_line!(), 27); + assert_eq!(indirect_line!(), 29); assert!((file!().ends_with("syntax-extension-source-utils.rs"))); assert_eq!(stringify!((2*3) + 5).to_string(), "( 2 * 3 ) + 5".to_string()); assert!(include!("syntax-extension-source-utils-files/includeme.\ @@ -42,7 +44,7 @@ pub fn main() { // The Windows tests are wrapped in an extra module for some reason assert!((m1::m2::where_am_i().ends_with("m1::m2"))); - assert!(match (45, "( 2 * 3 ) + 5") { + assert!(match (47, "( 2 * 3 ) + 5") { (line!(), stringify!((2*3) + 5)) => true, _ => false }) diff --git a/src/test/run-pass/syntax-trait-polarity.rs b/src/test/run-pass/syntax-trait-polarity.rs index 340ad2a531a..544234046eb 100644 --- a/src/test/run-pass/syntax-trait-polarity.rs +++ b/src/test/run-pass/syntax-trait-polarity.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(optin_builtin_traits)] +#![feature(optin_builtin_traits, core)] use std::marker::{MarkerTrait, Send}; diff --git a/src/test/run-pass/task-comm-0.rs b/src/test/run-pass/task-comm-0.rs index 78826666f53..a24d61c8cea 100644 --- a/src/test/run-pass/task-comm-0.rs +++ b/src/test/run-pass/task-comm-0.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + use std::thread::Thread; use std::sync::mpsc::{channel, Sender}; diff --git a/src/test/run-pass/task-comm-1.rs b/src/test/run-pass/task-comm-1.rs index 180f6e09ba9..e882d8506fc 100644 --- a/src/test/run-pass/task-comm-1.rs +++ b/src/test/run-pass/task-comm-1.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + use std::thread::Thread; pub fn main() { test00(); } diff --git a/src/test/run-pass/task-comm-10.rs b/src/test/run-pass/task-comm-10.rs index 60af3afec2b..99eebdb601a 100644 --- a/src/test/run-pass/task-comm-10.rs +++ b/src/test/run-pass/task-comm-10.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + use std::thread::Thread; use std::sync::mpsc::{channel, Sender}; diff --git a/src/test/run-pass/task-comm-11.rs b/src/test/run-pass/task-comm-11.rs index 1740c49c772..c33872e30c4 100644 --- a/src/test/run-pass/task-comm-11.rs +++ b/src/test/run-pass/task-comm-11.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + use std::sync::mpsc::{channel, Sender}; use std::thread::Thread; diff --git a/src/test/run-pass/task-comm-12.rs b/src/test/run-pass/task-comm-12.rs index 08dce2a7648..ff6d959327d 100644 --- a/src/test/run-pass/task-comm-12.rs +++ b/src/test/run-pass/task-comm-12.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + use std::thread::Thread; pub fn main() { test00(); } diff --git a/src/test/run-pass/task-comm-13.rs b/src/test/run-pass/task-comm-13.rs index 429c6ce9fb3..1f7da10252b 100644 --- a/src/test/run-pass/task-comm-13.rs +++ b/src/test/run-pass/task-comm-13.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + use std::sync::mpsc::{channel, Sender}; use std::thread::Thread; diff --git a/src/test/run-pass/task-comm-14.rs b/src/test/run-pass/task-comm-14.rs index 0735e3996ee..785df73317a 100644 --- a/src/test/run-pass/task-comm-14.rs +++ b/src/test/run-pass/task-comm-14.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + use std::sync::mpsc::{channel, Sender}; use std::thread::Thread; diff --git a/src/test/run-pass/task-comm-15.rs b/src/test/run-pass/task-comm-15.rs index 28eea784f36..e9ae3d2a25a 100644 --- a/src/test/run-pass/task-comm-15.rs +++ b/src/test/run-pass/task-comm-15.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + use std::sync::mpsc::{channel, Sender}; use std::thread::Thread; diff --git a/src/test/run-pass/task-comm-17.rs b/src/test/run-pass/task-comm-17.rs index 9db5465f7e9..f5ca52ba4b6 100644 --- a/src/test/run-pass/task-comm-17.rs +++ b/src/test/run-pass/task-comm-17.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + // Issue #922 // This test is specifically about spawning temporary closures. diff --git a/src/test/run-pass/task-comm-3.rs b/src/test/run-pass/task-comm-3.rs index 90282946838..bb0749eb8c0 100644 --- a/src/test/run-pass/task-comm-3.rs +++ b/src/test/run-pass/task-comm-3.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + // no-pretty-expanded FIXME #15189 use std::thread::Thread; diff --git a/src/test/run-pass/task-comm-7.rs b/src/test/run-pass/task-comm-7.rs index 6f3b47b8bfa..263ad0e4c02 100644 --- a/src/test/run-pass/task-comm-7.rs +++ b/src/test/run-pass/task-comm-7.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] #![allow(dead_assignment)] use std::sync::mpsc::{channel, Sender}; diff --git a/src/test/run-pass/task-comm-9.rs b/src/test/run-pass/task-comm-9.rs index 6d8de4a6a53..81d9148955a 100644 --- a/src/test/run-pass/task-comm-9.rs +++ b/src/test/run-pass/task-comm-9.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + use std::thread::Thread; use std::sync::mpsc::{channel, Sender}; diff --git a/src/test/run-pass/task-life-0.rs b/src/test/run-pass/task-life-0.rs index 3f229926480..462b38f6598 100644 --- a/src/test/run-pass/task-life-0.rs +++ b/src/test/run-pass/task-life-0.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + use std::thread::Thread; pub fn main() { diff --git a/src/test/run-pass/task-spawn-move-and-copy.rs b/src/test/run-pass/task-spawn-move-and-copy.rs index 46f9e991347..eb6bec9a092 100644 --- a/src/test/run-pass/task-spawn-move-and-copy.rs +++ b/src/test/run-pass/task-spawn-move-and-copy.rs @@ -9,7 +9,7 @@ // except according to those terms. #![allow(unknown_features)] -#![feature(box_syntax)] +#![feature(box_syntax, std_misc)] use std::thread::Thread; use std::sync::mpsc::channel; diff --git a/src/test/run-pass/task-stderr.rs b/src/test/run-pass/task-stderr.rs index 3131cda1dbc..824d240568f 100644 --- a/src/test/run-pass/task-stderr.rs +++ b/src/test/run-pass/task-stderr.rs @@ -9,7 +9,7 @@ // except according to those terms. #![allow(unknown_features)] -#![feature(box_syntax)] +#![feature(box_syntax, old_io, std_misc, io, set_panic, set_stdio)] use std::io::prelude::*; use std::io; diff --git a/src/test/run-pass/tcp-accept-stress.rs b/src/test/run-pass/tcp-accept-stress.rs index b87718ba468..5633ef2ecfc 100644 --- a/src/test/run-pass/tcp-accept-stress.rs +++ b/src/test/run-pass/tcp-accept-stress.rs @@ -13,6 +13,8 @@ // quite quickly and it takes a few seconds for the sockets to get // recycled. +#![feature(old_io, io, std_misc)] + use std::old_io::{TcpListener, Listener, Acceptor, EndOfFile, TcpStream}; use std::sync::Arc; use std::sync::atomic::{AtomicUsize, Ordering}; diff --git a/src/test/run-pass/tcp-connect-timeouts.rs b/src/test/run-pass/tcp-connect-timeouts.rs index 5462a996f73..a9a16cd72df 100644 --- a/src/test/run-pass/tcp-connect-timeouts.rs +++ b/src/test/run-pass/tcp-connect-timeouts.rs @@ -19,6 +19,7 @@ #![reexport_test_harness_main = "test_main"] #![allow(unused_imports)] +#![feature(old_io, std_misc, io)] use std::old_io::*; use std::old_io::test::*; diff --git a/src/test/run-pass/tempfile.rs b/src/test/run-pass/tempfile.rs index bc655837bab..74290518364 100644 --- a/src/test/run-pass/tempfile.rs +++ b/src/test/run-pass/tempfile.rs @@ -18,6 +18,8 @@ // they're in a different location than before. Hence, these tests are all run // serially here. +#![feature(old_io, old_path, os, old_fs)] + use std::old_path::{Path, GenericPath}; use std::old_io::fs::PathExtensions; use std::old_io::{fs, TempDir}; diff --git a/src/test/run-pass/test-fn-signature-verification-for-explicit-return-type.rs b/src/test/run-pass/test-fn-signature-verification-for-explicit-return-type.rs index df3c9a0f119..d58b5d3a00f 100644 --- a/src/test/run-pass/test-fn-signature-verification-for-explicit-return-type.rs +++ b/src/test/run-pass/test-fn-signature-verification-for-explicit-return-type.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(test)] + // compile-flags: --test // no-pretty-expanded extern crate test; diff --git a/src/test/run-pass/threads.rs b/src/test/run-pass/threads.rs index abc2938df00..436fb1fe9b5 100644 --- a/src/test/run-pass/threads.rs +++ b/src/test/run-pass/threads.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(std_misc)] + use std::thread::Thread; pub fn main() { diff --git a/src/test/run-pass/trait-bounds-basic.rs b/src/test/run-pass/trait-bounds-basic.rs index ed25bf8b02e..cc2347fb5f3 100644 --- a/src/test/run-pass/trait-bounds-basic.rs +++ b/src/test/run-pass/trait-bounds-basic.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] trait Foo : ::std::marker::MarkerTrait { } diff --git a/src/test/run-pass/trait-bounds-in-arc.rs b/src/test/run-pass/trait-bounds-in-arc.rs index cf23785b844..d2782976463 100644 --- a/src/test/run-pass/trait-bounds-in-arc.rs +++ b/src/test/run-pass/trait-bounds-in-arc.rs @@ -14,7 +14,7 @@ // ignore-pretty #![allow(unknown_features)] -#![feature(box_syntax)] +#![feature(box_syntax, std_misc)] #![feature(unboxed_closures)] use std::sync::Arc; diff --git a/src/test/run-pass/trait-bounds-on-structs-and-enums.rs b/src/test/run-pass/trait-bounds-on-structs-and-enums.rs index 976120908b2..6d080adbe63 100644 --- a/src/test/run-pass/trait-bounds-on-structs-and-enums.rs +++ b/src/test/run-pass/trait-bounds-on-structs-and-enums.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + trait U : ::std::marker::MarkerTrait {} trait T { fn get(self) -> X; } diff --git a/src/test/run-pass/trait-bounds-recursion.rs b/src/test/run-pass/trait-bounds-recursion.rs index 7135dad7d19..d10e098f9d6 100644 --- a/src/test/run-pass/trait-bounds-recursion.rs +++ b/src/test/run-pass/trait-bounds-recursion.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + trait I { fn i(&self) -> Self; } trait A : ::std::marker::MarkerTrait { diff --git a/src/test/run-pass/trait-coercion.rs b/src/test/run-pass/trait-coercion.rs index d1af6b746ac..6f2fc8ba79a 100644 --- a/src/test/run-pass/trait-coercion.rs +++ b/src/test/run-pass/trait-coercion.rs @@ -8,7 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(box_syntax)] +#![allow(unknown_features)] +#![feature(box_syntax, old_io, io)] use std::io::{self, Write}; diff --git a/src/test/run-pass/trait-inheritance-num.rs b/src/test/run-pass/trait-inheritance-num.rs index 5fb28eb9d8d..251223e30fb 100644 --- a/src/test/run-pass/trait-inheritance-num.rs +++ b/src/test/run-pass/trait-inheritance-num.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + use std::cmp::{PartialEq, PartialOrd}; use std::num::NumCast; diff --git a/src/test/run-pass/trait-inheritance-num0.rs b/src/test/run-pass/trait-inheritance-num0.rs index 183d6659062..8de226b7345 100644 --- a/src/test/run-pass/trait-inheritance-num0.rs +++ b/src/test/run-pass/trait-inheritance-num0.rs @@ -10,6 +10,8 @@ // Extending Num and using inherited static methods +#![feature(core)] + use std::cmp::PartialOrd; use std::num::NumCast; diff --git a/src/test/run-pass/trait-inheritance-num1.rs b/src/test/run-pass/trait-inheritance-num1.rs index 15fb5df4626..33b31a98599 100644 --- a/src/test/run-pass/trait-inheritance-num1.rs +++ b/src/test/run-pass/trait-inheritance-num1.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + use std::cmp::PartialOrd; use std::num::NumCast; diff --git a/src/test/run-pass/trait-inheritance-num2.rs b/src/test/run-pass/trait-inheritance-num2.rs index 1fb28c50652..df751a6d004 100644 --- a/src/test/run-pass/trait-inheritance-num2.rs +++ b/src/test/run-pass/trait-inheritance-num2.rs @@ -10,6 +10,8 @@ // A more complex example of numeric extensions +#![feature(core)] + use std::cmp::{PartialEq, PartialOrd}; use std::num::NumCast; diff --git a/src/test/run-pass/trait-inheritance-num3.rs b/src/test/run-pass/trait-inheritance-num3.rs index 09015d983ea..b5cf25bc5a8 100644 --- a/src/test/run-pass/trait-inheritance-num3.rs +++ b/src/test/run-pass/trait-inheritance-num3.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + use std::cmp::{PartialEq, PartialOrd}; use std::num::NumCast; diff --git a/src/test/run-pass/trait-inheritance-num5.rs b/src/test/run-pass/trait-inheritance-num5.rs index a21026839a7..acd60cea61f 100644 --- a/src/test/run-pass/trait-inheritance-num5.rs +++ b/src/test/run-pass/trait-inheritance-num5.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + use std::cmp::PartialEq; use std::num::NumCast; diff --git a/src/test/run-pass/trait-inheritance-static2.rs b/src/test/run-pass/trait-inheritance-static2.rs index 8f3b325a513..caedaf35737 100644 --- a/src/test/run-pass/trait-inheritance-static2.rs +++ b/src/test/run-pass/trait-inheritance-static2.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] + pub trait MyEq : ::std::marker::MarkerTrait { } pub trait MyNum : ::std::marker::MarkerTrait { diff --git a/src/test/run-pass/tydesc-name.rs b/src/test/run-pass/tydesc-name.rs index 2e7717fcfe1..2e8adfe508b 100644 --- a/src/test/run-pass/tydesc-name.rs +++ b/src/test/run-pass/tydesc-name.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(core)] use std::intrinsics::type_name; diff --git a/src/test/run-pass/type-id-higher-rank.rs b/src/test/run-pass/type-id-higher-rank.rs index d33ebeadba8..e4d7d292056 100644 --- a/src/test/run-pass/type-id-higher-rank.rs +++ b/src/test/run-pass/type-id-higher-rank.rs @@ -11,7 +11,7 @@ // Test that type IDs correctly account for higher-rank lifetimes // Also acts as a regression test for an ICE (issue #19791) -#![feature(unboxed_closures)] +#![feature(unboxed_closures, core)] use std::any::TypeId; diff --git a/src/test/run-pass/typeid-intrinsic.rs b/src/test/run-pass/typeid-intrinsic.rs index a251fcc7327..fd425214100 100644 --- a/src/test/run-pass/typeid-intrinsic.rs +++ b/src/test/run-pass/typeid-intrinsic.rs @@ -11,6 +11,8 @@ // aux-build:typeid-intrinsic.rs // aux-build:typeid-intrinsic2.rs +#![feature(hash, core)] + extern crate "typeid-intrinsic" as other1; extern crate "typeid-intrinsic2" as other2; diff --git a/src/test/run-pass/ufcs-polymorphic-paths.rs b/src/test/run-pass/ufcs-polymorphic-paths.rs index 29b1c8f81d3..1197e7c1414 100644 --- a/src/test/run-pass/ufcs-polymorphic-paths.rs +++ b/src/test/run-pass/ufcs-polymorphic-paths.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(macro_rules)] +#![feature(collections, rand)] use std::borrow::{Cow, IntoCow}; use std::collections::BitVec; diff --git a/src/test/run-pass/unboxed-closures-extern-fn-hr.rs b/src/test/run-pass/unboxed-closures-extern-fn-hr.rs index 6a071f6a4c5..774aed71ec8 100644 --- a/src/test/run-pass/unboxed-closures-extern-fn-hr.rs +++ b/src/test/run-pass/unboxed-closures-extern-fn-hr.rs @@ -10,7 +10,7 @@ // Checks that higher-ranked extern fn pointers implement the full range of Fn traits. -#![feature(unboxed_closures)] +#![feature(unboxed_closures, core)] use std::ops::{Fn,FnMut,FnOnce}; diff --git a/src/test/run-pass/unboxed-closures-fn-as-fnmut-and-fnonce.rs b/src/test/run-pass/unboxed-closures-fn-as-fnmut-and-fnonce.rs index 0aab5be2877..9f211e6d600 100644 --- a/src/test/run-pass/unboxed-closures-fn-as-fnmut-and-fnonce.rs +++ b/src/test/run-pass/unboxed-closures-fn-as-fnmut-and-fnonce.rs @@ -11,8 +11,7 @@ // Checks that the Fn trait hierarchy rules permit // any Fn trait to be used where Fn is implemented. -#![feature(unboxed_closures)] -#![feature(unboxed_closures)] +#![feature(unboxed_closures, core)] use std::ops::{Fn,FnMut,FnOnce}; diff --git a/src/test/run-pass/unboxed-closures-fnmut-as-fnonce.rs b/src/test/run-pass/unboxed-closures-fnmut-as-fnonce.rs index a8bb0918932..33b1a2d5470 100644 --- a/src/test/run-pass/unboxed-closures-fnmut-as-fnonce.rs +++ b/src/test/run-pass/unboxed-closures-fnmut-as-fnonce.rs @@ -11,8 +11,7 @@ // Checks that the Fn trait hierarchy rules permit // FnMut or FnOnce to be used where FnMut is implemented. -#![feature(unboxed_closures)] -#![feature(unboxed_closures)] +#![feature(unboxed_closures, core)] use std::ops::{FnMut,FnOnce}; diff --git a/src/test/run-pass/unboxed-closures-infer-argument-types-from-expected-bound.rs b/src/test/run-pass/unboxed-closures-infer-argument-types-from-expected-bound.rs index 56de1596110..2b5b5f7f707 100644 --- a/src/test/run-pass/unboxed-closures-infer-argument-types-from-expected-bound.rs +++ b/src/test/run-pass/unboxed-closures-infer-argument-types-from-expected-bound.rs @@ -11,7 +11,7 @@ // Test that we are able to infer that the type of `x` is `int` based // on the expected type from the object. -#![feature(unboxed_closures)] +#![feature(unboxed_closures, core)] use std::num::ToPrimitive; diff --git a/src/test/run-pass/unboxed-closures-infer-argument-types-from-expected-object-type.rs b/src/test/run-pass/unboxed-closures-infer-argument-types-from-expected-object-type.rs index c74ed665e7a..85b17d4b4d8 100644 --- a/src/test/run-pass/unboxed-closures-infer-argument-types-from-expected-object-type.rs +++ b/src/test/run-pass/unboxed-closures-infer-argument-types-from-expected-object-type.rs @@ -11,7 +11,7 @@ // Test that we are able to infer that the type of `x` is `int` based // on the expected type from the object. -#![feature(unboxed_closures)] +#![feature(unboxed_closures, core)] use std::num::ToPrimitive; diff --git a/src/test/run-pass/unboxed-closures-infer-argument-types-with-bound-regions-from-expected-bound.rs b/src/test/run-pass/unboxed-closures-infer-argument-types-with-bound-regions-from-expected-bound.rs index a61dd095a0d..f962a435020 100644 --- a/src/test/run-pass/unboxed-closures-infer-argument-types-with-bound-regions-from-expected-bound.rs +++ b/src/test/run-pass/unboxed-closures-infer-argument-types-with-bound-regions-from-expected-bound.rs @@ -11,7 +11,7 @@ // Test that we are able to infer that the type of `x` is `int` based // on the expected type from the object. -#![feature(unboxed_closures)] +#![feature(unboxed_closures, core)] use std::num::ToPrimitive; diff --git a/src/test/run-pass/unboxed-closures-manual-impl.rs b/src/test/run-pass/unboxed-closures-manual-impl.rs index f1b79a1829e..f2c278c2988 100644 --- a/src/test/run-pass/unboxed-closures-manual-impl.rs +++ b/src/test/run-pass/unboxed-closures-manual-impl.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(unboxed_closures)] +#![feature(unboxed_closures, core)] use std::ops::FnMut; diff --git a/src/test/run-pass/unboxed-closures-monomorphization.rs b/src/test/run-pass/unboxed-closures-monomorphization.rs index 056ae63b684..e221811948c 100644 --- a/src/test/run-pass/unboxed-closures-monomorphization.rs +++ b/src/test/run-pass/unboxed-closures-monomorphization.rs @@ -13,7 +13,7 @@ #![allow(unknown_features)] #![feature(box_syntax)] -#![feature(unboxed_closures)] +#![feature(unboxed_closures, core)] fn main(){ fn bar<'a, T:Clone+'a> (t: T) -> BoxT + 'a> { diff --git a/src/test/run-pass/unboxed-closures-prelude.rs b/src/test/run-pass/unboxed-closures-prelude.rs index 4ed3fa5ca2d..61070abdcbe 100644 --- a/src/test/run-pass/unboxed-closures-prelude.rs +++ b/src/test/run-pass/unboxed-closures-prelude.rs @@ -12,7 +12,7 @@ #![allow(unknown_features)] #![feature(box_syntax)] -#![feature(unboxed_closures)] +#![feature(unboxed_closures, core)] fn main() { // FIXME (#22405): Replace `Box::new` with `box` here when/if possible. diff --git a/src/test/run-pass/unfold-cross-crate.rs b/src/test/run-pass/unfold-cross-crate.rs index 2af38047264..4ad3f0e591b 100644 --- a/src/test/run-pass/unfold-cross-crate.rs +++ b/src/test/run-pass/unfold-cross-crate.rs @@ -10,6 +10,8 @@ // no-pretty-expanded FIXME #15189 +#![feature(core)] + use std::iter::Unfold; // Unfold had a bug with 'a that mean it didn't work diff --git a/src/test/run-pass/unit-like-struct-drop-run.rs b/src/test/run-pass/unit-like-struct-drop-run.rs index 66cc8d658c0..b035cb89c36 100644 --- a/src/test/run-pass/unit-like-struct-drop-run.rs +++ b/src/test/run-pass/unit-like-struct-drop-run.rs @@ -10,6 +10,8 @@ // Make sure the destructor is run for unit-like structs. +#![feature(alloc)] + use std::boxed::BoxAny; use std::thread; diff --git a/src/test/run-pass/unsized3.rs b/src/test/run-pass/unsized3.rs index f9185cd2642..de5e356f8cd 100644 --- a/src/test/run-pass/unsized3.rs +++ b/src/test/run-pass/unsized3.rs @@ -11,7 +11,7 @@ // Test structs with always-unsized fields. #![allow(unknown_features)] -#![feature(box_syntax)] +#![feature(box_syntax, core)] use std::mem; use std::raw; diff --git a/src/test/run-pass/utf8_chars.rs b/src/test/run-pass/utf8_chars.rs index c54b3b69c68..45a3f2327aa 100644 --- a/src/test/run-pass/utf8_chars.rs +++ b/src/test/run-pass/utf8_chars.rs @@ -10,6 +10,8 @@ // // ignore-lexer-test FIXME #15679 +#![feature(collections, core, str_char)] + use std::str; pub fn main() { diff --git a/src/test/run-pass/variadic-ffi.rs b/src/test/run-pass/variadic-ffi.rs index 60d617822cd..badd8b89877 100644 --- a/src/test/run-pass/variadic-ffi.rs +++ b/src/test/run-pass/variadic-ffi.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(libc, std_misc)] + extern crate libc; use std::ffi::{self, CString}; diff --git a/src/test/run-pass/variance-intersection-of-ref-and-opt-ref.rs b/src/test/run-pass/variance-intersection-of-ref-and-opt-ref.rs index 948d68e0ccd..fe1deba7b0d 100644 --- a/src/test/run-pass/variance-intersection-of-ref-and-opt-ref.rs +++ b/src/test/run-pass/variance-intersection-of-ref-and-opt-ref.rs @@ -14,6 +14,7 @@ // common intersection. #![allow(dead_code)] +#![feature(core)] struct List<'l> { field1: &'l i32, diff --git a/src/test/run-pass/variance-vec-covariant.rs b/src/test/run-pass/variance-vec-covariant.rs index caec6df5a4d..9e98ca0be3b 100644 --- a/src/test/run-pass/variance-vec-covariant.rs +++ b/src/test/run-pass/variance-vec-covariant.rs @@ -11,6 +11,7 @@ // Test that vec is now covariant in its argument type. #![allow(dead_code)] +#![feature(core)] fn foo<'a,'b>(v1: Vec<&'a i32>, v2: Vec<&'b i32>) -> i32 { bar(v1, v2).cloned().unwrap_or(0) // only type checks if we can intersect 'a and 'b diff --git a/src/test/run-pass/vec-concat.rs b/src/test/run-pass/vec-concat.rs index 64c4c17386b..870d48213c7 100644 --- a/src/test/run-pass/vec-concat.rs +++ b/src/test/run-pass/vec-concat.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(collections)] + use std::vec; pub fn main() { diff --git a/src/test/run-pass/vec-macro-no-std.rs b/src/test/run-pass/vec-macro-no-std.rs index 47b87fce2ab..a0e789674d2 100644 --- a/src/test/run-pass/vec-macro-no-std.rs +++ b/src/test/run-pass/vec-macro-no-std.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(lang_items, start, no_std)] +#![feature(lang_items, start, no_std, core, libc, collections)] #![no_std] extern crate "std" as other; diff --git a/src/test/run-pass/vector-sort-panic-safe.rs b/src/test/run-pass/vector-sort-panic-safe.rs index a6f4b8299cb..c029aa23448 100644 --- a/src/test/run-pass/vector-sort-panic-safe.rs +++ b/src/test/run-pass/vector-sort-panic-safe.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(rand, core)] + use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; use std::rand::{thread_rng, Rng, Rand}; use std::thread; diff --git a/src/test/run-pass/wait-forked-but-failed-child.rs b/src/test/run-pass/wait-forked-but-failed-child.rs index dcbecb859e5..5637263e935 100644 --- a/src/test/run-pass/wait-forked-but-failed-child.rs +++ b/src/test/run-pass/wait-forked-but-failed-child.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(libc, old_io)] + extern crate libc; use std::old_io::process::Command; diff --git a/src/test/run-pass/while-let.rs b/src/test/run-pass/while-let.rs index 1780445fb3b..e2352002c03 100644 --- a/src/test/run-pass/while-let.rs +++ b/src/test/run-pass/while-let.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(collections)] + use std::collections::BinaryHeap; fn make_pq() -> BinaryHeap { diff --git a/src/test/run-pass/while-prelude-drop.rs b/src/test/run-pass/while-prelude-drop.rs index bfabcb4d87b..84808fff0fa 100644 --- a/src/test/run-pass/while-prelude-drop.rs +++ b/src/test/run-pass/while-prelude-drop.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(collections)] + use std::string::String; #[derive(PartialEq)] -- cgit 1.4.1-3-g733a5 From e9019101a82dd7f61dcdcd52bcc0123d5ed25d22 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 13 Mar 2015 15:28:35 -0700 Subject: Add #![feature] attributes to doctests --- src/doc/reference.md | 6 +++-- src/doc/trpl/concurrency.md | 5 ++++ src/doc/trpl/ffi.md | 8 ++++++ src/doc/trpl/iterators.md | 2 ++ src/doc/trpl/method-syntax.md | 3 +++ src/doc/trpl/more-strings.md | 1 + src/doc/trpl/standard-input.md | 4 ++- src/doc/trpl/testing.md | 2 ++ src/doc/trpl/traits.md | 6 +++++ src/doc/trpl/unsafe.md | 5 ++++ src/liballoc/arc.rs | 8 ++++++ src/liballoc/boxed.rs | 3 +++ src/liballoc/lib.rs | 1 + src/liballoc/rc.rs | 12 +++++++++ src/libcollections/binary_heap.rs | 8 ++++++ src/libcollections/bit.rs | 45 ++++++++++++++++++++++++++++++++ src/libcollections/btree/map.rs | 5 ++++ src/libcollections/btree/set.rs | 11 ++++++++ src/libcollections/fmt.rs | 3 +++ src/libcollections/lib.rs | 1 + src/libcollections/linked_list.rs | 7 +++++ src/libcollections/slice.rs | 9 +++++++ src/libcollections/str.rs | 15 +++++++++++ src/libcollections/string.rs | 12 +++++++++ src/libcollections/vec.rs | 11 ++++++++ src/libcollections/vec_deque.rs | 15 +++++++++++ src/libcollections/vec_map.rs | 21 +++++++++++++++ src/libcore/cell.rs | 1 + src/libcore/cmp.rs | 7 ++++- src/libcore/error.rs | 1 + src/libcore/finally.rs | 2 ++ src/libcore/fmt/mod.rs | 4 +++ src/libcore/fmt/num.rs | 1 + src/libcore/hash/mod.rs | 2 ++ src/libcore/intrinsics.rs | 2 ++ src/libcore/iter.rs | 22 ++++++++++++++-- src/libcore/lib.rs | 1 + src/libcore/macros.rs | 1 + src/libcore/marker.rs | 1 + src/libcore/num/f32.rs | 3 ++- src/libcore/num/f64.rs | 3 ++- src/libcore/num/mod.rs | 22 ++++++++++++++++ src/libcore/option.rs | 4 +++ src/libcore/ptr.rs | 2 ++ src/libcore/raw.rs | 2 ++ src/libcore/result.rs | 9 +++++++ src/libcore/simd.rs | 2 +- src/libcore/slice.rs | 1 + src/libgraphviz/lib.rs | 3 +++ src/liblibc/lib.rs | 2 +- src/librand/distributions/exponential.rs | 1 + src/librand/distributions/gamma.rs | 4 +++ src/librand/distributions/mod.rs | 1 + src/librand/distributions/normal.rs | 2 ++ src/librand/distributions/range.rs | 1 + src/librand/lib.rs | 12 +++++++++ src/librand/reseeding.rs | 1 + src/librustc_bitflags/lib.rs | 2 ++ src/librustdoc/test.rs | 2 +- src/libserialize/hex.rs | 2 ++ src/libstd/collections/hash/map.rs | 3 +++ src/libstd/collections/hash/set.rs | 10 +++++++ src/libstd/collections/mod.rs | 2 ++ src/libstd/ffi/c_str.rs | 6 +++++ src/libstd/fs/mod.rs | 2 ++ src/libstd/lib.rs | 1 + src/libstd/macros.rs | 1 + src/libstd/net/addr.rs | 1 + src/libstd/net/mod.rs | 1 + src/libstd/net/tcp.rs | 2 ++ src/libstd/net/udp.rs | 1 + src/libstd/num/f32.rs | 43 ++++++++++++++++++++++++++++++ src/libstd/num/f64.rs | 41 +++++++++++++++++++++++++++++ src/libstd/num/mod.rs | 41 +++++++++++++++++++++++++++++ src/libstd/old_io/buffered.rs | 3 +++ src/libstd/old_io/comm_adapters.rs | 2 ++ src/libstd/old_io/fs.rs | 12 +++++++++ src/libstd/old_io/mem.rs | 4 +++ src/libstd/old_io/mod.rs | 14 ++++++++++ src/libstd/old_io/net/ip.rs | 1 + src/libstd/old_io/net/pipe.rs | 2 ++ src/libstd/old_io/net/tcp.rs | 5 ++++ src/libstd/old_io/net/udp.rs | 1 + src/libstd/old_io/pipe.rs | 1 + src/libstd/old_io/process.rs | 5 ++++ src/libstd/old_io/stdio.rs | 2 ++ src/libstd/old_io/tempfile.rs | 1 + src/libstd/old_io/timer.rs | 6 +++++ src/libstd/old_path/mod.rs | 32 +++++++++++++++++++++++ src/libstd/old_path/windows.rs | 2 ++ src/libstd/os.rs | 13 +++++++++ src/libstd/rand/mod.rs | 7 +++++ src/libstd/rand/reader.rs | 1 + src/libstd/sync/condvar.rs | 1 + src/libstd/sync/future.rs | 1 + src/libstd/sync/mpsc/mod.rs | 2 ++ src/libstd/sync/mpsc/select.rs | 2 ++ src/libstd/sync/mutex.rs | 2 ++ src/libstd/sync/rwlock.rs | 1 + src/libstd/sync/semaphore.rs | 1 + src/libstd/sync/task_pool.rs | 1 + src/libstd/thread_local/scoped.rs | 3 +++ src/libterm/lib.rs | 1 + src/libunicode/char.rs | 4 +++ src/libunicode/lib.rs | 1 + src/libunicode/u_str.rs | 25 +++++++++++------- src/test/pretty/default-trait-impl.rs | 2 +- 107 files changed, 649 insertions(+), 22 deletions(-) (limited to 'src/libstd') diff --git a/src/doc/reference.md b/src/doc/reference.md index 415ec4e4fbf..07df3bdad34 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -816,8 +816,7 @@ may optionally begin with any number of `attributes` that apply to the containing module. Attributes on the anonymous crate module define important metadata that influences the behavior of the compiler. -```{.rust} -# #![allow(unused_attribute)] +```no_run // Crate name #![crate_name = "projx"] @@ -1020,6 +1019,7 @@ Use declarations support a number of convenient shortcuts: An example of `use` declarations: ``` +# #![feature(core)] use std::iter::range_step; use std::option::Option::{Some, None}; use std::collections::hash_map::{self, HashMap}; @@ -1080,6 +1080,7 @@ declarations. An example of what will and will not work for `use` items: ``` +# #![feature(core)] # #![allow(unused_imports)] use foo::core::iter; // good: foo is at the root of the crate use foo::baz::foobaz; // good: foo is at the root of the crate @@ -1781,6 +1782,7 @@ functions, with the exception that they may not have a body and are instead terminated by a semicolon. ``` +# #![feature(libc)] extern crate libc; use libc::{c_char, FILE}; diff --git a/src/doc/trpl/concurrency.md b/src/doc/trpl/concurrency.md index 4a16db63950..9c86d2d3b84 100644 --- a/src/doc/trpl/concurrency.md +++ b/src/doc/trpl/concurrency.md @@ -88,6 +88,7 @@ When `guard` goes out of scope, it will block execution until the thread is finished. If we didn't want this behaviour, we could use `thread::spawn()`: ``` +# #![feature(old_io, std_misc)] use std::thread; use std::old_io::timer; use std::time::Duration; @@ -146,6 +147,7 @@ As an example, here is a Rust program that would have a data race in many languages. It will not compile: ```ignore +# #![feature(old_io, std_misc)] use std::thread; use std::old_io::timer; use std::time::Duration; @@ -185,6 +187,7 @@ only one person at a time can mutate what's inside. For that, we can use the but for a different reason: ```ignore +# #![feature(old_io, std_misc)] use std::thread; use std::old_io::timer; use std::time::Duration; @@ -229,6 +232,7 @@ guard across thread boundaries, which gives us our error. We can use `Arc` to fix this. Here's the working version: ``` +# #![feature(old_io, std_misc)] use std::sync::{Arc, Mutex}; use std::thread; use std::old_io::timer; @@ -254,6 +258,7 @@ handle is then moved into the new thread. Let's examine the body of the thread more closely: ``` +# #![feature(old_io, std_misc)] # use std::sync::{Arc, Mutex}; # use std::thread; # use std::old_io::timer; diff --git a/src/doc/trpl/ffi.md b/src/doc/trpl/ffi.md index 018f35337f3..695279e2d5b 100644 --- a/src/doc/trpl/ffi.md +++ b/src/doc/trpl/ffi.md @@ -12,6 +12,7 @@ The following is a minimal example of calling a foreign function which will compile if snappy is installed: ```no_run +# #![feature(libc)] extern crate libc; use libc::size_t; @@ -45,6 +46,7 @@ keeping the binding correct at runtime. The `extern` block can be extended to cover the entire snappy API: ```no_run +# #![feature(libc)] extern crate libc; use libc::{c_int, size_t}; @@ -80,6 +82,7 @@ length is number of elements currently contained, and the capacity is the total the allocated memory. The length is less than or equal to the capacity. ``` +# #![feature(libc)] # extern crate libc; # use libc::{c_int, size_t}; # unsafe fn snappy_validate_compressed_buffer(_: *const u8, _: size_t) -> c_int { 0 } @@ -104,6 +107,7 @@ required capacity to hold the compressed output. The vector can then be passed t the true length after compression for setting the length. ``` +# #![feature(libc)] # extern crate libc; # use libc::{size_t, c_int}; # unsafe fn snappy_compress(a: *const u8, b: size_t, c: *mut u8, @@ -130,6 +134,7 @@ Decompression is similar, because snappy stores the uncompressed size as part of format and `snappy_uncompressed_length` will retrieve the exact buffer size required. ``` +# #![feature(libc)] # extern crate libc; # use libc::{size_t, c_int}; # unsafe fn snappy_uncompress(compressed: *const u8, @@ -408,6 +413,7 @@ global state. In order to access these variables, you declare them in `extern` blocks with the `static` keyword: ```no_run +# #![feature(libc)] extern crate libc; #[link(name = "readline")] @@ -426,6 +432,7 @@ interface. To do this, statics can be declared with `mut` so we can mutate them. ```no_run +# #![feature(libc)] extern crate libc; use std::ffi::CString; @@ -458,6 +465,7 @@ calling foreign functions. Some foreign functions, most notably the Windows API, conventions. Rust provides a way to tell the compiler which convention to use: ``` +# #![feature(libc)] extern crate libc; #[cfg(all(target_os = "win32", target_arch = "x86"))] diff --git a/src/doc/trpl/iterators.md b/src/doc/trpl/iterators.md index 33dc1ba07ca..8d7b1c3bd83 100644 --- a/src/doc/trpl/iterators.md +++ b/src/doc/trpl/iterators.md @@ -246,6 +246,7 @@ These two basic iterators should serve you well. There are some more advanced iterators, including ones that are infinite. Like `count`: ```rust +# #![feature(core)] std::iter::count(1, 5); ``` @@ -294,6 +295,7 @@ has no side effect on the original iterator. Let's try it out with our infinite iterator from before, `count()`: ```rust +# #![feature(core)] for i in std::iter::count(1, 5).take(5) { println!("{}", i); } diff --git a/src/doc/trpl/method-syntax.md b/src/doc/trpl/method-syntax.md index 0ca42c3b12d..8cb16f7ab33 100644 --- a/src/doc/trpl/method-syntax.md +++ b/src/doc/trpl/method-syntax.md @@ -23,6 +23,7 @@ the ability to use this *method call syntax* via the `impl` keyword. Here's how it works: ```{rust} +# #![feature(core)] struct Circle { x: f64, y: f64, @@ -87,6 +88,7 @@ original example, `foo.bar().baz()`? This is called 'method chaining', and we can do it by returning `self`. ``` +# #![feature(core)] struct Circle { x: f64, y: f64, @@ -164,6 +166,7 @@ have method overloading, named arguments, or variable arguments. We employ the builder pattern instead. It looks like this: ``` +# #![feature(core)] struct Circle { x: f64, y: f64, diff --git a/src/doc/trpl/more-strings.md b/src/doc/trpl/more-strings.md index 6567cd448f9..4b2281badd7 100644 --- a/src/doc/trpl/more-strings.md +++ b/src/doc/trpl/more-strings.md @@ -148,6 +148,7 @@ Rust provides iterators for each of these situations: Usually, the `graphemes()` method on `&str` is what you want: ``` +# #![feature(unicode)] let s = "u͔n͈̰̎i̙̮͚̦c͚̉o̼̩̰͗d͔̆̓ͥé"; for l in s.graphemes(true) { diff --git a/src/doc/trpl/standard-input.md b/src/doc/trpl/standard-input.md index 794b1df7563..0ef286ac069 100644 --- a/src/doc/trpl/standard-input.md +++ b/src/doc/trpl/standard-input.md @@ -5,7 +5,7 @@ we haven't seen before. Here's a simple program that reads some input, and then prints it back out: ```{rust,ignore} -fn main() { +corefn main() { println!("Type something!"); let input = std::old_io::stdin().read_line().ok().expect("Failed to read line"); @@ -28,6 +28,7 @@ Since writing the fully qualified name all the time is annoying, we can use the `use` statement to import it in: ```{rust} +# #![feature(old_io)] use std::old_io::stdin; stdin(); @@ -37,6 +38,7 @@ However, it's considered better practice to not import individual functions, but to import the module, and only use one level of qualification: ```{rust} +# #![feature(old_io)] use std::old_io; old_io::stdin(); diff --git a/src/doc/trpl/testing.md b/src/doc/trpl/testing.md index 72e9ec9f750..8fb08e1c6cf 100644 --- a/src/doc/trpl/testing.md +++ b/src/doc/trpl/testing.md @@ -546,6 +546,8 @@ is an opaque "black box" to the optimizer and so forces it to consider any argument as used. ```rust +# #![feature(test)] + extern crate test; # fn main() { diff --git a/src/doc/trpl/traits.md b/src/doc/trpl/traits.md index 676f1cc425a..fe26fc5e1eb 100644 --- a/src/doc/trpl/traits.md +++ b/src/doc/trpl/traits.md @@ -4,6 +4,7 @@ Do you remember the `impl` keyword, used to call a function with method syntax? ```{rust} +# #![feature(core)] struct Circle { x: f64, y: f64, @@ -21,6 +22,7 @@ Traits are similar, except that we define a trait with just the method signature, then implement the trait for that struct. Like this: ```{rust} +# #![feature(core)] struct Circle { x: f64, y: f64, @@ -84,6 +86,7 @@ which implements `HasArea` will have an `.area()` method. Here's an extended example of how this works: ```{rust} +# #![feature(core)] trait HasArea { fn area(&self) -> f64; } @@ -225,6 +228,7 @@ If we add a `use` line right above `main` and make the right things public, everything is fine: ```{rust} +# #![feature(core)] use shapes::HasArea; mod shapes { @@ -408,6 +412,7 @@ but instead, we found a floating-point variable. We need a different bound. `Flo to the rescue: ``` +# #![feature(std_misc)] use std::num::Float; fn inverse(x: T) -> Result { @@ -423,6 +428,7 @@ from the `Float` trait. Both `f32` and `f64` implement `Float`, so our function works just fine: ``` +# #![feature(std_misc)] # use std::num::Float; # fn inverse(x: T) -> Result { # if x == Float::zero() { return Err("x cannot be zero!".to_string()) } diff --git a/src/doc/trpl/unsafe.md b/src/doc/trpl/unsafe.md index 11f0b8e1ddb..2116976d55a 100644 --- a/src/doc/trpl/unsafe.md +++ b/src/doc/trpl/unsafe.md @@ -187,6 +187,7 @@ As an example, we give a reimplementation of owned boxes by wrapping reimplementation is as safe as the `Box` type. ``` +# #![feature(libc)] #![feature(unsafe_destructor)] extern crate libc; @@ -443,6 +444,7 @@ The function marked `#[start]` is passed the command line parameters in the same format as C: ``` +# #![feature(libc)] #![feature(lang_items, start, no_std)] #![no_std] @@ -470,6 +472,7 @@ correct ABI and the correct name, which requires overriding the compiler's name mangling too: ```ignore +# #![feature(libc)] #![feature(no_std)] #![no_std] #![no_main] @@ -526,6 +529,7 @@ As an example, here is a program that will calculate the dot product of two vectors provided from C, using idiomatic Rust practices. ``` +# #![feature(libc, core)] #![feature(lang_items, start, no_std)] #![no_std] @@ -650,6 +654,7 @@ and one for deallocation. A freestanding program that uses the `Box` sugar for dynamic allocations via `malloc` and `free`: ``` +# #![feature(libc)] #![feature(lang_items, box_syntax, start, no_std)] #![no_std] diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 8528be2860c..97d3f78f67c 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -95,6 +95,7 @@ use heap::deallocate; /// task. /// /// ``` +/// # #![feature(alloc, core)] /// use std::sync::Arc; /// use std::thread; /// @@ -185,6 +186,7 @@ impl Arc { /// # Examples /// /// ``` + /// # #![feature(alloc)] /// use std::sync::Arc; /// /// let five = Arc::new(5); @@ -246,6 +248,7 @@ impl Clone for Arc { /// # Examples /// /// ``` + /// # #![feature(alloc)] /// use std::sync::Arc; /// /// let five = Arc::new(5); @@ -289,6 +292,7 @@ impl Arc { /// # Examples /// /// ``` + /// # #![feature(alloc)] /// use std::sync::Arc; /// /// let mut five = Arc::new(5); @@ -324,6 +328,7 @@ impl Drop for Arc { /// # Examples /// /// ``` + /// # #![feature(alloc)] /// use std::sync::Arc; /// /// { @@ -387,6 +392,7 @@ impl Weak { /// # Examples /// /// ``` + /// # #![feature(alloc)] /// use std::sync::Arc; /// /// let five = Arc::new(5); @@ -424,6 +430,7 @@ impl Clone for Weak { /// # Examples /// /// ``` + /// # #![feature(alloc)] /// use std::sync::Arc; /// /// let weak_five = Arc::new(5).downgrade(); @@ -448,6 +455,7 @@ impl Drop for Weak { /// # Examples /// /// ``` + /// # #![feature(alloc)] /// use std::sync::Arc; /// /// { diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 6bdfe2b1551..8b18fbf554a 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -65,6 +65,7 @@ use core::raw::TraitObject; /// The following two examples are equivalent: /// /// ``` +/// # #![feature(alloc)] /// #![feature(box_syntax)] /// use std::boxed::HEAP; /// @@ -135,6 +136,7 @@ impl Box { /// /// # Examples /// ``` +/// # #![feature(alloc)] /// use std::boxed; /// /// let seventeen = Box::new(17u32); @@ -178,6 +180,7 @@ impl Clone for Box { /// # Examples /// /// ``` + /// # #![feature(alloc, core)] /// let x = Box::new(5); /// let mut y = Box::new(10); /// diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 34c0686fe37..541de2d37fb 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -66,6 +66,7 @@ #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/")] +#![doc(test(no_crate_inject))] #![feature(no_std)] #![no_std] diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 855235e89c8..e4b09bba529 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -32,6 +32,7 @@ //! and have the `Owner` remain allocated as long as any `Gadget` points at it. //! //! ```rust +//! # #![feature(alloc, collections)] //! use std::rc::Rc; //! //! struct Owner { @@ -88,6 +89,7 @@ //! Read the `Cell` documentation for more details on interior mutability. //! //! ```rust +//! # #![feature(alloc)] //! use std::rc::Rc; //! use std::rc::Weak; //! use std::cell::RefCell; @@ -218,6 +220,7 @@ impl Rc { /// # Examples /// /// ``` + /// # #![feature(alloc)] /// use std::rc::Rc; /// /// let five = Rc::new(5); @@ -247,6 +250,7 @@ pub fn strong_count(this: &Rc) -> usize { this.strong() } /// # Examples /// /// ``` +/// # #![feature(alloc)] /// use std::rc; /// use std::rc::Rc; /// @@ -267,6 +271,7 @@ pub fn is_unique(rc: &Rc) -> bool { /// # Examples /// /// ``` +/// # #![feature(alloc)] /// use std::rc::{self, Rc}; /// /// let x = Rc::new(3); @@ -301,6 +306,7 @@ pub fn try_unwrap(rc: Rc) -> Result> { /// # Examples /// /// ``` +/// # #![feature(alloc)] /// use std::rc::{self, Rc}; /// /// let mut x = Rc::new(3); @@ -330,6 +336,7 @@ impl Rc { /// # Examples /// /// ``` + /// # #![feature(alloc)] /// use std::rc::Rc; /// /// let mut five = Rc::new(5); @@ -372,6 +379,7 @@ impl Drop for Rc { /// # Examples /// /// ``` + /// # #![feature(alloc)] /// use std::rc::Rc; /// /// { @@ -420,6 +428,7 @@ impl Clone for Rc { /// # Examples /// /// ``` + /// # #![feature(alloc)] /// use std::rc::Rc; /// /// let five = Rc::new(5); @@ -648,6 +657,7 @@ impl Weak { /// # Examples /// /// ``` + /// # #![feature(alloc)] /// use std::rc::Rc; /// /// let five = Rc::new(5); @@ -676,6 +686,7 @@ impl Drop for Weak { /// # Examples /// /// ``` + /// # #![feature(alloc)] /// use std::rc::Rc; /// /// { @@ -721,6 +732,7 @@ impl Clone for Weak { /// # Examples /// /// ``` + /// # #![feature(alloc)] /// use std::rc::Rc; /// /// let weak_five = Rc::new(5).downgrade(); diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 11c8656c994..6edee82dc30 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -216,6 +216,7 @@ impl BinaryHeap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BinaryHeap; /// let heap = BinaryHeap::from_vec(vec![9, 1, 2, 7, 3, 2]); /// ``` @@ -235,6 +236,7 @@ impl BinaryHeap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BinaryHeap; /// let heap = BinaryHeap::from_vec(vec![1, 2, 3, 4]); /// @@ -255,6 +257,7 @@ impl BinaryHeap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BinaryHeap; /// let heap = BinaryHeap::from_vec(vec![1, 2, 3, 4]); /// @@ -360,6 +363,7 @@ impl BinaryHeap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BinaryHeap; /// let mut heap = BinaryHeap::from_vec(vec![1, 3]); /// @@ -405,6 +409,7 @@ impl BinaryHeap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BinaryHeap; /// let mut heap = BinaryHeap::new(); /// heap.push(1); @@ -436,6 +441,7 @@ impl BinaryHeap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BinaryHeap; /// let mut heap = BinaryHeap::new(); /// @@ -461,6 +467,7 @@ impl BinaryHeap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BinaryHeap; /// let heap = BinaryHeap::from_vec(vec![1, 2, 3, 4, 5, 6, 7]); /// let vec = heap.into_vec(); @@ -478,6 +485,7 @@ impl BinaryHeap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BinaryHeap; /// /// let mut heap = BinaryHeap::from_vec(vec![1, 2, 4, 5, 7]); diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index 90fbe04d348..d83ff92bf3d 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -38,6 +38,7 @@ //! [sieve]: http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes //! //! ``` +//! # #![feature(collections, core)] //! use std::collections::{BitSet, BitVec}; //! use std::num::Float; //! use std::iter; @@ -134,6 +135,7 @@ static FALSE: bool = false; /// # Examples /// /// ``` +/// # #![feature(collections)] /// use std::collections::BitVec; /// /// let mut bv = BitVec::from_elem(10, false); @@ -250,6 +252,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// let mut bv = BitVec::new(); /// ``` @@ -264,6 +267,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// /// let mut bv = BitVec::from_elem(10, false); @@ -304,6 +308,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// /// let bv = BitVec::from_bytes(&[0b10100000, 0b00010010]); @@ -346,6 +351,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// /// let bv = BitVec::from_fn(5, |i| { i % 2 == 0 }); @@ -364,6 +370,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// /// let bv = BitVec::from_bytes(&[0b01100000]); @@ -396,6 +403,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// /// let mut bv = BitVec::from_elem(5, false); @@ -420,6 +428,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// /// let before = 0b01100000; @@ -440,6 +449,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// /// let before = 0b01100000; @@ -468,6 +478,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// /// let a = 0b01100100; @@ -498,6 +509,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// /// let a = 0b01100100; @@ -528,6 +540,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// /// let a = 0b01100100; @@ -557,6 +570,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// /// let mut bv = BitVec::from_elem(5, true); @@ -581,6 +595,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// /// let bv = BitVec::from_bytes(&[0b01110100, 0b10010010]); @@ -597,6 +612,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// /// let mut bv = BitVec::from_elem(10, false); @@ -614,6 +630,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// /// let mut bv = BitVec::from_elem(10, false); @@ -635,6 +652,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// /// let mut bv = BitVec::from_elem(3, true); @@ -682,6 +700,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// /// let bv = BitVec::from_bytes(&[0b10100000]); @@ -702,6 +721,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// /// let mut bv = BitVec::from_bytes(&[0b01001011]); @@ -728,6 +748,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// /// let mut bv = BitVec::from_elem(3, false); @@ -758,6 +779,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// /// let mut bv = BitVec::from_elem(3, false); @@ -780,6 +802,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// /// let mut bv = BitVec::new(); @@ -801,6 +824,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// /// let mut bv = BitVec::from_bytes(&[0b01001011]); @@ -851,6 +875,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// /// let mut bv = BitVec::from_bytes(&[0b01001001]); @@ -881,6 +906,7 @@ impl BitVec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitVec; /// /// let mut bv = BitVec::new(); @@ -1091,6 +1117,7 @@ impl<'a> IntoIterator for &'a BitVec { /// # Examples /// /// ``` +/// # #![feature(collections)] /// use std::collections::{BitSet, BitVec}; /// /// // It's a regular set @@ -1187,6 +1214,7 @@ impl BitSet { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitSet; /// /// let mut s = BitSet::new(); @@ -1203,6 +1231,7 @@ impl BitSet { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitSet; /// /// let mut s = BitSet::with_capacity(100); @@ -1220,6 +1249,7 @@ impl BitSet { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::{BitVec, BitSet}; /// /// let bv = BitVec::from_bytes(&[0b01100000]); @@ -1249,6 +1279,7 @@ impl BitSet { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitSet; /// /// let mut s = BitSet::with_capacity(100); @@ -1270,6 +1301,7 @@ impl BitSet { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitSet; /// /// let mut s = BitSet::new(); @@ -1296,6 +1328,7 @@ impl BitSet { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitSet; /// /// let mut s = BitSet::new(); @@ -1316,6 +1349,7 @@ impl BitSet { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitSet; /// /// let mut s = BitSet::new(); @@ -1336,6 +1370,7 @@ impl BitSet { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitSet; /// /// let mut s = BitSet::new(); @@ -1382,6 +1417,7 @@ impl BitSet { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BitSet; /// /// let mut s = BitSet::new(); @@ -1414,6 +1450,7 @@ impl BitSet { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::{BitVec, BitSet}; /// /// let s = BitSet::from_bit_vec(BitVec::from_bytes(&[0b01001010])); @@ -1435,6 +1472,7 @@ impl BitSet { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::{BitVec, BitSet}; /// /// let a = BitSet::from_bit_vec(BitVec::from_bytes(&[0b01101000])); @@ -1465,6 +1503,7 @@ impl BitSet { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::{BitVec, BitSet}; /// /// let a = BitSet::from_bit_vec(BitVec::from_bytes(&[0b01101000])); @@ -1495,6 +1534,7 @@ impl BitSet { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::{BitSet, BitVec}; /// /// let a = BitSet::from_bit_vec(BitVec::from_bytes(&[0b01101000])); @@ -1533,6 +1573,7 @@ impl BitSet { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::{BitSet, BitVec}; /// /// let a = BitSet::from_bit_vec(BitVec::from_bytes(&[0b01101000])); @@ -1562,6 +1603,7 @@ impl BitSet { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::{BitSet, BitVec}; /// /// let a = 0b01101000; @@ -1585,6 +1627,7 @@ impl BitSet { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::{BitSet, BitVec}; /// /// let a = 0b01101000; @@ -1609,6 +1652,7 @@ impl BitSet { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::{BitSet, BitVec}; /// /// let a = 0b01101000; @@ -1641,6 +1685,7 @@ impl BitSet { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::{BitSet, BitVec}; /// /// let a = 0b01101000; diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index a9e1ce8d7ce..e69ca8c9a09 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -1269,6 +1269,7 @@ impl BTreeMap { /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::collections::BTreeMap; /// /// let mut a = BTreeMap::new(); @@ -1291,6 +1292,7 @@ impl BTreeMap { /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::collections::BTreeMap; /// /// let mut a = BTreeMap::new(); @@ -1478,6 +1480,7 @@ impl BTreeMap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BTreeMap; /// use std::collections::Bound::{Included, Unbounded}; /// @@ -1504,6 +1507,7 @@ impl BTreeMap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BTreeMap; /// use std::collections::Bound::{Included, Excluded}; /// @@ -1529,6 +1533,7 @@ impl BTreeMap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BTreeMap; /// use std::collections::btree_map::Entry; /// diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index 5616d36ce0b..bce0450852f 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -116,6 +116,7 @@ impl BTreeSet { /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::collections::BTreeSet; /// /// let set: BTreeSet = [1, 2, 3, 4].iter().cloned().collect(); @@ -137,6 +138,7 @@ impl BTreeSet { /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::collections::BTreeSet; /// /// let set: BTreeSet = [1, 2, 3, 4].iter().cloned().collect(); @@ -162,6 +164,7 @@ impl BTreeSet { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::BTreeSet; /// use std::collections::Bound::{Included, Unbounded}; /// @@ -190,6 +193,7 @@ impl BTreeSet { /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::collections::BTreeSet; /// /// let mut a = BTreeSet::new(); @@ -213,6 +217,7 @@ impl BTreeSet { /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::collections::BTreeSet; /// /// let mut a = BTreeSet::new(); @@ -237,6 +242,7 @@ impl BTreeSet { /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::collections::BTreeSet; /// /// let mut a = BTreeSet::new(); @@ -261,6 +267,7 @@ impl BTreeSet { /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::collections::BTreeSet; /// /// let mut a = BTreeSet::new(); @@ -333,6 +340,7 @@ impl BTreeSet { /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::collections::BTreeSet; /// /// let set: BTreeSet<_> = [1, 2, 3].iter().cloned().collect(); @@ -350,6 +358,7 @@ impl BTreeSet { /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::collections::BTreeSet; /// /// let a: BTreeSet<_> = [1, 2, 3].iter().cloned().collect(); @@ -371,6 +380,7 @@ impl BTreeSet { /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::collections::BTreeSet; /// /// let sup: BTreeSet<_> = [1, 2, 3].iter().cloned().collect(); @@ -413,6 +423,7 @@ impl BTreeSet { /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::collections::BTreeSet; /// /// let sub: BTreeSet<_> = [1, 2].iter().cloned().collect(); diff --git a/src/libcollections/fmt.rs b/src/libcollections/fmt.rs index 3af7485b237..b106f4adbc7 100644 --- a/src/libcollections/fmt.rs +++ b/src/libcollections/fmt.rs @@ -174,6 +174,7 @@ //! like: //! //! ``` +//! # #![feature(core, std_misc)] //! use std::fmt; //! use std::f64; //! use std::num::Float; @@ -261,6 +262,7 @@ //! Example usage is: //! //! ``` +//! # #![feature(old_io)] //! # #![allow(unused_must_use)] //! use std::io::Write; //! let mut w = Vec::new(); @@ -288,6 +290,7 @@ //! off, some example usage is: //! //! ``` +//! # #![feature(old_io)] //! use std::fmt; //! use std::io::{self, Write}; //! diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index cf9f6a39a55..fa8413ff170 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -22,6 +22,7 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/", html_playground_url = "http://play.rust-lang.org/")] +#![doc(test(no_crate_inject))] #![feature(alloc)] #![feature(box_syntax)] diff --git a/src/libcollections/linked_list.rs b/src/libcollections/linked_list.rs index 9e0a6d04381..ae00c820a1d 100644 --- a/src/libcollections/linked_list.rs +++ b/src/libcollections/linked_list.rs @@ -235,6 +235,7 @@ impl LinkedList { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::LinkedList; /// /// let mut a = LinkedList::new(); @@ -483,6 +484,7 @@ impl LinkedList { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::LinkedList; /// /// let mut dl = LinkedList::new(); @@ -530,6 +532,7 @@ impl LinkedList { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::LinkedList; /// /// let mut d = LinkedList::new(); @@ -548,6 +551,7 @@ impl LinkedList { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::LinkedList; /// /// let mut d = LinkedList::new(); @@ -573,6 +577,7 @@ impl LinkedList { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::LinkedList; /// /// let mut d = LinkedList::new(); @@ -765,6 +770,7 @@ impl<'a, A> IterMut<'a, A> { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::LinkedList; /// /// let mut list: LinkedList<_> = vec![1, 3, 4].into_iter().collect(); @@ -792,6 +798,7 @@ impl<'a, A> IterMut<'a, A> { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::LinkedList; /// /// let mut list: LinkedList<_> = vec![1, 2, 3].into_iter().collect(); diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 45864153dd7..9b9417d2be7 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -14,6 +14,7 @@ //! Slices are a view into a block of memory represented as a pointer and a length. //! //! ```rust +//! # #![feature(core)] //! // slicing a Vec //! let vec = vec!(1, 2, 3); //! let int_slice = vec.as_slice(); @@ -270,6 +271,7 @@ impl [T] { /// # Examples /// /// ```rust + /// # #![feature(collections)] /// let mut a = [1, 2, 3, 4, 5]; /// let b = vec![6, 7, 8]; /// let num_moved = a.move_from(b, 0, 3); @@ -560,6 +562,7 @@ impl [T] { /// found; the fourth could match any position in `[1,4]`. /// /// ```rust + /// # #![feature(core)] /// let s = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; /// let s = s.as_slice(); /// @@ -842,6 +845,7 @@ impl [T] { /// # Examples /// /// ```rust + /// # #![feature(collections)] /// let v = [1, 2, 3]; /// let mut perms = v.permutations(); /// @@ -853,6 +857,7 @@ impl [T] { /// Iterating through permutations one by one. /// /// ```rust + /// # #![feature(collections)] /// let v = [1, 2, 3]; /// let mut perms = v.permutations(); /// @@ -874,6 +879,7 @@ impl [T] { /// # Example /// /// ```rust + /// # #![feature(collections)] /// let mut dst = [0, 0, 0]; /// let src = [1, 2]; /// @@ -921,6 +927,7 @@ impl [T] { /// found; the fourth could match any position in `[1,4]`. /// /// ```rust + /// # #![feature(core)] /// let s = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; /// let s = s.as_slice(); /// @@ -950,6 +957,7 @@ impl [T] { /// # Example /// /// ```rust + /// # #![feature(collections)] /// let v: &mut [_] = &mut [0, 1, 2]; /// v.next_permutation(); /// let b: &mut [_] = &mut [0, 2, 1]; @@ -972,6 +980,7 @@ impl [T] { /// # Example /// /// ```rust + /// # #![feature(collections)] /// let v: &mut [_] = &mut [1, 0, 2]; /// v.prev_permutation(); /// let b: &mut [_] = &mut [0, 2, 1]; diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 3a289e4ef37..494dd009ea9 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -548,6 +548,7 @@ impl str { /// # Examples /// /// ``` + /// # #![feature(collections)] /// assert!("hello".contains_char('e')); /// /// assert!(!"hello".contains_char('z')); @@ -739,6 +740,7 @@ impl str { /// # Examples /// /// ``` + /// # #![feature(collections)] /// let v: Vec<(usize, usize)> = "abcXXXabcYYYabc".match_indices("abc").collect(); /// assert_eq!(v, [(0,3), (6,9), (12,15)]); /// @@ -761,6 +763,7 @@ impl str { /// # Examples /// /// ``` + /// # #![feature(collections)] /// let v: Vec<&str> = "abcXXXabcYYYabc".split_str("abc").collect(); /// assert_eq!(v, ["", "XXX", "YYY", ""]); /// @@ -869,6 +872,7 @@ impl str { /// # Examples /// /// ``` + /// # #![feature(collections)] /// let s = "Löwe 老虎 Léopard"; /// /// assert_eq!(s.slice_chars(0, 4), "Löwe"); @@ -1019,6 +1023,7 @@ impl str { /// # Examples /// /// ``` + /// # #![feature(str_char)] /// let s = "Löwe 老虎 Léopard"; /// assert!(s.is_char_boundary(0)); /// // start of `老` @@ -1055,6 +1060,7 @@ impl str { /// done by `.chars()` or `.char_indices()`. /// /// ``` + /// # #![feature(str_char, core)] /// use std::str::CharRange; /// /// let s = "中华Việt Nam"; @@ -1105,6 +1111,7 @@ impl str { /// done by `.chars().rev()` or `.char_indices()`. /// /// ``` + /// # #![feature(str_char, core)] /// use std::str::CharRange; /// /// let s = "中华Việt Nam"; @@ -1148,6 +1155,7 @@ impl str { /// # Examples /// /// ``` + /// # #![feature(str_char)] /// let s = "abπc"; /// assert_eq!(s.char_at(1), 'b'); /// assert_eq!(s.char_at(2), 'π'); @@ -1172,6 +1180,7 @@ impl str { /// # Examples /// /// ``` + /// # #![feature(str_char)] /// let s = "abπc"; /// assert_eq!(s.char_at_reverse(1), 'a'); /// assert_eq!(s.char_at_reverse(2), 'b'); @@ -1286,6 +1295,7 @@ impl str { /// # Examples /// /// ``` + /// # #![feature(collections)] /// let s = "Löwe 老虎 Léopard"; /// /// assert_eq!(s.find_str("老虎 L"), Some(6)); @@ -1307,6 +1317,7 @@ impl str { /// # Examples /// /// ``` + /// # #![feature(str_char)] /// let s = "Löwe 老虎 Léopard"; /// let (c, s1) = s.slice_shift_char().unwrap(); /// @@ -1335,6 +1346,7 @@ impl str { /// # Examples /// /// ``` + /// # #![feature(collections)] /// let string = "a\nb\nc"; /// let lines: Vec<&str> = string.lines().collect(); /// @@ -1434,6 +1446,7 @@ impl str { /// # Examples /// /// ``` + /// # #![feature(unicode, core)] /// let gr1 = "a\u{310}e\u{301}o\u{308}\u{332}".graphemes(true).collect::>(); /// let b: &[_] = &["a\u{310}", "e\u{301}", "o\u{308}\u{332}"]; /// @@ -1456,6 +1469,7 @@ impl str { /// # Examples /// /// ``` + /// # #![feature(unicode, core)] /// let gr_inds = "a̐éö̲\r\n".grapheme_indices(true).collect::>(); /// let b: &[_] = &[(0, "a̐"), (3, "é"), (6, "ö̲"), (11, "\r\n")]; /// @@ -1475,6 +1489,7 @@ impl str { /// # Examples /// /// ``` + /// # #![feature(str_words)] /// let some_words = " Mary had\ta little \n\t lamb"; /// let v: Vec<&str> = some_words.words().collect(); /// diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index cd6f27bf65f..abc67aa6136 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -90,6 +90,7 @@ impl String { /// # Examples /// /// ``` + /// # #![feature(collections, core)] /// let s = String::from_str("hello"); /// assert_eq!(s.as_slice(), "hello"); /// ``` @@ -122,6 +123,7 @@ impl String { /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::str::Utf8Error; /// /// let hello_vec = vec![104, 101, 108, 108, 111]; @@ -350,6 +352,7 @@ impl String { /// # Examples /// /// ``` + /// # #![feature(collections)] /// let s = String::from_str("hello"); /// let bytes = s.into_bytes(); /// assert_eq!(bytes, [104, 101, 108, 108, 111]); @@ -365,6 +368,7 @@ impl String { /// # Examples /// /// ``` + /// # #![feature(collections)] /// let mut s = String::from_str("foo"); /// s.push_str("bar"); /// assert_eq!(s, "foobar"); @@ -441,6 +445,7 @@ impl String { /// # Examples /// /// ``` + /// # #![feature(collections)] /// let mut s = String::from_str("foo"); /// s.reserve(100); /// assert!(s.capacity() >= 100); @@ -458,6 +463,7 @@ impl String { /// # Examples /// /// ``` + /// # #![feature(collections)] /// let mut s = String::from_str("abc"); /// s.push('1'); /// s.push('2'); @@ -493,6 +499,7 @@ impl String { /// # Examples /// /// ``` + /// # #![feature(collections)] /// let s = String::from_str("hello"); /// let b: &[_] = &[104, 101, 108, 108, 111]; /// assert_eq!(s.as_bytes(), b); @@ -513,6 +520,7 @@ impl String { /// # Examples /// /// ``` + /// # #![feature(collections)] /// let mut s = String::from_str("hello"); /// s.truncate(2); /// assert_eq!(s, "he"); @@ -530,6 +538,7 @@ impl String { /// # Examples /// /// ``` + /// # #![feature(collections)] /// let mut s = String::from_str("foo"); /// assert_eq!(s.pop(), Some('o')); /// assert_eq!(s.pop(), Some('o')); @@ -567,6 +576,7 @@ impl String { /// # Examples /// /// ``` + /// # #![feature(collections)] /// let mut s = String::from_str("foo"); /// assert_eq!(s.remove(0), 'f'); /// assert_eq!(s.remove(1), 'o'); @@ -629,6 +639,7 @@ impl String { /// # Examples /// /// ``` + /// # #![feature(collections)] /// let mut s = String::from_str("hello"); /// unsafe { /// let vec = s.as_mut_vec(); @@ -930,6 +941,7 @@ impl<'a> Deref for DerefString<'a> { /// # Examples /// /// ``` +/// # #![feature(collections)] /// use std::string::as_string; /// /// fn string_consumer(s: String) { diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index b0e8dc7d0b6..473442e531b 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -73,6 +73,7 @@ use borrow::{Cow, IntoCow}; /// # Examples /// /// ``` +/// # #![feature(collections)] /// let mut vec = Vec::new(); /// vec.push(1); /// vec.push(2); @@ -345,6 +346,7 @@ impl Vec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// let mut vec = Vec::with_capacity(10); /// vec.push_all(&[1, 2, 3]); /// assert_eq!(vec.capacity(), 10); @@ -400,6 +402,7 @@ impl Vec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// let mut vec = vec![1, 2, 3, 4]; /// vec.truncate(2); /// assert_eq!(vec, [1, 2]); @@ -565,6 +568,7 @@ impl Vec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// let mut v = vec![1, 2, 3]; /// assert_eq!(v.remove(1), 2); /// assert_eq!(v, [1, 3]); @@ -696,6 +700,7 @@ impl Vec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// let mut vec = vec![1, 2, 3]; /// let mut vec2 = vec![4, 5, 6]; /// vec.append(&mut vec2); @@ -732,6 +737,7 @@ impl Vec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// let mut v = vec!["a".to_string(), "b".to_string()]; /// for s in v.drain() { /// // s has type String, not &String @@ -813,6 +819,7 @@ impl Vec { /// # Examples /// /// ``` + /// # #![feature(collections, core)] /// let v = vec![0, 1, 2]; /// let w = v.map_in_place(|i| i + 3); /// assert_eq!(w.as_slice(), [3, 4, 5].as_slice()); @@ -1015,6 +1022,7 @@ impl Vec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// let mut vec = vec![1,2,3]; /// let vec2 = vec.split_off(1); /// assert_eq!(vec, [1]); @@ -1053,6 +1061,7 @@ impl Vec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// let mut vec = vec!["hello"]; /// vec.resize(3, "world"); /// assert_eq!(vec, ["hello", "world", "world"]); @@ -1081,6 +1090,7 @@ impl Vec { /// # Examples /// /// ``` + /// # #![feature(collections)] /// let mut vec = vec![1]; /// vec.push_all(&[2, 3, 4]); /// assert_eq!(vec, [1, 2, 3, 4]); @@ -1554,6 +1564,7 @@ impl AsSlice for Vec { /// # Examples /// /// ``` + /// # #![feature(core)] /// fn foo(slice: &[i32]) {} /// /// let vec = vec![1, 2]; diff --git a/src/libcollections/vec_deque.rs b/src/libcollections/vec_deque.rs index 56ca74dab1f..d2570640038 100644 --- a/src/libcollections/vec_deque.rs +++ b/src/libcollections/vec_deque.rs @@ -257,6 +257,7 @@ impl VecDeque { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecDeque; /// /// let mut buf = VecDeque::new(); @@ -284,6 +285,7 @@ impl VecDeque { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecDeque; /// /// let buf: VecDeque = VecDeque::with_capacity(10); @@ -307,6 +309,7 @@ impl VecDeque { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecDeque; /// /// let mut buf: VecDeque = vec![1].into_iter().collect(); @@ -328,6 +331,7 @@ impl VecDeque { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecDeque; /// /// let mut buf: VecDeque = vec![1].into_iter().collect(); @@ -403,6 +407,7 @@ impl VecDeque { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecDeque; /// /// let mut buf = VecDeque::with_capacity(15); @@ -489,6 +494,7 @@ impl VecDeque { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecDeque; /// /// let mut buf = VecDeque::new(); @@ -512,6 +518,7 @@ impl VecDeque { /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::collections::VecDeque; /// /// let mut buf = VecDeque::new(); @@ -535,6 +542,7 @@ impl VecDeque { /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::collections::VecDeque; /// /// let mut buf = VecDeque::new(); @@ -644,6 +652,7 @@ impl VecDeque { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecDeque; /// /// let mut v = VecDeque::new(); @@ -882,6 +891,7 @@ impl VecDeque { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecDeque; /// /// let mut buf = VecDeque::new(); @@ -915,6 +925,7 @@ impl VecDeque { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecDeque; /// /// let mut buf = VecDeque::new(); @@ -948,6 +959,7 @@ impl VecDeque { /// /// # Examples /// ``` + /// # #![feature(collections)] /// use std::collections::VecDeque; /// /// let mut buf = VecDeque::new(); @@ -1321,6 +1333,7 @@ impl VecDeque { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecDeque; /// /// let mut buf: VecDeque<_> = vec![1,2,3].into_iter().collect(); @@ -1383,6 +1396,7 @@ impl VecDeque { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecDeque; /// /// let mut buf: VecDeque<_> = vec![1, 2, 3].into_iter().collect(); @@ -1407,6 +1421,7 @@ impl VecDeque { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecDeque; /// /// let mut buf = VecDeque::new(); diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index 6e67d876327..84fb06809b9 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -34,6 +34,7 @@ use vec::Vec; /// # Examples /// /// ``` +/// # #![feature(collections)] /// use std::collections::VecMap; /// /// let mut months = VecMap::new(); @@ -132,6 +133,7 @@ impl VecMap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecMap; /// let mut map: VecMap<&str> = VecMap::new(); /// ``` @@ -144,6 +146,7 @@ impl VecMap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecMap; /// let mut map: VecMap<&str> = VecMap::with_capacity(10); /// ``` @@ -158,6 +161,7 @@ impl VecMap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecMap; /// let map: VecMap = VecMap::with_capacity(10); /// assert!(map.capacity() >= 10); @@ -177,6 +181,7 @@ impl VecMap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecMap; /// let mut map: VecMap<&str> = VecMap::new(); /// map.reserve_len(10); @@ -201,6 +206,7 @@ impl VecMap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecMap; /// let mut map: VecMap<&str> = VecMap::new(); /// map.reserve_len_exact(10); @@ -240,6 +246,7 @@ impl VecMap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecMap; /// /// let mut map = VecMap::new(); @@ -268,6 +275,7 @@ impl VecMap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecMap; /// /// let mut map = VecMap::new(); @@ -299,6 +307,7 @@ impl VecMap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecMap; /// /// let mut map = VecMap::new(); @@ -325,6 +334,7 @@ impl VecMap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecMap; /// /// let mut a = VecMap::new(); @@ -360,6 +370,7 @@ impl VecMap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecMap; /// /// let mut a = VecMap::new(); @@ -416,6 +427,7 @@ impl VecMap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecMap; /// /// let mut map = VecMap::new(); @@ -443,6 +455,7 @@ impl VecMap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecMap; /// /// let mut a = VecMap::new(); @@ -460,6 +473,7 @@ impl VecMap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecMap; /// /// let mut a = VecMap::new(); @@ -477,6 +491,7 @@ impl VecMap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecMap; /// /// let mut a = VecMap::new(); @@ -492,6 +507,7 @@ impl VecMap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecMap; /// /// let mut map = VecMap::new(); @@ -516,6 +532,7 @@ impl VecMap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecMap; /// /// let mut map = VecMap::new(); @@ -534,6 +551,7 @@ impl VecMap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecMap; /// /// let mut map = VecMap::new(); @@ -562,6 +580,7 @@ impl VecMap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecMap; /// /// let mut map = VecMap::new(); @@ -587,6 +606,7 @@ impl VecMap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecMap; /// /// let mut map = VecMap::new(); @@ -608,6 +628,7 @@ impl VecMap { /// # Examples /// /// ``` + /// # #![feature(collections)] /// use std::collections::VecMap; /// use std::collections::vec_map::Entry; /// diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index e3a7f23851c..a9c5de23d94 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -220,6 +220,7 @@ impl Cell { /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::cell::Cell; /// /// let c = Cell::new(5); diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index b37bad5f754..9ab8ab8672d 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -19,7 +19,8 @@ //! could do the following: //! //! ``` -//! use core::num::SignedInt; +//! # #![feature(core)] +//! use std::num::SignedInt; //! //! struct FuzzyNum { //! num: i32, @@ -398,6 +399,7 @@ pub fn max(v1: T, v2: T) -> T { /// # Examples /// /// ``` +/// # #![feature(core)] /// use std::cmp; /// /// assert_eq!(Some(1), cmp::partial_min(1, 2)); @@ -407,6 +409,7 @@ pub fn max(v1: T, v2: T) -> T { /// When comparison is impossible: /// /// ``` +/// # #![feature(core)] /// use std::cmp; /// /// let result = cmp::partial_min(std::f64::NAN, 1.0); @@ -429,6 +432,7 @@ pub fn partial_min(v1: T, v2: T) -> Option { /// # Examples /// /// ``` +/// # #![feature(core)] /// use std::cmp; /// /// assert_eq!(Some(2), cmp::partial_max(1, 2)); @@ -438,6 +442,7 @@ pub fn partial_min(v1: T, v2: T) -> Option { /// When comparison is impossible: /// /// ``` +/// # #![feature(core)] /// use std::cmp; /// /// let result = cmp::partial_max(std::f64::NAN, 1.0); diff --git a/src/libcore/error.rs b/src/libcore/error.rs index 161f6c78921..8baf9744bbc 100644 --- a/src/libcore/error.rs +++ b/src/libcore/error.rs @@ -48,6 +48,7 @@ //! For example, //! //! ``` +//! # #![feature(os, old_io, old_path)] //! use std::error::FromError; //! use std::old_io::{File, IoError}; //! use std::os::{MemoryMap, MapError}; diff --git a/src/libcore/finally.rs b/src/libcore/finally.rs index 19cd34cdb09..93a7d2bb17b 100644 --- a/src/libcore/finally.rs +++ b/src/libcore/finally.rs @@ -19,6 +19,7 @@ //! # Examples //! //! ``` +//! # #![feature(core)] //! # #![feature(unboxed_closures)] //! //! use std::finally::Finally; @@ -70,6 +71,7 @@ impl Finally for F where F: FnMut() -> T { /// # Examples /// /// ``` +/// # #![feature(core)] /// use std::finally::try_finally; /// /// struct State<'a> { buffer: &'a mut [u8], len: usize } diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 741cf7b47fa..cf427c16588 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -624,6 +624,7 @@ impl<'a> Formatter<'a> { /// # Examples /// /// ```rust + /// # #![feature(debug_builders, core)] /// use std::fmt; /// /// struct Foo { @@ -655,6 +656,7 @@ impl<'a> Formatter<'a> { /// # Examples /// /// ```rust + /// # #![feature(debug_builders, core)] /// use std::fmt; /// /// struct Foo(i32, String); @@ -683,6 +685,7 @@ impl<'a> Formatter<'a> { /// # Examples /// /// ```rust + /// # #![feature(debug_builders, core)] /// use std::fmt; /// /// struct Foo(Vec); @@ -712,6 +715,7 @@ impl<'a> Formatter<'a> { /// # Examples /// /// ```rust + /// # #![feature(debug_builders, core)] /// use std::fmt; /// /// struct Foo(Vec<(String, i32)>); diff --git a/src/libcore/fmt/num.rs b/src/libcore/fmt/num.rs index fe22ee60da6..49da99b97cb 100644 --- a/src/libcore/fmt/num.rs +++ b/src/libcore/fmt/num.rs @@ -146,6 +146,7 @@ pub struct RadixFmt(T, R); /// # Examples /// /// ``` +/// # #![feature(core)] /// use std::fmt::radix; /// assert_eq!(format!("{}", radix(55, 36)), "1j".to_string()); /// ``` diff --git a/src/libcore/hash/mod.rs b/src/libcore/hash/mod.rs index fdc0020dfcd..3c5810fdf80 100644 --- a/src/libcore/hash/mod.rs +++ b/src/libcore/hash/mod.rs @@ -16,6 +16,7 @@ //! # Examples //! //! ```rust +//! # #![feature(hash)] //! use std::hash::{hash, Hash, SipHasher}; //! //! #[derive(Hash)] @@ -35,6 +36,7 @@ //! the trait `Hash`: //! //! ```rust +//! # #![feature(hash)] //! use std::hash::{hash, Hash, Hasher, SipHasher}; //! //! struct Person { diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 1462d07652d..9873ba476ac 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -262,6 +262,7 @@ extern "rust-intrinsic" { /// A safe swap function: /// /// ``` + /// # #![feature(core)] /// use std::mem; /// use std::ptr; /// @@ -301,6 +302,7 @@ extern "rust-intrinsic" { /// Efficiently create a Rust vector from an unsafe buffer: /// /// ``` + /// # #![feature(core)] /// use std::ptr; /// /// unsafe fn from_buf_raw(ptr: *const T, elts: uint) -> Vec { diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 4f8b1c21ab2..5f5b8ef73ef 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -334,6 +334,7 @@ pub trait IteratorExt: Iterator + Sized { /// # Examples /// /// ``` + /// # #![feature(core)] /// let xs = [100, 200, 300]; /// let mut it = xs.iter().cloned().peekable(); /// assert_eq!(*it.peek().unwrap(), 100); @@ -465,6 +466,7 @@ pub trait IteratorExt: Iterator + Sized { /// # Examples /// /// ``` + /// # #![feature(core)] /// let xs = [2, 3]; /// let ys = [0, 1, 0, 1, 2]; /// let it = xs.iter().flat_map(|&x| std::iter::count(0, 1).take(x)); @@ -521,6 +523,7 @@ pub trait IteratorExt: Iterator + Sized { /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::iter::AdditiveIterator; /// /// let a = [1, 4, 2, 3, 8, 9, 6]; @@ -563,6 +566,7 @@ pub trait IteratorExt: Iterator + Sized { /// # Examples /// /// ``` + /// # #![feature(core)] /// let a = [1, 2, 3, 4, 5]; /// let b: Vec<_> = a.iter().cloned().collect(); /// assert_eq!(a, b); @@ -579,6 +583,7 @@ pub trait IteratorExt: Iterator + Sized { /// do not. /// /// ``` + /// # #![feature(core)] /// let vec = vec![1, 2, 3, 4]; /// let (even, odd): (Vec<_>, Vec<_>) = vec.into_iter().partition(|&n| n % 2 == 0); /// assert_eq!(even, [2, 4]); @@ -648,6 +653,7 @@ pub trait IteratorExt: Iterator + Sized { /// # Examples /// /// ``` + /// # #![feature(core)] /// let a = [1, 2, 3, 4, 5]; /// let mut it = a.iter(); /// assert!(it.any(|x| *x == 3)); @@ -668,6 +674,7 @@ pub trait IteratorExt: Iterator + Sized { /// # Examples /// /// ``` + /// # #![feature(core)] /// let a = [1, 2, 3, 4, 5]; /// let mut it = a.iter(); /// assert_eq!(it.find(|&x| *x == 3).unwrap(), &3); @@ -690,6 +697,7 @@ pub trait IteratorExt: Iterator + Sized { /// # Examples /// /// ``` + /// # #![feature(core)] /// let a = [1, 2, 3, 4, 5]; /// let mut it = a.iter(); /// assert_eq!(it.position(|x| *x == 3).unwrap(), 2); @@ -718,6 +726,7 @@ pub trait IteratorExt: Iterator + Sized { /// # Examples /// /// ``` + /// # #![feature(core)] /// let a = [1, 2, 2, 4, 5]; /// let mut it = a.iter(); /// assert_eq!(it.rposition(|x| *x == 2).unwrap(), 2); @@ -795,6 +804,7 @@ pub trait IteratorExt: Iterator + Sized { /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::iter::MinMaxResult::{NoElements, OneElement, MinMax}; /// /// let a: [i32; 0] = []; @@ -860,7 +870,8 @@ pub trait IteratorExt: Iterator + Sized { /// # Examples /// /// ``` - /// use core::num::SignedInt; + /// # #![feature(core)] + /// use std::num::SignedInt; /// /// let a = [-3, 0, 1, 5, -10]; /// assert_eq!(*a.iter().max_by(|x| x.abs()).unwrap(), -10); @@ -890,7 +901,8 @@ pub trait IteratorExt: Iterator + Sized { /// # Examples /// /// ``` - /// use core::num::SignedInt; + /// # #![feature(core)] + /// use std::num::SignedInt; /// /// let a = [-3, 0, 1, 5, -10]; /// assert_eq!(*a.iter().min_by(|x| x.abs()).unwrap(), 0); @@ -940,6 +952,7 @@ pub trait IteratorExt: Iterator + Sized { /// # Examples /// /// ``` + /// # #![feature(core)] /// let a = [(1, 2), (3, 4)]; /// let (left, right): (Vec<_>, Vec<_>) = a.iter().cloned().unzip(); /// assert_eq!([1, 3], left); @@ -1146,6 +1159,7 @@ pub trait AdditiveIterator { /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::iter::AdditiveIterator; /// /// let a = [1, 2, 3, 4, 5]; @@ -1188,6 +1202,7 @@ pub trait MultiplicativeIterator { /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::iter::{count, MultiplicativeIterator}; /// /// fn factorial(n: usize) -> usize { @@ -1248,6 +1263,7 @@ impl MinMaxResult { /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::iter::MinMaxResult::{self, NoElements, OneElement, MinMax}; /// /// let r: MinMaxResult = NoElements; @@ -2292,6 +2308,7 @@ impl RandomAccessIterator for Inspect /// An iterator that yields sequential Fibonacci numbers, and stops on overflow. /// /// ``` +/// # #![feature(core)] /// use std::iter::Unfold; /// use std::num::Int; // For `.checked_add()` /// @@ -2693,6 +2710,7 @@ pub struct RangeStepInclusive { /// # Examples /// /// ``` +/// # #![feature(core)] /// use std::iter::range_step_inclusive; /// /// for i in range_step_inclusive(0, 10, 2) { diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 29cc11d5a60..6e82f0f854c 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -56,6 +56,7 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/", html_playground_url = "http://play.rust-lang.org/")] +#![doc(test(no_crate_inject))] #![feature(no_std)] #![no_std] diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index c647b037944..40e32f4171a 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -231,6 +231,7 @@ macro_rules! writeln { /// Iterators: /// /// ``` +/// # #![feature(core)] /// fn divide_by_three(x: u32) -> u32 { // one of the poorest implementations of x/3 /// for i in std::iter::count(0, 1) { /// if 3*i < i { panic!("u32 overflow"); } diff --git a/src/libcore/marker.rs b/src/libcore/marker.rs index 1b866501b8e..ae6bcc79539 100644 --- a/src/libcore/marker.rs +++ b/src/libcore/marker.rs @@ -319,6 +319,7 @@ impl MarkerTrait for T { } /// `MarkerTrait`: /// /// ``` +/// # #![feature(core)] /// use std::marker::MarkerTrait; /// trait Even : MarkerTrait { } /// ``` diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index ae1b5f65eeb..d211b0f9928 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -282,7 +282,8 @@ impl Float for f32 { /// The fractional part of the number, satisfying: /// /// ``` - /// use core::num::Float; + /// # #![feature(core)] + /// use std::num::Float; /// /// let x = 1.65f32; /// assert!(x == x.trunc() + x.fract()) diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index 4a73c1e8fcf..1421fdd72f2 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -289,7 +289,8 @@ impl Float for f64 { /// The fractional part of the number, satisfying: /// /// ``` - /// use core::num::Float; + /// # #![feature(core)] + /// use std::num::Float; /// /// let x = 1.65f64; /// assert!(x == x.trunc() + x.fract()) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 17ef0ecb1c0..9ca7b48fbe5 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -85,6 +85,7 @@ pub trait Int /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::num::Int; /// /// let n = 0b01001100u8; @@ -100,6 +101,7 @@ pub trait Int /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::num::Int; /// /// let n = 0b01001100u8; @@ -119,6 +121,7 @@ pub trait Int /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::num::Int; /// /// let n = 0b0101000u16; @@ -135,6 +138,7 @@ pub trait Int /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::num::Int; /// /// let n = 0b0101000u16; @@ -151,6 +155,7 @@ pub trait Int /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::num::Int; /// /// let n = 0x0123456789ABCDEFu64; @@ -168,6 +173,7 @@ pub trait Int /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::num::Int; /// /// let n = 0x0123456789ABCDEFu64; @@ -392,6 +398,7 @@ pub trait Int /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::num::Int; /// /// assert_eq!(2.pow(4), 16); @@ -787,6 +794,7 @@ macro_rules! int_impl { /// # Examples /// /// ```rust + /// # #![feature(core)] /// use std::num::Int; /// /// let n = 0b01001100u8; @@ -803,6 +811,7 @@ macro_rules! int_impl { /// # Examples /// /// ```rust + /// # #![feature(core)] /// use std::num::Int; /// /// let n = 0b01001100u8; @@ -822,6 +831,7 @@ macro_rules! int_impl { /// # Examples /// /// ```rust + /// # #![feature(core)] /// use std::num::Int; /// /// let n = 0b0101000u16; @@ -841,6 +851,7 @@ macro_rules! int_impl { /// # Examples /// /// ```rust + /// # #![feature(core)] /// use std::num::Int; /// /// let n = 0b0101000u16; @@ -860,6 +871,7 @@ macro_rules! int_impl { /// # Examples /// /// ```rust + /// # #![feature(core)] /// use std::num::Int; /// /// let n = 0x0123456789ABCDEFu64; @@ -881,6 +893,7 @@ macro_rules! int_impl { /// # Examples /// /// ```rust + /// # #![feature(core)] /// use std::num::Int; /// /// let n = 0x0123456789ABCDEFu64; @@ -1112,6 +1125,7 @@ macro_rules! int_impl { /// # Examples /// /// ```rust + /// # #![feature(core)] /// use std::num::Int; /// /// assert_eq!(2.pow(4), 16); @@ -1277,6 +1291,7 @@ macro_rules! uint_impl { /// # Examples /// /// ```rust + /// # #![feature(core)] /// use std::num::Int; /// /// let n = 0b01001100u8; @@ -1295,6 +1310,7 @@ macro_rules! uint_impl { /// # Examples /// /// ```rust + /// # #![feature(core)] /// use std::num::Int; /// /// let n = 0b01001100u8; @@ -1314,6 +1330,7 @@ macro_rules! uint_impl { /// # Examples /// /// ```rust + /// # #![feature(core)] /// use std::num::Int; /// /// let n = 0b0101000u16; @@ -1333,6 +1350,7 @@ macro_rules! uint_impl { /// # Examples /// /// ```rust + /// # #![feature(core)] /// use std::num::Int; /// /// let n = 0b0101000u16; @@ -1352,6 +1370,7 @@ macro_rules! uint_impl { /// # Examples /// /// ```rust + /// # #![feature(core)] /// use std::num::Int; /// /// let n = 0x0123456789ABCDEFu64; @@ -1375,6 +1394,7 @@ macro_rules! uint_impl { /// # Examples /// /// ```rust + /// # #![feature(core)] /// use std::num::Int; /// /// let n = 0x0123456789ABCDEFu64; @@ -1606,6 +1626,7 @@ macro_rules! uint_impl { /// # Examples /// /// ```rust + /// # #![feature(core)] /// use std::num::Int; /// /// assert_eq!(2.pow(4), 16); @@ -2266,6 +2287,7 @@ impl_from_primitive! { f64, to_f64 } /// # Examples /// /// ``` +/// # #![feature(core)] /// use std::num; /// /// let twenty: f32 = num::cast(0x14).unwrap(); diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 455c68d4319..ecb060397ab 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -275,6 +275,7 @@ impl Option { /// # Examples /// /// ``` + /// # #![feature(core)] /// let mut x = Some("Diamonds"); /// { /// let v = x.as_mut_slice(); @@ -470,6 +471,7 @@ impl Option { /// # Examples /// /// ``` + /// # #![feature(core)] /// let x = Some("foo"); /// assert_eq!(x.ok_or(0), Ok("foo")); /// @@ -491,6 +493,7 @@ impl Option { /// # Examples /// /// ``` + /// # #![feature(core)] /// let x = Some("foo"); /// assert_eq!(x.ok_or_else(|| 0), Ok("foo")); /// @@ -532,6 +535,7 @@ impl Option { /// # Examples /// /// ``` + /// # #![feature(core)] /// let mut x = Some(4); /// match x.iter_mut().next() { /// Some(&mut ref mut v) => *v = 42, diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 1cbea057e88..c05dffb3696 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -52,6 +52,7 @@ //! the raw pointer. It doesn't destroy `T` or deallocate any memory. //! //! ``` +//! # #![feature(alloc)] //! use std::boxed; //! //! unsafe { @@ -70,6 +71,7 @@ //! ## 3. Get it from C. //! //! ``` +//! # #![feature(libc)] //! extern crate libc; //! //! use std::mem; diff --git a/src/libcore/raw.rs b/src/libcore/raw.rs index 35dfc762687..8502a9c53c4 100644 --- a/src/libcore/raw.rs +++ b/src/libcore/raw.rs @@ -48,6 +48,7 @@ use mem; /// # Examples /// /// ``` +/// # #![feature(core)] /// use std::raw::{self, Repr}; /// /// let slice: &[u16] = &[1, 2, 3, 4]; @@ -106,6 +107,7 @@ pub struct Closure { /// # Examples /// /// ``` +/// # #![feature(core)] /// use std::mem; /// use std::raw; /// diff --git a/src/libcore/result.rs b/src/libcore/result.rs index bc8d53e2a57..a994590a395 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -95,6 +95,7 @@ //! by the [`Writer`](../io/trait.Writer.html) trait: //! //! ``` +//! # #![feature(old_io)] //! use std::old_io::IoError; //! //! trait Writer { @@ -110,6 +111,7 @@ //! something like this: //! //! ```{.ignore} +//! # #![feature(old_io)] //! use std::old_io::*; //! use std::old_path::Path; //! @@ -129,6 +131,7 @@ //! a marginally useful message indicating why: //! //! ```{.no_run} +//! # #![feature(old_io, old_path)] //! use std::old_io::*; //! use std::old_path::Path; //! @@ -140,6 +143,7 @@ //! You might also simply assert success: //! //! ```{.no_run} +//! # #![feature(old_io, old_path)] //! # use std::old_io::*; //! # use std::old_path::Path; //! @@ -151,6 +155,7 @@ //! Or propagate the error up the call stack with `try!`: //! //! ``` +//! # #![feature(old_io, old_path)] //! # use std::old_io::*; //! # use std::old_path::Path; //! fn write_message() -> Result<(), IoError> { @@ -171,6 +176,7 @@ //! It replaces this: //! //! ``` +//! # #![feature(old_io, old_path)] //! use std::old_io::*; //! use std::old_path::Path; //! @@ -196,6 +202,7 @@ //! With this: //! //! ``` +//! # #![feature(old_io, old_path)] //! use std::old_io::*; //! use std::old_path::Path; //! @@ -411,6 +418,7 @@ impl Result { /// Convert from `Result` to `&mut [T]` (without copying) /// /// ``` + /// # #![feature(core)] /// let mut x: Result<&str, u32> = Ok("Gold"); /// { /// let v = x.as_mut_slice(); @@ -452,6 +460,7 @@ impl Result { /// ignoring I/O and parse errors: /// /// ``` + /// # #![feature(old_io)] /// use std::old_io::*; /// /// let mut buffer: &[u8] = b"1\n2\n3\n4\n"; diff --git a/src/libcore/simd.rs b/src/libcore/simd.rs index 0058971faf0..21cff3021ab 100644 --- a/src/libcore/simd.rs +++ b/src/libcore/simd.rs @@ -19,7 +19,7 @@ //! provided beyond this module. //! //! ```rust -//! +//! # #![feature(core)] //! fn main() { //! use std::simd::f32x4; //! let a = f32x4(40.0, 41.0, 42.0, 43.0); diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 907b2eba80c..b8e6a05f3da 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -1491,6 +1491,7 @@ pub unsafe fn from_raw_parts_mut<'a, T>(p: *mut T, len: usize) -> &'a mut [T] { /// # Examples /// /// ``` +/// #![feature(core)] /// use std::slice; /// /// // manifest a slice out of thin air! diff --git a/src/libgraphviz/lib.rs b/src/libgraphviz/lib.rs index 0e080459344..a5017c67ee4 100644 --- a/src/libgraphviz/lib.rs +++ b/src/libgraphviz/lib.rs @@ -47,6 +47,7 @@ //! which is cyclic. //! //! ```rust +//! # #![feature(rustc_private, core)] //! use std::borrow::IntoCow; //! use std::io::Write; //! use graphviz as dot; @@ -148,6 +149,7 @@ //! entity `&sube`). //! //! ```rust +//! # #![feature(rustc_private, core)] //! use std::borrow::IntoCow; //! use std::io::Write; //! use graphviz as dot; @@ -205,6 +207,7 @@ //! Hasse-diagram for the subsets of the set `{x, y}`. //! //! ```rust +//! # #![feature(rustc_private, core)] //! use std::borrow::IntoCow; //! use std::io::Write; //! use graphviz as dot; diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs index 893781e6220..41c782a2a46 100644 --- a/src/liblibc/lib.rs +++ b/src/liblibc/lib.rs @@ -5031,7 +5031,7 @@ pub mod funcs { /// /// # Examples /// - /// ```no_run + /// ```no_run,ignore /// extern crate libc; /// /// fn main() { diff --git a/src/librand/distributions/exponential.rs b/src/librand/distributions/exponential.rs index 3180f03cfd3..0c5f5cb0d44 100644 --- a/src/librand/distributions/exponential.rs +++ b/src/librand/distributions/exponential.rs @@ -60,6 +60,7 @@ impl Rand for Exp1 { /// # Examples /// /// ``` +/// # #![feature(rand)] /// use std::rand; /// use std::rand::distributions::{Exp, IndependentSample}; /// diff --git a/src/librand/distributions/gamma.rs b/src/librand/distributions/gamma.rs index 8eaac203fb4..d04e83e84f7 100644 --- a/src/librand/distributions/gamma.rs +++ b/src/librand/distributions/gamma.rs @@ -40,6 +40,7 @@ use super::{IndependentSample, Sample, Exp}; /// # Examples /// /// ``` +/// # #![feature(rand)] /// use std::rand; /// use std::rand::distributions::{IndependentSample, Gamma}; /// @@ -187,6 +188,7 @@ impl IndependentSample for GammaLargeShape { /// # Examples /// /// ``` +/// # #![feature(rand)] /// use std::rand; /// use std::rand::distributions::{ChiSquared, IndependentSample}; /// @@ -244,6 +246,7 @@ impl IndependentSample for ChiSquared { /// # Examples /// /// ``` +/// # #![feature(rand)] /// use std::rand; /// use std::rand::distributions::{FisherF, IndependentSample}; /// @@ -288,6 +291,7 @@ impl IndependentSample for FisherF { /// # Examples /// /// ``` +/// # #![feature(rand)] /// use std::rand; /// use std::rand::distributions::{StudentT, IndependentSample}; /// diff --git a/src/librand/distributions/mod.rs b/src/librand/distributions/mod.rs index a46709932e2..5cafb8d2e5e 100644 --- a/src/librand/distributions/mod.rs +++ b/src/librand/distributions/mod.rs @@ -94,6 +94,7 @@ pub struct Weighted { /// # Examples /// /// ``` +/// # #![feature(rand)] /// use std::rand; /// use std::rand::distributions::{Weighted, WeightedChoice, IndependentSample}; /// diff --git a/src/librand/distributions/normal.rs b/src/librand/distributions/normal.rs index d07964624bf..7cecc6ac611 100644 --- a/src/librand/distributions/normal.rs +++ b/src/librand/distributions/normal.rs @@ -76,6 +76,7 @@ impl Rand for StandardNormal { /// # Examples /// /// ``` +/// # #![feature(rand)] /// use std::rand; /// use std::rand::distributions::{Normal, IndependentSample}; /// @@ -124,6 +125,7 @@ impl IndependentSample for Normal { /// # Examples /// /// ``` +/// # #![feature(rand)] /// use std::rand; /// use std::rand::distributions::{LogNormal, IndependentSample}; /// diff --git a/src/librand/distributions/range.rs b/src/librand/distributions/range.rs index 4086e149e78..e6f27a28ffa 100644 --- a/src/librand/distributions/range.rs +++ b/src/librand/distributions/range.rs @@ -36,6 +36,7 @@ use distributions::{Sample, IndependentSample}; /// # Examples /// /// ``` +/// # #![feature(rand)] /// use std::rand::distributions::{IndependentSample, Range}; /// /// fn main() { diff --git a/src/librand/lib.rs b/src/librand/lib.rs index 8de773e9fec..9f6399ff12d 100644 --- a/src/librand/lib.rs +++ b/src/librand/lib.rs @@ -149,6 +149,7 @@ pub trait Rng : Sized { /// # Examples /// /// ``` + /// # #![feature(rand, core)] /// use std::rand::{thread_rng, Rng}; /// /// let mut v = [0; 13579]; @@ -184,6 +185,7 @@ pub trait Rng : Sized { /// # Examples /// /// ``` + /// # #![feature(rand)] /// use std::rand::{thread_rng, Rng}; /// /// let mut rng = thread_rng(); @@ -202,6 +204,7 @@ pub trait Rng : Sized { /// # Examples /// /// ``` + /// # #![feature(rand)] /// use std::rand::{thread_rng, Rng}; /// /// let mut rng = thread_rng(); @@ -229,6 +232,7 @@ pub trait Rng : Sized { /// # Examples /// /// ``` + /// # #![feature(rand)] /// use std::rand::{thread_rng, Rng}; /// /// let mut rng = thread_rng(); @@ -247,6 +251,7 @@ pub trait Rng : Sized { /// # Examples /// /// ``` + /// # #![feature(rand)] /// use std::rand::{thread_rng, Rng}; /// /// let mut rng = thread_rng(); @@ -261,6 +266,7 @@ pub trait Rng : Sized { /// # Examples /// /// ``` + /// # #![feature(rand)] /// use std::rand::{thread_rng, Rng}; /// /// let s: String = thread_rng().gen_ascii_chars().take(10).collect(); @@ -277,6 +283,7 @@ pub trait Rng : Sized { /// # Examples /// /// ``` + /// # #![feature(rand)] /// use std::rand::{thread_rng, Rng}; /// /// let choices = [1, 2, 4, 8, 16, 32]; @@ -297,6 +304,7 @@ pub trait Rng : Sized { /// # Examples /// /// ``` + /// # #![feature(rand, core)] /// use std::rand::{thread_rng, Rng}; /// /// let mut rng = thread_rng(); @@ -360,6 +368,7 @@ pub trait SeedableRng: Rng { /// # Examples /// /// ``` + /// # #![feature(rand)] /// use std::rand::{Rng, SeedableRng, StdRng}; /// /// let seed: &[_] = &[1, 2, 3, 4]; @@ -375,6 +384,7 @@ pub trait SeedableRng: Rng { /// # Examples /// /// ``` + /// # #![feature(rand)] /// use std::rand::{Rng, SeedableRng, StdRng}; /// /// let seed: &[_] = &[1, 2, 3, 4]; @@ -480,6 +490,7 @@ impl Rand for XorShiftRng { /// # Examples /// /// ``` +/// # #![feature(rand)] /// use std::rand::{random, Open01}; /// /// let Open01(val) = random::>(); @@ -497,6 +508,7 @@ pub struct Open01(pub F); /// # Examples /// /// ``` +/// # #![feature(rand)] /// use std::rand::{random, Closed01}; /// /// let Closed01(val) = random::>(); diff --git a/src/librand/reseeding.rs b/src/librand/reseeding.rs index 81e65da37fc..95dd986d2e3 100644 --- a/src/librand/reseeding.rs +++ b/src/librand/reseeding.rs @@ -103,6 +103,7 @@ impl, Rsdr: Reseeder + Default> /// # Examples /// /// ``` +/// # #![feature(rand)] /// use std::rand::{Rng, SeedableRng, StdRng}; /// use std::rand::reseeding::{Reseeder, ReseedingRng}; /// diff --git a/src/librustc_bitflags/lib.rs b/src/librustc_bitflags/lib.rs index 054bfec7a20..93a2a5d1257 100644 --- a/src/librustc_bitflags/lib.rs +++ b/src/librustc_bitflags/lib.rs @@ -33,6 +33,7 @@ /// # Examples /// /// ```{.rust} +/// # #![feature(rustc_private)] /// #[macro_use] extern crate rustc_bitflags; /// /// bitflags! { @@ -59,6 +60,7 @@ /// The generated `struct`s can also be extended with type and trait implementations: /// /// ```{.rust} +/// # #![feature(rustc_private)] /// #[macro_use] extern crate rustc_bitflags; /// /// use std::fmt; diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 1b596e65a78..0f645d2b8ea 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -268,7 +268,7 @@ pub fn maketest(s: &str, cratename: Option<&str>, lints: bool, // Don't inject `extern crate std` because it's already injected by the // compiler. - if !s.contains("extern crate") && cratename != Some("std") && inject_crate { + if !s.contains("extern crate") && inject_crate { match cratename { Some(cratename) => { if s.contains(cratename) { diff --git a/src/libserialize/hex.rs b/src/libserialize/hex.rs index 1f8d45a007d..e42aa1835dc 100644 --- a/src/libserialize/hex.rs +++ b/src/libserialize/hex.rs @@ -32,6 +32,7 @@ impl ToHex for [u8] { /// # Examples /// /// ``` + /// # #![feature(rustc_private)] /// extern crate serialize; /// use serialize::hex::ToHex; /// @@ -101,6 +102,7 @@ impl FromHex for str { /// This converts a string literal to hexadecimal and back. /// /// ``` + /// # #![feature(rustc_private)] /// extern crate serialize; /// use serialize::hex::{FromHex, ToHex}; /// diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 9139e182ce4..a632306454e 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -538,6 +538,7 @@ impl HashMap /// # Examples /// /// ``` + /// # #![feature(std_misc)] /// use std::collections::HashMap; /// use std::collections::hash_map::RandomState; /// @@ -566,6 +567,7 @@ impl HashMap /// # Examples /// /// ``` + /// # #![feature(std_misc)] /// use std::collections::HashMap; /// use std::collections::hash_map::RandomState; /// @@ -981,6 +983,7 @@ impl HashMap /// # Examples /// /// ``` + /// # #![feature(std_misc)] /// use std::collections::HashMap; /// /// let mut a = HashMap::new(); diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index de3f080de82..3bc511f8a22 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -145,6 +145,7 @@ impl HashSet /// # Examples /// /// ``` + /// # #![feature(std_misc)] /// use std::collections::HashSet; /// use std::collections::hash_map::RandomState; /// @@ -169,6 +170,7 @@ impl HashSet /// # Examples /// /// ``` + /// # #![feature(std_misc)] /// use std::collections::HashSet; /// use std::collections::hash_map::RandomState; /// @@ -295,6 +297,7 @@ impl HashSet /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::collections::HashSet; /// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect(); /// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect(); @@ -325,6 +328,7 @@ impl HashSet /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::collections::HashSet; /// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect(); /// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect(); @@ -351,6 +355,7 @@ impl HashSet /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::collections::HashSet; /// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect(); /// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect(); @@ -376,6 +381,7 @@ impl HashSet /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::collections::HashSet; /// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect(); /// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect(); @@ -458,6 +464,7 @@ impl HashSet /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::collections::HashSet; /// /// let set: HashSet<_> = [1, 2, 3].iter().cloned().collect(); @@ -477,6 +484,7 @@ impl HashSet /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::collections::HashSet; /// /// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect(); @@ -498,6 +506,7 @@ impl HashSet /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::collections::HashSet; /// /// let sup: HashSet<_> = [1, 2, 3].iter().cloned().collect(); @@ -519,6 +528,7 @@ impl HashSet /// # Examples /// /// ``` + /// # #![feature(core)] /// use std::collections::HashSet; /// /// let sub: HashSet<_> = [1, 2].iter().cloned().collect(); diff --git a/src/libstd/collections/mod.rs b/src/libstd/collections/mod.rs index caada8ae50f..8d24f6b1916 100644 --- a/src/libstd/collections/mod.rs +++ b/src/libstd/collections/mod.rs @@ -300,6 +300,7 @@ //! #### Counting the number of times each character in a string occurs //! //! ``` +//! # #![feature(collections)] //! use std::collections::btree_map::{BTreeMap, Entry}; //! //! let mut count = BTreeMap::new(); @@ -327,6 +328,7 @@ //! #### Tracking the inebriation of customers at a bar //! //! ``` +//! # #![feature(collections)] //! use std::collections::btree_map::{BTreeMap, Entry}; //! //! // A client of the bar. They have an id and a blood alcohol level. diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index fc4f03ff3a5..96088003b99 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -44,6 +44,7 @@ use vec::Vec; /// # Examples /// /// ```no_run +/// # #![feature(libc)] /// # extern crate libc; /// # fn main() { /// use std::ffi::CString; @@ -82,6 +83,7 @@ pub struct CString { /// Inspecting a foreign C string /// /// ```no_run +/// # #![feature(libc)] /// extern crate libc; /// use std::ffi::CStr; /// @@ -98,6 +100,7 @@ pub struct CString { /// Passing a Rust-originating C string /// /// ```no_run +/// # #![feature(libc)] /// extern crate libc; /// use std::ffi::{CString, CStr}; /// @@ -144,6 +147,7 @@ impl CString { /// # Examples /// /// ```no_run + /// # #![feature(libc)] /// extern crate libc; /// use std::ffi::CString; /// @@ -179,6 +183,7 @@ impl CString { /// # Examples /// /// ```no_run + /// # #![feature(libc)] /// extern crate libc; /// use std::ffi::CString; /// @@ -329,6 +334,7 @@ impl CStr { /// # Examples /// /// ```no_run + /// # #![feature(libc)] /// # extern crate libc; /// # fn main() { /// use std::ffi::CStr; diff --git a/src/libstd/fs/mod.rs b/src/libstd/fs/mod.rs index 7df6d6887a2..ba98e1ddd55 100644 --- a/src/libstd/fs/mod.rs +++ b/src/libstd/fs/mod.rs @@ -633,6 +633,7 @@ pub fn remove_dir_all(path: P) -> io::Result<()> { /// # Examples /// /// ``` +/// # #![feature(path_ext)] /// use std::io; /// use std::fs::{self, PathExt, DirEntry}; /// use std::path::Path; @@ -771,6 +772,7 @@ pub fn set_file_times(path: P, accessed: u64, /// # Examples /// /// ``` +/// # #![feature(fs)] /// # fn foo() -> std::io::Result<()> { /// use std::fs; /// diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 1aa2189d315..dc390b534b7 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -105,6 +105,7 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/", html_playground_url = "http://play.rust-lang.org/")] +#![doc(test(no_crate_inject))] #![feature(alloc)] #![feature(box_syntax)] diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index f4a7e8b1b98..061c00329d2 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -112,6 +112,7 @@ macro_rules! try { /// # Examples /// /// ``` +/// # #![feature(std_misc)] /// use std::thread; /// use std::sync::mpsc; /// diff --git a/src/libstd/net/addr.rs b/src/libstd/net/addr.rs index 87241117043..e8187dc2c40 100644 --- a/src/libstd/net/addr.rs +++ b/src/libstd/net/addr.rs @@ -263,6 +263,7 @@ impl hash::Hash for SocketAddrV6 { /// Some examples: /// /// ```no_run +/// # #![feature(net)] /// use std::net::{SocketAddrV4, TcpStream, UdpSocket, TcpListener, Ipv4Addr}; /// /// fn main() { diff --git a/src/libstd/net/mod.rs b/src/libstd/net/mod.rs index 543fdd16f41..48b3247f212 100644 --- a/src/libstd/net/mod.rs +++ b/src/libstd/net/mod.rs @@ -91,6 +91,7 @@ impl Iterator for LookupHost { /// # Examples /// /// ```no_run +/// # #![feature(net)] /// use std::net; /// /// # fn foo() -> std::io::Result<()> { diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index f263d7d72d3..869faa795f9 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -27,6 +27,7 @@ use sys_common::AsInner; /// # Examples /// /// ```no_run +/// # #![feature(net)] /// use std::io::prelude::*; /// use std::net::TcpStream; /// @@ -46,6 +47,7 @@ pub struct TcpStream(net_imp::TcpStream); /// # Examples /// /// ```no_run +/// # #![feature(net)] /// use std::net::{TcpListener, TcpStream}; /// use std::thread; /// diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs index 1ace1957526..e593bbe8e48 100644 --- a/src/libstd/net/udp.rs +++ b/src/libstd/net/udp.rs @@ -27,6 +27,7 @@ use sys_common::AsInner; /// # Examples /// /// ```no_run +/// # #![feature(net)] /// use std::net::UdpSocket; /// /// # fn foo() -> std::io::Result<()> { diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index b5513dfd035..a4f06f14d49 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -365,6 +365,7 @@ impl f32 { /// Returns the `NaN` value. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let nan: f32 = Float::nan(); @@ -379,6 +380,7 @@ impl f32 { /// Returns the infinite value. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f32; /// @@ -396,6 +398,7 @@ impl f32 { /// Returns the negative infinite value. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f32; /// @@ -413,6 +416,7 @@ impl f32 { /// Returns `0.0`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let inf: f32 = Float::infinity(); @@ -431,6 +435,7 @@ impl f32 { /// Returns `-0.0`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let inf: f32 = Float::infinity(); @@ -449,6 +454,7 @@ impl f32 { /// Returns `1.0`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let one: f32 = Float::one(); @@ -525,6 +531,7 @@ impl f32 { /// Returns the smallest finite value that this type can represent. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f64; /// @@ -548,6 +555,7 @@ impl f32 { /// Returns the largest finite value that this type can represent. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f64; /// @@ -563,6 +571,7 @@ impl f32 { /// Returns `true` if this value is `NaN` and false otherwise. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f64; /// @@ -580,6 +589,7 @@ impl f32 { /// false otherwise. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f32; /// @@ -601,6 +611,7 @@ impl f32 { /// Returns `true` if this number is neither infinite nor `NaN`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f32; /// @@ -623,6 +634,7 @@ impl f32 { /// [subnormal][subnormal], or `NaN`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f32; /// @@ -650,6 +662,7 @@ impl f32 { /// predicate instead. /// /// ``` + /// # #![feature(core)] /// use std::num::{Float, FpCategory}; /// use std::f32; /// @@ -668,6 +681,7 @@ impl f32 { /// The floating point encoding is documented in the [Reference][floating-point]. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let num = 2.0f32; @@ -770,6 +784,7 @@ impl f32 { /// number is `Float::nan()`. /// /// ``` + /// # #![feature(core, std_misc)] /// use std::num::Float; /// use std::f64; /// @@ -795,6 +810,7 @@ impl f32 { /// - `Float::nan()` if the number is `Float::nan()` /// /// ``` + /// # #![feature(core, std_misc)] /// use std::num::Float; /// use std::f64; /// @@ -856,6 +872,7 @@ impl f32 { /// a separate multiplication operation followed by an add. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let m = 10.0; @@ -875,6 +892,7 @@ impl f32 { /// Take the reciprocal (inverse) of a number, `1/x`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let x = 2.0; @@ -922,6 +940,7 @@ impl f32 { /// Returns NaN if `self` is a negative number. /// /// ``` + /// # #![feature(core, std_misc)] /// use std::num::Float; /// /// let positive = 4.0; @@ -940,6 +959,7 @@ impl f32 { /// Take the reciprocal (inverse) square root of a number, `1/sqrt(x)`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let f = 4.0; @@ -1061,6 +1081,7 @@ impl f32 { /// Convert radians to degrees. /// /// ``` + /// # #![feature(std_misc, core)] /// use std::num::Float; /// use std::f64::consts; /// @@ -1077,6 +1098,7 @@ impl f32 { /// Convert degrees to radians. /// /// ``` + /// # #![feature(std_misc, core)] /// use std::num::Float; /// use std::f64::consts; /// @@ -1093,6 +1115,7 @@ impl f32 { /// Constructs a floating point number of `x*2^exp`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// // 3*2^2 - 12 == 0 @@ -1114,6 +1137,7 @@ impl f32 { /// * `0.5 <= abs(x) < 1.0` /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let x = 4.0; @@ -1141,6 +1165,7 @@ impl f32 { /// `other`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let x = 1.0f32; @@ -1194,6 +1219,7 @@ impl f32 { /// * Else: `self - other` /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let x = 3.0; @@ -1214,6 +1240,7 @@ impl f32 { /// Take the cubic root of a number. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let x = 8.0; @@ -1233,6 +1260,7 @@ impl f32 { /// legs of length `x` and `y`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let x = 2.0; @@ -1253,6 +1281,7 @@ impl f32 { /// Computes the sine of a number (in radians). /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -1271,6 +1300,7 @@ impl f32 { /// Computes the cosine of a number (in radians). /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -1289,6 +1319,7 @@ impl f32 { /// Computes the tangent of a number (in radians). /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -1308,6 +1339,7 @@ impl f32 { /// [-1, 1]. /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -1329,6 +1361,7 @@ impl f32 { /// [-1, 1]. /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -1372,6 +1405,7 @@ impl f32 { /// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)` /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -1401,6 +1435,7 @@ impl f32 { /// `(sin(x), cos(x))`. /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -1423,6 +1458,7 @@ impl f32 { /// number is close to zero. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let x = 7.0; @@ -1442,6 +1478,7 @@ impl f32 { /// the operations were performed separately. /// /// ``` + /// # #![feature(std_misc, core)] /// use std::num::Float; /// use std::f64; /// @@ -1461,6 +1498,7 @@ impl f32 { /// Hyperbolic sine function. /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -1483,6 +1521,7 @@ impl f32 { /// Hyperbolic cosine function. /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -1505,6 +1544,7 @@ impl f32 { /// Hyperbolic tangent function. /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -1527,6 +1567,7 @@ impl f32 { /// Inverse hyperbolic sine function. /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// /// let x = 1.0; @@ -1548,6 +1589,7 @@ impl f32 { /// Inverse hyperbolic cosine function. /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// /// let x = 1.0; @@ -1569,6 +1611,7 @@ impl f32 { /// Inverse hyperbolic tangent function. /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index 61bddc3d18f..9306804d1f7 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -374,6 +374,7 @@ impl f64 { /// Returns the `NaN` value. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let nan: f32 = Float::nan(); @@ -388,6 +389,7 @@ impl f64 { /// Returns the infinite value. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f32; /// @@ -405,6 +407,7 @@ impl f64 { /// Returns the negative infinite value. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f32; /// @@ -422,6 +425,7 @@ impl f64 { /// Returns `0.0`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let inf: f32 = Float::infinity(); @@ -440,6 +444,7 @@ impl f64 { /// Returns `-0.0`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let inf: f32 = Float::infinity(); @@ -458,6 +463,7 @@ impl f64 { /// Returns `1.0`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let one: f32 = Float::one(); @@ -534,6 +540,7 @@ impl f64 { /// Returns the smallest finite value that this type can represent. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f64; /// @@ -557,6 +564,7 @@ impl f64 { /// Returns the largest finite value that this type can represent. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f64; /// @@ -572,6 +580,7 @@ impl f64 { /// Returns `true` if this value is `NaN` and false otherwise. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f64; /// @@ -589,6 +598,7 @@ impl f64 { /// false otherwise. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f32; /// @@ -610,6 +620,7 @@ impl f64 { /// Returns `true` if this number is neither infinite nor `NaN`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f32; /// @@ -632,6 +643,7 @@ impl f64 { /// [subnormal][subnormal], or `NaN`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f32; /// @@ -659,6 +671,7 @@ impl f64 { /// predicate instead. /// /// ``` + /// # #![feature(core)] /// use std::num::{Float, FpCategory}; /// use std::f32; /// @@ -677,6 +690,7 @@ impl f64 { /// The floating point encoding is documented in the [Reference][floating-point]. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let num = 2.0f32; @@ -779,6 +793,7 @@ impl f64 { /// number is `Float::nan()`. /// /// ``` + /// # #![feature(core, std_misc)] /// use std::num::Float; /// use std::f64; /// @@ -804,6 +819,7 @@ impl f64 { /// - `Float::nan()` if the number is `Float::nan()` /// /// ``` + /// # #![feature(core, std_misc)] /// use std::num::Float; /// use std::f64; /// @@ -865,6 +881,7 @@ impl f64 { /// a separate multiplication operation followed by an add. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let m = 10.0; @@ -884,6 +901,7 @@ impl f64 { /// Take the reciprocal (inverse) of a number, `1/x`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let x = 2.0; @@ -931,6 +949,7 @@ impl f64 { /// Returns NaN if `self` is a negative number. /// /// ``` + /// # #![feature(core, std_misc)] /// use std::num::Float; /// /// let positive = 4.0; @@ -948,6 +967,7 @@ impl f64 { /// Take the reciprocal (inverse) square root of a number, `1/sqrt(x)`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let f = 4.0; @@ -1069,6 +1089,7 @@ impl f64 { /// Convert radians to degrees. /// /// ``` + /// # #![feature(std_misc, core)] /// use std::num::Float; /// use std::f64::consts; /// @@ -1085,6 +1106,7 @@ impl f64 { /// Convert degrees to radians. /// /// ``` + /// # #![feature(std_misc, core)] /// use std::num::Float; /// use std::f64::consts; /// @@ -1101,6 +1123,7 @@ impl f64 { /// Constructs a floating point number of `x*2^exp`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// // 3*2^2 - 12 == 0 @@ -1122,6 +1145,7 @@ impl f64 { /// * `0.5 <= abs(x) < 1.0` /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let x = 4.0; @@ -1149,6 +1173,7 @@ impl f64 { /// `other`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let x = 1.0f32; @@ -1202,6 +1227,7 @@ impl f64 { /// * Else: `self - other` /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let x = 3.0; @@ -1222,6 +1248,7 @@ impl f64 { /// Take the cubic root of a number. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let x = 8.0; @@ -1241,6 +1268,7 @@ impl f64 { /// legs of length `x` and `y`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let x = 2.0; @@ -1261,6 +1289,7 @@ impl f64 { /// Computes the sine of a number (in radians). /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -1279,6 +1308,7 @@ impl f64 { /// Computes the cosine of a number (in radians). /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -1297,6 +1327,7 @@ impl f64 { /// Computes the tangent of a number (in radians). /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -1316,6 +1347,7 @@ impl f64 { /// [-1, 1]. /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -1337,6 +1369,7 @@ impl f64 { /// [-1, 1]. /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -1380,6 +1413,7 @@ impl f64 { /// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)` /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -1409,6 +1443,7 @@ impl f64 { /// `(sin(x), cos(x))`. /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -1431,6 +1466,7 @@ impl f64 { /// number is close to zero. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let x = 7.0; @@ -1450,6 +1486,7 @@ impl f64 { /// the operations were performed separately. /// /// ``` + /// # #![feature(std_misc, core)] /// use std::num::Float; /// use std::f64; /// @@ -1469,6 +1506,7 @@ impl f64 { /// Hyperbolic sine function. /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -1491,6 +1529,7 @@ impl f64 { /// Hyperbolic cosine function. /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -1513,6 +1552,7 @@ impl f64 { /// Hyperbolic tangent function. /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -1577,6 +1617,7 @@ impl f64 { /// Inverse hyperbolic tangent function. /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 562094a87f4..b9e9433e3ee 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -55,6 +55,7 @@ pub trait Float /// Returns the `NaN` value. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let nan: f32 = Float::nan(); @@ -67,6 +68,7 @@ pub trait Float /// Returns the infinite value. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f32; /// @@ -82,6 +84,7 @@ pub trait Float /// Returns the negative infinite value. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f32; /// @@ -97,6 +100,7 @@ pub trait Float /// Returns `0.0`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let inf: f32 = Float::infinity(); @@ -113,6 +117,7 @@ pub trait Float /// Returns `-0.0`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let inf: f32 = Float::infinity(); @@ -129,6 +134,7 @@ pub trait Float /// Returns `1.0`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let one: f32 = Float::one(); @@ -182,6 +188,7 @@ pub trait Float /// Returns the smallest finite value that this type can represent. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f64; /// @@ -199,6 +206,7 @@ pub trait Float /// Returns the largest finite value that this type can represent. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f64; /// @@ -211,6 +219,7 @@ pub trait Float /// Returns `true` if this value is `NaN` and false otherwise. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f64; /// @@ -226,6 +235,7 @@ pub trait Float /// false otherwise. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f32; /// @@ -245,6 +255,7 @@ pub trait Float /// Returns `true` if this number is neither infinite nor `NaN`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f32; /// @@ -265,6 +276,7 @@ pub trait Float /// [subnormal][subnormal], or `NaN`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f32; /// @@ -291,6 +303,7 @@ pub trait Float /// predicate instead. /// /// ``` + /// # #![feature(core)] /// use std::num::{Float, FpCategory}; /// use std::f32; /// @@ -308,6 +321,7 @@ pub trait Float /// The floating point encoding is documented in the [Reference][floating-point]. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let num = 2.0f32; @@ -399,6 +413,7 @@ pub trait Float /// number is `Float::nan()`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f64; /// @@ -422,6 +437,7 @@ pub trait Float /// - `Float::nan()` if the number is `Float::nan()` /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// use std::f64; /// @@ -478,6 +494,7 @@ pub trait Float /// a separate multiplication operation followed by an add. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let m = 10.0; @@ -495,6 +512,7 @@ pub trait Float /// Take the reciprocal (inverse) of a number, `1/x`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let x = 2.0; @@ -537,6 +555,7 @@ pub trait Float /// Returns NaN if `self` is a negative number. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let positive = 4.0; @@ -553,6 +572,7 @@ pub trait Float /// Take the reciprocal (inverse) square root of a number, `1/sqrt(x)`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let f = 4.0; @@ -662,6 +682,7 @@ pub trait Float /// Convert radians to degrees. /// /// ``` + /// # #![feature(std_misc, core)] /// use std::num::Float; /// use std::f64::consts; /// @@ -676,6 +697,7 @@ pub trait Float /// Convert degrees to radians. /// /// ``` + /// # #![feature(std_misc, core)] /// use std::num::Float; /// use std::f64::consts; /// @@ -690,6 +712,7 @@ pub trait Float /// Constructs a floating point number of `x*2^exp`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// // 3*2^2 - 12 == 0 @@ -707,6 +730,7 @@ pub trait Float /// * `0.5 <= abs(x) < 1.0` /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let x = 4.0; @@ -726,6 +750,7 @@ pub trait Float /// `other`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let x = 1.0f32; @@ -769,6 +794,7 @@ pub trait Float /// * Else: `self - other` /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let x = 3.0; @@ -785,6 +811,7 @@ pub trait Float /// Take the cubic root of a number. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let x = 8.0; @@ -800,6 +827,7 @@ pub trait Float /// legs of length `x` and `y`. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let x = 2.0; @@ -817,6 +845,7 @@ pub trait Float /// Computes the sine of a number (in radians). /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -831,6 +860,7 @@ pub trait Float /// Computes the cosine of a number (in radians). /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -845,6 +875,7 @@ pub trait Float /// Computes the tangent of a number (in radians). /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -860,6 +891,7 @@ pub trait Float /// [-1, 1]. /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -877,6 +909,7 @@ pub trait Float /// [-1, 1]. /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -912,6 +945,7 @@ pub trait Float /// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)` /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -937,6 +971,7 @@ pub trait Float /// `(sin(x), cos(x))`. /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -956,6 +991,7 @@ pub trait Float /// number is close to zero. /// /// ``` + /// # #![feature(std_misc)] /// use std::num::Float; /// /// let x = 7.0; @@ -971,6 +1007,7 @@ pub trait Float /// the operations were performed separately. /// /// ``` + /// # #![feature(std_misc, core)] /// use std::num::Float; /// use std::f64; /// @@ -987,6 +1024,7 @@ pub trait Float /// Hyperbolic sine function. /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -1005,6 +1043,7 @@ pub trait Float /// Hyperbolic cosine function. /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -1023,6 +1062,7 @@ pub trait Float /// Hyperbolic tangent function. /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// @@ -1069,6 +1109,7 @@ pub trait Float /// Inverse hyperbolic tangent function. /// /// ``` + /// # #![feature(core)] /// use std::num::Float; /// use std::f64; /// diff --git a/src/libstd/old_io/buffered.rs b/src/libstd/old_io/buffered.rs index 3e5f732e345..cb67d709a14 100644 --- a/src/libstd/old_io/buffered.rs +++ b/src/libstd/old_io/buffered.rs @@ -33,6 +33,7 @@ use vec::Vec; /// # Examples /// /// ``` +/// # #![feature(old_io, old_path)] /// use std::old_io::*; /// use std::old_path::Path; /// @@ -137,6 +138,7 @@ impl Reader for BufferedReader { /// # Examples /// /// ``` +/// # #![feature(old_io, old_path)] /// use std::old_io::*; /// use std::old_path::Path; /// @@ -324,6 +326,7 @@ impl Reader for InternalBufferedWriter { /// # Examples /// /// ``` +/// # #![feature(old_io, old_path)] /// # #![allow(unused_must_use)] /// use std::old_io::*; /// use std::old_path::Path; diff --git a/src/libstd/old_io/comm_adapters.rs b/src/libstd/old_io/comm_adapters.rs index 7e62a21f105..cd8252540da 100644 --- a/src/libstd/old_io/comm_adapters.rs +++ b/src/libstd/old_io/comm_adapters.rs @@ -23,6 +23,7 @@ use vec::Vec; /// # Examples /// /// ``` +/// # #![feature(old_io)] /// use std::sync::mpsc::channel; /// use std::old_io::*; /// @@ -114,6 +115,7 @@ impl Reader for ChanReader { /// # Examples /// /// ``` +/// # #![feature(old_io, io)] /// # #![allow(unused_must_use)] /// use std::sync::mpsc::channel; /// use std::old_io::*; diff --git a/src/libstd/old_io/fs.rs b/src/libstd/old_io/fs.rs index 87e5b91fc28..40a7cce81dd 100644 --- a/src/libstd/old_io/fs.rs +++ b/src/libstd/old_io/fs.rs @@ -30,6 +30,7 @@ //! # Examples //! //! ```rust +//! # #![feature(old_io, io, old_path)] //! # #![allow(unused_must_use)] //! use std::old_io::fs::PathExtensions; //! use std::old_io::*; @@ -105,6 +106,7 @@ impl File { /// # Examples /// /// ```rust,should_fail + /// # #![feature(old_io, old_path)] /// use std::old_io::*; /// use std::old_path::Path; /// @@ -177,6 +179,7 @@ impl File { /// # Examples /// /// ``` + /// # #![feature(old_io, old_path)] /// use std::old_io::*; /// use std::old_path::Path; /// @@ -197,6 +200,7 @@ impl File { /// # Examples /// /// ``` + /// # #![feature(old_io, old_path, io)] /// # #![allow(unused_must_use)] /// use std::old_io::*; /// use std::old_path::Path; @@ -289,6 +293,7 @@ impl File { /// # Examples /// /// ``` +/// # #![feature(old_io, old_path)] /// # #![allow(unused_must_use)] /// use std::old_io::*; /// use std::old_path::Path; @@ -321,6 +326,7 @@ pub fn unlink(path: &Path) -> IoResult<()> { /// # Examples /// /// ``` +/// # #![feature(old_io, old_path)] /// use std::old_io::*; /// use std::old_path::Path; /// @@ -364,6 +370,7 @@ pub fn lstat(path: &Path) -> IoResult { /// # Examples /// /// ``` +/// # #![feature(old_io, old_path)] /// # #![allow(unused_must_use)] /// use std::old_io::*; /// use std::old_path::Path; @@ -393,6 +400,7 @@ pub fn rename(from: &Path, to: &Path) -> IoResult<()> { /// # Examples /// /// ``` +/// # #![feature(old_io, old_path)] /// # #![allow(unused_must_use)] /// use std::old_io::*; /// use std::old_path::Path; @@ -444,6 +452,7 @@ pub fn copy(from: &Path, to: &Path) -> IoResult<()> { /// # Examples /// /// ``` +/// # #![feature(old_io, old_path)] /// # #![allow(unused_must_use)] /// use std::old_io; /// use std::old_io::*; @@ -516,6 +525,7 @@ pub fn readlink(path: &Path) -> IoResult { /// # Examples /// /// ``` +/// # #![feature(old_io, old_path, old_fs)] /// # #![allow(unused_must_use)] /// use std::old_io; /// use std::old_io::*; @@ -541,6 +551,7 @@ pub fn mkdir(path: &Path, mode: FilePermission) -> IoResult<()> { /// # Examples /// /// ``` +/// # #![feature(old_io, old_path)] /// # #![allow(unused_must_use)] /// use std::old_io::*; /// use std::old_path::Path; @@ -566,6 +577,7 @@ pub fn rmdir(path: &Path) -> IoResult<()> { /// # Examples /// /// ``` +/// # #![feature(old_io, old_path)] /// use std::old_io::fs::PathExtensions; /// use std::old_io; /// use std::old_io::*; diff --git a/src/libstd/old_io/mem.rs b/src/libstd/old_io/mem.rs index 1acc6abc850..d877a60b079 100644 --- a/src/libstd/old_io/mem.rs +++ b/src/libstd/old_io/mem.rs @@ -54,6 +54,7 @@ impl Writer for Vec { /// # Examples /// /// ``` +/// # #![feature(old_io, io)] /// # #![allow(unused_must_use)] /// use std::old_io::*; /// @@ -114,6 +115,7 @@ impl Writer for MemWriter { /// # Examples /// /// ``` +/// # #![feature(old_io)] /// # #![allow(unused_must_use)] /// use std::old_io::*; /// @@ -244,6 +246,7 @@ impl<'a> Buffer for &'a [u8] { /// # Examples /// /// ``` +/// # #![feature(old_io, io)] /// # #![allow(unused_must_use)] /// use std::old_io::*; /// @@ -316,6 +319,7 @@ impl<'a> Seek for BufWriter<'a> { /// # Examples /// /// ``` +/// # #![feature(old_io)] /// # #![allow(unused_must_use)] /// use std::old_io::*; /// diff --git a/src/libstd/old_io/mod.rs b/src/libstd/old_io/mod.rs index 6dfb54fd66c..ac908c529dc 100644 --- a/src/libstd/old_io/mod.rs +++ b/src/libstd/old_io/mod.rs @@ -48,6 +48,7 @@ //! * Read lines from stdin //! //! ```rust +//! # #![feature(old_io, old_path)] //! use std::old_io as io; //! use std::old_io::*; //! @@ -60,6 +61,7 @@ //! * Read a complete file //! //! ```rust +//! # #![feature(old_io, old_path)] //! use std::old_io::*; //! use std::old_path::Path; //! @@ -69,6 +71,7 @@ //! * Write a line to a file //! //! ```rust +//! # #![feature(old_io, old_path)] //! # #![allow(unused_must_use)] //! use std::old_io::*; //! use std::old_path::Path; @@ -82,6 +85,7 @@ //! * Iterate over the lines of a file //! //! ```rust,no_run +//! # #![feature(old_io, old_path)] //! use std::old_io::*; //! use std::old_path::Path; //! @@ -95,6 +99,7 @@ //! * Pull the lines of a file into a vector of strings //! //! ```rust,no_run +//! # #![feature(old_io, old_path)] //! use std::old_io::*; //! use std::old_path::Path; //! @@ -106,6 +111,7 @@ //! * Make a simple TCP client connection and request //! //! ```rust +//! # #![feature(old_io)] //! # #![allow(unused_must_use)] //! use std::old_io::*; //! @@ -122,6 +128,7 @@ //! * Make a simple TCP server //! //! ```rust +//! # #![feature(old_io)] //! # fn main() { } //! # fn foo() { //! # #![allow(dead_code)] @@ -186,6 +193,7 @@ //! If you wanted to handle the error though you might write: //! //! ```rust +//! # #![feature(old_io, old_path)] //! # #![allow(unused_must_use)] //! use std::old_io::*; //! use std::old_path::Path; @@ -221,6 +229,7 @@ //! If you wanted to read several `u32`s from a file and return their product: //! //! ```rust +//! # #![feature(old_io, old_path)] //! use std::old_io::*; //! use std::old_path::Path; //! @@ -948,6 +957,7 @@ unsafe fn slice_vec_capacity<'a, T>(v: &'a mut Vec, start: uint, end: uint) - /// # Examples /// /// ``` +/// # #![feature(old_io)] /// use std::old_io as io; /// use std::old_io::*; /// use std::old_io::util::LimitReader; @@ -1282,6 +1292,7 @@ impl<'a> Writer for &'a mut (Writer+'a) { /// # Examples /// /// ``` +/// # #![feature(old_io)] /// use std::old_io::util::TeeReader; /// use std::old_io::*; /// @@ -1407,6 +1418,7 @@ pub trait Buffer: Reader { /// # Examples /// /// ``` + /// # #![feature(old_io)] /// use std::old_io::*; /// /// let mut reader = BufReader::new(b"hello\nworld"); @@ -1631,6 +1643,7 @@ impl<'a, T, A: ?Sized + Acceptor> Iterator for IncomingConnections<'a, A> { /// # Examples /// /// ``` +/// # #![feature(old_io)] /// use std::old_io as io; /// /// let eof = io::standard_error(io::EndOfFile); @@ -1719,6 +1732,7 @@ pub enum FileType { /// # Examples /// /// ```no_run +/// # #![feature(old_io, old_path)] /// /// use std::old_io::fs::PathExtensions; /// use std::old_path::Path; diff --git a/src/libstd/old_io/net/ip.rs b/src/libstd/old_io/net/ip.rs index 077a5072570..f7953ac51b8 100644 --- a/src/libstd/old_io/net/ip.rs +++ b/src/libstd/old_io/net/ip.rs @@ -414,6 +414,7 @@ pub struct ParseError; /// Some examples: /// /// ```rust,no_run +/// # #![feature(old_io, core)] /// # #![allow(unused_must_use)] /// /// use std::old_io::{TcpStream, TcpListener}; diff --git a/src/libstd/old_io/net/pipe.rs b/src/libstd/old_io/net/pipe.rs index 77efedbc327..f9e5ae71e12 100644 --- a/src/libstd/old_io/net/pipe.rs +++ b/src/libstd/old_io/net/pipe.rs @@ -54,6 +54,7 @@ impl UnixStream { /// # Examples /// /// ``` + /// # #![feature(old_io, old_path, io)] /// # #![allow(unused_must_use)] /// use std::old_io::net::pipe::UnixStream; /// use std::old_io::*; @@ -181,6 +182,7 @@ impl UnixListener { /// # Examples /// /// ``` + /// # #![feature(old_io, io, old_path)] /// # fn foo() { /// use std::old_io::net::pipe::UnixListener; /// use std::old_io::*; diff --git a/src/libstd/old_io/net/tcp.rs b/src/libstd/old_io/net/tcp.rs index dbf3c4a4b1e..75f786f0bb1 100644 --- a/src/libstd/old_io/net/tcp.rs +++ b/src/libstd/old_io/net/tcp.rs @@ -41,6 +41,7 @@ use sys_common; /// # Examples /// /// ```no_run +/// # #![feature(old_io, io)] /// use std::old_io::*; /// /// { @@ -133,6 +134,7 @@ impl TcpStream { /// # Examples /// /// ```no_run + /// # #![feature(old_io, std_misc)] /// # #![allow(unused_must_use)] /// use std::old_io::*; /// use std::time::Duration; @@ -278,6 +280,7 @@ impl sys_common::AsInner for TcpStream { /// # Examples /// /// ``` +/// # #![feature(old_io)] /// # fn foo() { /// use std::old_io::*; /// use std::thread; @@ -374,6 +377,7 @@ impl TcpAcceptor { /// # Examples /// /// ```no_run + /// # #![feature(old_io, io)] /// use std::old_io::*; /// /// let mut a = TcpListener::bind("127.0.0.1:8482").listen().unwrap(); @@ -417,6 +421,7 @@ impl TcpAcceptor { /// # Examples /// /// ``` + /// # #![feature(old_io, io)] /// use std::old_io::*; /// use std::thread; /// diff --git a/src/libstd/old_io/net/udp.rs b/src/libstd/old_io/net/udp.rs index 97ef3da2f36..3aa811974b3 100644 --- a/src/libstd/old_io/net/udp.rs +++ b/src/libstd/old_io/net/udp.rs @@ -31,6 +31,7 @@ use sys_common; /// # Examples /// /// ```rust,no_run +/// # #![feature(old_io)] /// # #![allow(unused_must_use)] /// /// use std::old_io::net::udp::UdpSocket; diff --git a/src/libstd/old_io/pipe.rs b/src/libstd/old_io/pipe.rs index b2b28453c89..0b555e2f0ff 100644 --- a/src/libstd/old_io/pipe.rs +++ b/src/libstd/old_io/pipe.rs @@ -46,6 +46,7 @@ impl PipeStream { /// # Examples /// /// ```{rust,no_run} + /// # #![feature(old_io, libc, io)] /// # #![allow(unused_must_use)] /// extern crate libc; /// diff --git a/src/libstd/old_io/process.rs b/src/libstd/old_io/process.rs index 54fd20f45e2..d7ede451fb8 100644 --- a/src/libstd/old_io/process.rs +++ b/src/libstd/old_io/process.rs @@ -61,6 +61,7 @@ use thread; /// # Examples /// /// ```should_fail +/// # #![feature(old_io)] /// use std::old_io::*; /// /// let mut child = match Command::new("/bin/cat").arg("file.txt").spawn() { @@ -164,6 +165,7 @@ pub type EnvMap = HashMap; /// to be changed (for example, by adding arguments) prior to spawning: /// /// ``` +/// # #![feature(old_io)] /// use std::old_io::*; /// /// let mut process = match Command::new("sh").arg("-c").arg("echo hello").spawn() { @@ -365,6 +367,7 @@ impl Command { /// # Examples /// /// ``` + /// # #![feature(old_io, core)] /// use std::old_io::Command; /// /// let output = match Command::new("cat").arg("foot.txt").output() { @@ -386,6 +389,7 @@ impl Command { /// # Examples /// /// ``` + /// # #![feature(old_io)] /// use std::old_io::Command; /// /// let status = match Command::new("ls").status() { @@ -660,6 +664,7 @@ impl Process { /// # Examples /// /// ```no_run + /// # #![feature(old_io, io)] /// use std::old_io::{Command, IoResult}; /// use std::old_io::process::ProcessExit; /// diff --git a/src/libstd/old_io/stdio.rs b/src/libstd/old_io/stdio.rs index a1c8630e0ec..ef811f832b3 100644 --- a/src/libstd/old_io/stdio.rs +++ b/src/libstd/old_io/stdio.rs @@ -18,6 +18,7 @@ //! # Examples //! //! ```rust +//! # #![feature(old_io)] //! # #![allow(unused_must_use)] //! use std::old_io; //! use std::old_io::*; @@ -140,6 +141,7 @@ impl StdinReader { /// # Examples /// /// ``` + /// # #![feature(old_io)] /// use std::old_io; /// use std::old_io::*; /// diff --git a/src/libstd/old_io/tempfile.rs b/src/libstd/old_io/tempfile.rs index 90b3d1004c0..c0f6ddaaef7 100644 --- a/src/libstd/old_io/tempfile.rs +++ b/src/libstd/old_io/tempfile.rs @@ -29,6 +29,7 @@ use string::String; /// # Examples /// /// ```no_run +/// # #![feature(old_io, old_path)] /// use std::old_io::*; /// use std::old_path::{Path, GenericPath}; /// diff --git a/src/libstd/old_io/timer.rs b/src/libstd/old_io/timer.rs index 65c62a99335..f8cba044443 100644 --- a/src/libstd/old_io/timer.rs +++ b/src/libstd/old_io/timer.rs @@ -31,6 +31,7 @@ use sys::timer::Timer as TimerImp; /// # Examples /// /// ``` +/// # #![feature(old_io, std_misc)] /// # fn foo() { /// use std::old_io::Timer; /// use std::time::Duration; @@ -54,6 +55,7 @@ use sys::timer::Timer as TimerImp; /// the `old_io::timer` module. /// /// ``` +/// # #![feature(old_io, std_misc)] /// # fn foo() { /// use std::old_io::timer; /// use std::time::Duration; @@ -116,6 +118,7 @@ impl Timer { /// # Examples /// /// ``` + /// # #![feature(old_io, std_misc)] /// use std::old_io::Timer; /// use std::time::Duration; /// @@ -129,6 +132,7 @@ impl Timer { /// ``` /// /// ``` + /// # #![feature(old_io, std_misc)] /// use std::old_io::Timer; /// use std::time::Duration; /// @@ -168,6 +172,7 @@ impl Timer { /// # Examples /// /// ``` + /// # #![feature(old_io, std_misc)] /// use std::old_io::Timer; /// use std::time::Duration; /// @@ -187,6 +192,7 @@ impl Timer { /// ``` /// /// ``` + /// # #![feature(old_io, std_misc)] /// use std::old_io::Timer; /// use std::time::Duration; /// diff --git a/src/libstd/old_path/mod.rs b/src/libstd/old_path/mod.rs index 909fa4062b6..50bda04b5d0 100644 --- a/src/libstd/old_path/mod.rs +++ b/src/libstd/old_path/mod.rs @@ -49,6 +49,7 @@ //! ## Examples //! //! ```rust +//! # #![feature(old_path, old_io)] //! use std::old_io::fs::PathExtensions; //! use std::old_path::{Path, GenericPath}; //! @@ -143,6 +144,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -168,6 +170,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -191,6 +194,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -209,6 +213,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -224,6 +229,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -240,6 +246,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -259,6 +266,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -277,6 +285,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -293,6 +302,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -313,6 +323,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -329,6 +340,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -349,6 +361,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -377,6 +390,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -398,6 +412,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -426,6 +441,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -445,6 +461,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -472,6 +489,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -523,6 +541,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -549,6 +568,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -574,6 +594,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -594,6 +615,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -610,6 +632,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -635,6 +658,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -665,6 +689,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -683,6 +708,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -709,6 +735,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -732,6 +759,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -750,6 +778,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -769,6 +798,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -789,6 +819,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} @@ -806,6 +837,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// # foo(); /// # #[cfg(windows)] fn foo() {} diff --git a/src/libstd/old_path/windows.rs b/src/libstd/old_path/windows.rs index cea2c238ece..4f367e30526 100644 --- a/src/libstd/old_path/windows.rs +++ b/src/libstd/old_path/windows.rs @@ -605,6 +605,7 @@ impl Path { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// println!("{}", Path::new(r"C:\some\path").display()); /// ``` @@ -620,6 +621,7 @@ impl Path { /// # Examples /// /// ``` + /// # #![feature(old_path)] /// use std::old_path::{Path, GenericPath}; /// let path = Path::new_opt(r"C:\some\path"); /// diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 3870b8614ff..6296cd9554c 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -125,6 +125,7 @@ pub const TMPBUF_SZ : uint = 1000; /// # Examples /// /// ``` +/// # #![feature(os, old_path)] /// use std::os; /// use std::old_path::{Path, GenericPath}; /// @@ -146,6 +147,7 @@ pub fn getcwd() -> IoResult { /// # Examples /// /// ``` +/// # #![feature(os)] /// use std::os; /// /// // We will iterate through the references to the element returned by os::env(); @@ -182,6 +184,7 @@ pub fn env_as_bytes() -> Vec<(Vec, Vec)> { /// # Examples /// /// ``` +/// # #![feature(os)] /// use std::os; /// /// let key = "HOME"; @@ -224,6 +227,7 @@ fn byteify(s: OsString) -> Vec { /// # Examples /// /// ``` +/// # #![feature(os)] /// use std::os; /// /// let key = "KEY"; @@ -265,6 +269,7 @@ pub fn unsetenv(n: &str) { /// # Examples /// /// ``` +/// # #![feature(old_path, os)] /// use std::os; /// use std::old_path::{Path, GenericPath}; /// @@ -298,6 +303,7 @@ pub fn split_paths(unparsed: T) -> Vec { /// # Examples /// /// ``` +/// # #![feature(os, old_path, core)] /// use std::os; /// use std::old_path::Path; /// @@ -359,6 +365,7 @@ pub fn dll_filename(base: &str) -> String { /// # Examples /// /// ``` +/// # #![feature(os, old_path)] /// use std::os; /// use std::old_path::{Path, GenericPath}; /// @@ -380,6 +387,7 @@ pub fn self_exe_name() -> Option { /// # Examples /// /// ``` +/// # #![feature(os, old_path)] /// use std::os; /// use std::old_path::{Path, GenericPath}; /// @@ -410,6 +418,7 @@ pub fn self_exe_path() -> Option { /// # Examples /// /// ``` +/// # #![feature(os, old_path)] /// use std::os; /// use std::old_path::{Path, GenericPath}; /// @@ -501,6 +510,7 @@ pub fn tmpdir() -> Path { /// # Examples /// /// ``` +/// # #![feature(os, old_path)] /// use std::os; /// use std::old_path::{Path, GenericPath}; /// @@ -533,6 +543,7 @@ pub fn make_absolute(p: &Path) -> IoResult { /// # Examples /// /// ``` +/// # #![feature(os, old_path)] /// use std::os; /// use std::old_path::{Path, GenericPath}; /// @@ -555,6 +566,7 @@ pub fn errno() -> i32 { /// # Examples /// /// ``` +/// # #![feature(os)] /// use std::os; /// /// // Same as println!("{}", last_os_error()); @@ -751,6 +763,7 @@ extern "system" { /// # Examples /// /// ``` +/// # #![feature(os)] /// use std::os; /// /// // Prints each argument on a separate line diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index 69053252ed1..656ca980624 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -58,6 +58,7 @@ //! # Examples //! //! ```rust +//! # #![feature(rand)] //! use std::rand; //! use std::rand::Rng; //! @@ -68,6 +69,7 @@ //! ``` //! //! ```rust +//! # #![feature(rand)] //! use std::rand; //! //! let tuple = rand::random::<(f64, char)>(); @@ -92,6 +94,7 @@ //! multiply this fraction by 4. //! //! ``` +//! # #![feature(rand)] //! use std::rand; //! use std::rand::distributions::{IndependentSample, Range}; //! @@ -134,6 +137,7 @@ //! [Monty Hall Problem]: http://en.wikipedia.org/wiki/Monty_Hall_problem //! //! ``` +//! # #![feature(rand)] //! use std::rand; //! use std::rand::Rng; //! use std::rand::distributions::{IndependentSample, Range}; @@ -384,6 +388,7 @@ impl Rng for ThreadRng { /// # Examples /// /// ``` +/// # #![feature(rand)] /// use std::rand; /// /// let x: u8 = rand::random(); @@ -400,6 +405,7 @@ impl Rng for ThreadRng { /// Caching the thread local random number generator: /// /// ``` +/// # #![feature(rand)] /// use std::rand; /// use std::rand::Rng; /// @@ -427,6 +433,7 @@ pub fn random() -> T { /// # Examples /// /// ``` +/// # #![feature(rand)] /// use std::rand::{thread_rng, sample}; /// /// let mut rng = thread_rng(); diff --git a/src/libstd/rand/reader.rs b/src/libstd/rand/reader.rs index 5231b122b9e..d3a8fa864fc 100644 --- a/src/libstd/rand/reader.rs +++ b/src/libstd/rand/reader.rs @@ -24,6 +24,7 @@ use result::Result::{Ok, Err}; /// # Examples /// /// ``` +/// # #![feature(rand, old_io)] /// use std::rand::{reader, Rng}; /// use std::old_io::MemReader; /// diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs index 4430cc3b0af..69c5267ab69 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -69,6 +69,7 @@ pub struct Condvar { inner: Box } /// # Examples /// /// ``` +/// # #![feature(std_misc)] /// use std::sync::{StaticCondvar, CONDVAR_INIT}; /// /// static CVAR: StaticCondvar = CONDVAR_INIT; diff --git a/src/libstd/sync/future.rs b/src/libstd/sync/future.rs index ee9bcd3dd89..3c7fecb7515 100644 --- a/src/libstd/sync/future.rs +++ b/src/libstd/sync/future.rs @@ -14,6 +14,7 @@ //! # Examples //! //! ``` +//! # #![feature(std_misc)] //! use std::sync::Future; //! //! // a fake, for now diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 123dad978f5..cb8acf14e13 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -119,6 +119,7 @@ //! after 10 seconds no matter what: //! //! ```no_run +//! # #![feature(std_misc, old_io)] //! use std::sync::mpsc::channel; //! use std::old_io::timer::Timer; //! use std::time::Duration; @@ -143,6 +144,7 @@ //! has been inactive for 5 seconds: //! //! ```no_run +//! # #![feature(std_misc, old_io)] //! use std::sync::mpsc::channel; //! use std::old_io::timer::Timer; //! use std::time::Duration; diff --git a/src/libstd/sync/mpsc/select.rs b/src/libstd/sync/mpsc/select.rs index b5739c36aa9..0f936641cdc 100644 --- a/src/libstd/sync/mpsc/select.rs +++ b/src/libstd/sync/mpsc/select.rs @@ -27,6 +27,7 @@ //! # Examples //! //! ```rust +//! # #![feature(std_misc)] //! use std::sync::mpsc::channel; //! //! let (tx1, rx1) = channel(); @@ -119,6 +120,7 @@ impl Select { /// # Examples /// /// ``` + /// # #![feature(std_misc)] /// use std::sync::mpsc::Select; /// /// let select = Select::new(); diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index 130fd1d7dc8..2bf75cf1d37 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -85,6 +85,7 @@ use fmt; /// To recover from a poisoned mutex: /// /// ``` +/// # #![feature(std_misc)] /// use std::sync::{Arc, Mutex}; /// use std::thread; /// @@ -136,6 +137,7 @@ unsafe impl Sync for Mutex { } /// # Examples /// /// ``` +/// # #![feature(std_misc)] /// use std::sync::{StaticMutex, MUTEX_INIT}; /// /// static LOCK: StaticMutex = MUTEX_INIT; diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 368e88e4e8b..6e94db6d753 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -77,6 +77,7 @@ unsafe impl Sync for RwLock {} /// # Examples /// /// ``` +/// # #![feature(std_misc)] /// use std::sync::{StaticRwLock, RW_LOCK_INIT}; /// /// static LOCK: StaticRwLock = RW_LOCK_INIT; diff --git a/src/libstd/sync/semaphore.rs b/src/libstd/sync/semaphore.rs index 2f9873950b6..059cce57245 100644 --- a/src/libstd/sync/semaphore.rs +++ b/src/libstd/sync/semaphore.rs @@ -25,6 +25,7 @@ use sync::{Mutex, Condvar}; /// # Examples /// /// ``` +/// # #![feature(std_misc)] /// use std::sync::Semaphore; /// /// // Create a semaphore that represents 5 resources diff --git a/src/libstd/sync/task_pool.rs b/src/libstd/sync/task_pool.rs index 8a1946b86ab..51cf70e615b 100644 --- a/src/libstd/sync/task_pool.rs +++ b/src/libstd/sync/task_pool.rs @@ -61,6 +61,7 @@ impl<'a> Drop for Sentinel<'a> { /// # Examples /// /// ``` +/// # #![feature(std_misc, core)] /// use std::sync::TaskPool; /// use std::iter::AdditiveIterator; /// use std::sync::mpsc::channel; diff --git a/src/libstd/thread_local/scoped.rs b/src/libstd/thread_local/scoped.rs index 86e6c059a70..34b581f7fda 100644 --- a/src/libstd/thread_local/scoped.rs +++ b/src/libstd/thread_local/scoped.rs @@ -24,6 +24,7 @@ //! # Examples //! //! ``` +//! # #![feature(std_misc)] //! scoped_thread_local!(static FOO: u32); //! //! // Initially each scoped slot is empty. @@ -142,6 +143,7 @@ impl Key { /// # Examples /// /// ``` + /// # #![feature(std_misc)] /// scoped_thread_local!(static FOO: u32); /// /// FOO.set(&100, || { @@ -194,6 +196,7 @@ impl Key { /// # Examples /// /// ```no_run + /// # #![feature(std_misc)] /// scoped_thread_local!(static FOO: u32); /// /// FOO.with(|slot| { diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index f517dca53cd..990ce769d9b 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -19,6 +19,7 @@ //! # Examples //! //! ```no_run +//! # #![feature(rustc_private)] //! extern crate term; //! //! use std::io::prelude::*; diff --git a/src/libunicode/char.rs b/src/libunicode/char.rs index e0f013cbc80..db5a25b9bed 100644 --- a/src/libunicode/char.rs +++ b/src/libunicode/char.rs @@ -209,6 +209,7 @@ pub trait CharExt { /// In both of these examples, 'ß' takes two bytes to encode. /// /// ``` + /// # #![feature(unicode)] /// let mut b = [0; 2]; /// /// let result = 'ß'.encode_utf8(&mut b); @@ -219,6 +220,7 @@ pub trait CharExt { /// A buffer that's too small: /// /// ``` + /// # #![feature(unicode)] /// let mut b = [0; 1]; /// /// let result = 'ß'.encode_utf8(&mut b); @@ -241,6 +243,7 @@ pub trait CharExt { /// In both of these examples, 'ß' takes one `u16` to encode. /// /// ``` + /// # #![feature(unicode)] /// let mut b = [0; 1]; /// /// let result = 'ß'.encode_utf16(&mut b); @@ -251,6 +254,7 @@ pub trait CharExt { /// A buffer that's too small: /// /// ``` + /// # #![feature(unicode)] /// let mut b = [0; 0]; /// /// let result = 'ß'.encode_utf8(&mut b); diff --git a/src/libunicode/lib.rs b/src/libunicode/lib.rs index a09c0cb3bd6..6879fa7b3ba 100644 --- a/src/libunicode/lib.rs +++ b/src/libunicode/lib.rs @@ -35,6 +35,7 @@ #![feature(no_std)] #![no_std] #![feature(core)] +#![doc(test(no_crate_inject))] extern crate core; diff --git a/src/libunicode/u_str.rs b/src/libunicode/u_str.rs index 485065685f1..de3a593143e 100644 --- a/src/libunicode/u_str.rs +++ b/src/libunicode/u_str.rs @@ -481,19 +481,24 @@ impl<'a> Iterator for Utf16Items<'a> { /// # Examples /// /// ``` +/// # #![feature(unicode)] +/// extern crate unicode; +/// /// use unicode::str::Utf16Item::{ScalarValue, LoneSurrogate}; /// -/// // 𝄞music -/// let v = [0xD834, 0xDD1E, 0x006d, 0x0075, -/// 0x0073, 0xDD1E, 0x0069, 0x0063, -/// 0xD834]; +/// fn main() { +/// // 𝄞music +/// let v = [0xD834, 0xDD1E, 0x006d, 0x0075, +/// 0x0073, 0xDD1E, 0x0069, 0x0063, +/// 0xD834]; /// -/// assert_eq!(unicode::str::utf16_items(&v).collect::>(), -/// vec![ScalarValue('𝄞'), -/// ScalarValue('m'), ScalarValue('u'), ScalarValue('s'), -/// LoneSurrogate(0xDD1E), -/// ScalarValue('i'), ScalarValue('c'), -/// LoneSurrogate(0xD834)]); +/// assert_eq!(unicode::str::utf16_items(&v).collect::>(), +/// vec![ScalarValue('𝄞'), +/// ScalarValue('m'), ScalarValue('u'), ScalarValue('s'), +/// LoneSurrogate(0xDD1E), +/// ScalarValue('i'), ScalarValue('c'), +/// LoneSurrogate(0xD834)]); +/// } /// ``` pub fn utf16_items<'a>(v: &'a [u16]) -> Utf16Items<'a> { Utf16Items { iter : v.iter() } diff --git a/src/test/pretty/default-trait-impl.rs b/src/test/pretty/default-trait-impl.rs index d148bb15e99..509bee9def2 100644 --- a/src/test/pretty/default-trait-impl.rs +++ b/src/test/pretty/default-trait-impl.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(optin_builtin_traits)] +#![feature(optin_builtin_traits, core)] // pp-exact -- cgit 1.4.1-3-g733a5 From 8389253df0431e58bfe0a8e0e3949d58ebe7400f Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Wed, 18 Mar 2015 09:14:54 -0700 Subject: Add generic conversion traits This commit: * Introduces `std::convert`, providing an implementation of RFC 529. * Deprecates the `AsPath`, `AsOsStr`, and `IntoBytes` traits, all in favor of the corresponding generic conversion traits. Consequently, various IO APIs now take `AsRef` rather than `AsPath`, and so on. Since the types provided by `std` implement both traits, this should cause relatively little breakage. * Deprecates many `from_foo` constructors in favor of `from`. * Changes `PathBuf::new` to take no argument (creating an empty buffer, as per convention). The previous behavior is now available as `PathBuf::from`. * De-stabilizes `IntoCow`. It's not clear whether we need this separate trait. Closes #22751 Closes #14433 [breaking-change] --- src/compiletest/compiletest.rs | 10 +- src/compiletest/header.rs | 4 +- src/compiletest/runtest.rs | 2 +- src/libcollections/borrow.rs | 11 +- src/libcollections/lib.rs | 1 + src/libcollections/slice.rs | 11 +- src/libcollections/str.rs | 28 ++--- src/libcollections/string.rs | 23 ++++ src/libcollections/vec.rs | 52 +++++++-- src/libcore/convert.rs | 113 +++++++++++++++++++ src/libcore/lib.rs | 1 + src/libcore/option.rs | 17 +++ src/libcore/prelude.rs | 1 + src/libcore/result.rs | 21 +++- src/libcore/slice.rs | 5 + src/libcore/str/mod.rs | 4 + src/libgraphviz/lib.rs | 1 + src/librustc/lib.rs | 2 + src/librustc/metadata/cstore.rs | 2 +- src/librustc/metadata/filesearch.rs | 6 +- src/librustc/metadata/loader.rs | 2 +- src/librustc/middle/traits/select.rs | 2 +- src/librustc/session/config.rs | 2 +- src/librustc/session/search_paths.rs | 2 +- src/librustc_back/archive.rs | 2 +- src/librustc_back/fs.rs | 2 +- src/librustc_back/lib.rs | 1 + src/librustc_back/rpath.rs | 2 +- src/librustc_back/target/mod.rs | 4 +- src/librustc_borrowck/lib.rs | 1 + src/librustc_driver/driver.rs | 6 +- src/librustc_driver/lib.rs | 13 ++- src/librustc_lint/builtin.rs | 4 +- src/librustc_trans/back/link.rs | 8 +- src/librustc_trans/lib.rs | 1 + src/librustc_trans/save/mod.rs | 4 +- src/librustc_trans/trans/debuginfo.rs | 2 +- src/librustc_typeck/collect.rs | 8 +- src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/externalfiles.rs | 2 +- src/librustdoc/html/render.rs | 6 +- src/librustdoc/lib.rs | 11 +- src/librustdoc/test.rs | 2 +- src/libserialize/lib.rs | 1 + src/libserialize/serialize.rs | 2 +- src/libstd/env.rs | 6 +- src/libstd/ffi/c_str.rs | 11 +- src/libstd/ffi/os_str.rs | 77 ++++++++++++- src/libstd/fs/mod.rs | 70 ++++++------ src/libstd/fs/tempdir.rs | 7 +- src/libstd/lib.rs | 3 + src/libstd/net/ip.rs | 1 - src/libstd/os.rs | 5 +- src/libstd/path.rs | 200 +++++++++++++++++++++++++++++----- src/libstd/prelude/v1.rs | 4 + src/libstd/process.rs | 6 +- src/libstd/sys/unix/fs2.rs | 3 +- src/libstd/sys/unix/os.rs | 8 +- src/libsyntax/codemap.rs | 3 +- src/libsyntax/ext/source_util.rs | 2 +- src/libsyntax/lib.rs | 2 + src/libsyntax/parse/parser.rs | 4 +- src/libterm/lib.rs | 1 + src/libterm/terminfo/searcher.rs | 12 +- src/libtest/lib.rs | 5 +- src/rustbook/book.rs | 8 +- src/rustbook/build.rs | 6 +- src/rustbook/main.rs | 1 + src/test/run-pass/env-home-dir.rs | 10 +- 69 files changed, 666 insertions(+), 196 deletions(-) create mode 100644 src/libcore/convert.rs (limited to 'src/libstd') diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 01c4e99b77c..1ee5917ac9c 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -20,6 +20,8 @@ #![feature(std_misc)] #![feature(test)] #![feature(path_ext)] +#![feature(convert)] +#![feature(str_char)] #![deny(warnings)] @@ -115,7 +117,7 @@ pub fn parse_config(args: Vec ) -> Config { fn opt_path(m: &getopts::Matches, nm: &str) -> PathBuf { match m.opt_str(nm) { - Some(s) => PathBuf::new(&s), + Some(s) => PathBuf::from(&s), None => panic!("no option (=path) found for {}", nm), } } @@ -130,10 +132,10 @@ pub fn parse_config(args: Vec ) -> Config { compile_lib_path: matches.opt_str("compile-lib-path").unwrap(), run_lib_path: matches.opt_str("run-lib-path").unwrap(), rustc_path: opt_path(matches, "rustc-path"), - clang_path: matches.opt_str("clang-path").map(|s| PathBuf::new(&s)), + clang_path: matches.opt_str("clang-path").map(|s| PathBuf::from(&s)), valgrind_path: matches.opt_str("valgrind-path"), force_valgrind: matches.opt_present("force-valgrind"), - llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| PathBuf::new(&s)), + llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| PathBuf::from(&s)), src_base: opt_path(matches, "src-base"), build_base: opt_path(matches, "build-base"), aux_base: opt_path(matches, "aux-base"), @@ -141,7 +143,7 @@ pub fn parse_config(args: Vec ) -> Config { mode: matches.opt_str("mode").unwrap().parse().ok().expect("invalid mode"), run_ignored: matches.opt_present("ignored"), filter: filter, - logfile: matches.opt_str("logfile").map(|s| PathBuf::new(&s)), + logfile: matches.opt_str("logfile").map(|s| PathBuf::from(&s)), runtool: matches.opt_str("runtool"), host_rustcflags: matches.opt_str("host-rustcflags"), target_rustcflags: matches.opt_str("target-rustcflags"), diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index 29123173f5b..e1ad66c69e4 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -328,10 +328,10 @@ fn parse_exec_env(line: &str) -> Option<(String, String)> { fn parse_pp_exact(line: &str, testfile: &Path) -> Option { match parse_name_value_directive(line, "pp-exact") { - Some(s) => Some(PathBuf::new(&s)), + Some(s) => Some(PathBuf::from(&s)), None => { if parse_name_directive(line, "pp-exact") { - testfile.file_name().map(|s| PathBuf::new(s)) + testfile.file_name().map(|s| PathBuf::from(s)) } else { None } diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index a754bd950f7..319248cb810 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -1440,7 +1440,7 @@ fn aux_output_dir_name(config: &Config, testfile: &Path) -> PathBuf { } fn output_testname(testfile: &Path) -> PathBuf { - PathBuf::new(testfile.file_stem().unwrap()) + PathBuf::from(testfile.file_stem().unwrap()) } fn output_base_name(config: &Config, testfile: &Path) -> PathBuf { diff --git a/src/libcollections/borrow.rs b/src/libcollections/borrow.rs index 4bedbdeb368..88d59f699d1 100644 --- a/src/libcollections/borrow.rs +++ b/src/libcollections/borrow.rs @@ -14,6 +14,7 @@ use core::clone::Clone; use core::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd}; +use core::convert::AsRef; use core::hash::{Hash, Hasher}; use core::marker::Sized; use core::ops::Deref; @@ -291,10 +292,9 @@ impl<'a, B: ?Sized> Hash for Cow<'a, B> where B: Hash + ToOwned } /// Trait for moving into a `Cow` -#[stable(feature = "rust1", since = "1.0.0")] +#[unstable(feature = "into_cow", reason = "may be replaced by `convert::Into`")] pub trait IntoCow<'a, B: ?Sized> where B: ToOwned { /// Moves `self` into `Cow` - #[stable(feature = "rust1", since = "1.0.0")] fn into_cow(self) -> Cow<'a, B>; } @@ -304,3 +304,10 @@ impl<'a, B: ?Sized> IntoCow<'a, B> for Cow<'a, B> where B: ToOwned { self } } + +#[stable(feature = "rust1", since = "1.0.0")] +impl<'a, T: Clone> AsRef for Cow<'a, T> { + fn as_ref(&self) -> &T { + self + } +} diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index c4a01496763..156c90f1e84 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -36,6 +36,7 @@ #![feature(unsafe_no_drop_flag)] #![feature(step_by)] #![feature(str_char)] +#![feature(convert)] #![cfg_attr(test, feature(rand, rustc_private, test))] #![cfg_attr(test, allow(deprecated))] // rand diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 45864153dd7..0a0307aef32 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -88,6 +88,7 @@ #![stable(feature = "rust1", since = "1.0.0")] use alloc::boxed::Box; +use core::convert::AsRef; use core::clone::Clone; use core::cmp::Ordering::{self, Greater, Less}; use core::cmp::{self, Ord, PartialEq}; @@ -1088,23 +1089,23 @@ pub trait SliceConcatExt { fn connect(&self, sep: &T) -> U; } -impl> SliceConcatExt> for [V] { +impl> SliceConcatExt> for [V] { fn concat(&self) -> Vec { - let size = self.iter().fold(0, |acc, v| acc + v.as_slice().len()); + let size = self.iter().fold(0, |acc, v| acc + v.as_ref().len()); let mut result = Vec::with_capacity(size); for v in self { - result.push_all(v.as_slice()) + result.push_all(v.as_ref()) } result } fn connect(&self, sep: &T) -> Vec { - let size = self.iter().fold(0, |acc, v| acc + v.as_slice().len()); + let size = self.iter().fold(0, |acc, v| acc + v.as_ref().len()); let mut result = Vec::with_capacity(size + self.len()); let mut first = true; for v in self { if first { first = false } else { result.push(sep.clone()) } - result.push_all(v.as_slice()) + result.push_all(v.as_ref()) } result } diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 3a289e4ef37..c014ddc069d 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -61,10 +61,10 @@ use core::iter::AdditiveIterator; use core::iter::{Iterator, IteratorExt, Extend}; use core::option::Option::{self, Some, None}; use core::result::Result; -use core::slice::AsSlice; use core::str as core_str; use unicode::str::{UnicodeStr, Utf16Encoder}; +use core::convert::AsRef; use vec_deque::VecDeque; use borrow::{Borrow, ToOwned}; use string::String; @@ -86,51 +86,47 @@ pub use core::str::{Searcher, ReverseSearcher, DoubleEndedSearcher, SearchStep}; Section: Creating a string */ -impl SliceConcatExt for [S] { +impl> SliceConcatExt for [S] { fn concat(&self) -> String { - let s = self.as_slice(); - - if s.is_empty() { + if self.is_empty() { return String::new(); } // `len` calculation may overflow but push_str will check boundaries - let len = s.iter().map(|s| s.as_slice().len()).sum(); + let len = self.iter().map(|s| s.as_ref().len()).sum(); let mut result = String::with_capacity(len); - for s in s { - result.push_str(s.as_slice()) + for s in self { + result.push_str(s.as_ref()) } result } fn connect(&self, sep: &str) -> String { - let s = self.as_slice(); - - if s.is_empty() { + if self.is_empty() { return String::new(); } // concat is faster if sep.is_empty() { - return s.concat(); + return self.concat(); } // this is wrong without the guarantee that `self` is non-empty // `len` calculation may overflow but push_str but will check boundaries - let len = sep.len() * (s.len() - 1) - + s.iter().map(|s| s.as_slice().len()).sum(); + let len = sep.len() * (self.len() - 1) + + self.iter().map(|s| s.as_ref().len()).sum(); let mut result = String::with_capacity(len); let mut first = true; - for s in s { + for s in self { if first { first = false; } else { result.push_str(sep); } - result.push_str(s.as_slice()); + result.push_str(s.as_ref()); } result } diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index cd6f27bf65f..6463949ac8a 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -814,6 +814,7 @@ impl<'a, 'b> PartialEq> for &'b str { } #[unstable(feature = "collections", reason = "waiting on Str stabilization")] +#[allow(deprecated)] impl Str for String { #[inline] #[stable(feature = "rust1", since = "1.0.0")] @@ -973,6 +974,27 @@ impl ToString for T { } } +#[stable(feature = "rust1", since = "1.0.0")] +impl AsRef for String { + fn as_ref(&self) -> &str { + self + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl<'a> From<&'a str> for String { + fn from(s: &'a str) -> String { + s.to_string() + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl Into> for String { + fn into(self) -> Vec { + self.into_bytes() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl IntoCow<'static, str> for String { #[inline] @@ -989,6 +1011,7 @@ impl<'a> IntoCow<'a, str> for &'a str { } } +#[allow(deprecated)] impl<'a> Str for Cow<'a, str> { #[inline] fn as_slice<'b>(&'b self) -> &'b str { diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index b0e8dc7d0b6..85833c34049 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1369,7 +1369,7 @@ impl ops::Index for Vec { type Output = [T]; #[inline] fn index(&self, _index: &ops::RangeFull) -> &[T] { - self.as_slice() + self } } @@ -1406,7 +1406,13 @@ impl ops::IndexMut for Vec { impl ops::Deref for Vec { type Target = [T]; - fn deref(&self) -> &[T] { self.as_slice() } + fn deref(&self) -> &[T] { + unsafe { + let p = *self.ptr; + assume(p != 0 as *mut T); + slice::from_raw_parts(p, self.len) + } + } } #[stable(feature = "rust1", since = "1.0.0")] @@ -1548,6 +1554,7 @@ impl Ord for Vec { } } +#[allow(deprecated)] impl AsSlice for Vec { /// Returns a slice into `self`. /// @@ -1562,11 +1569,7 @@ impl AsSlice for Vec { #[inline] #[stable(feature = "rust1", since = "1.0.0")] fn as_slice(&self) -> &[T] { - unsafe { - let p = *self.ptr; - assume(p != 0 as *mut T); - slice::from_raw_parts(p, self.len) - } + self } } @@ -1614,6 +1617,41 @@ impl fmt::Debug for Vec { } } +#[stable(feature = "rust1", since = "1.0.0")] +impl AsRef> for Vec { + fn as_ref(&self) -> &Vec { + self + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl Into> for Vec { + fn into(self) -> Vec { + self + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl AsRef<[T]> for Vec { + fn as_ref(&self) -> &[T] { + self + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl<'a, T: Clone> From<&'a [T]> for Vec { + fn from(s: &'a [T]) -> Vec { + s.to_vec() + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl<'a> From<&'a str> for Vec { + fn from(s: &'a str) -> Vec { + s.as_bytes().to_vec() + } +} + //////////////////////////////////////////////////////////////////////////////// // Clone-on-write //////////////////////////////////////////////////////////////////////////////// diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs new file mode 100644 index 00000000000..65a226d37cb --- /dev/null +++ b/src/libcore/convert.rs @@ -0,0 +1,113 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Traits for conversions between types. +//! +//! The traits in this module provide a general way to talk about +//! conversions from one type to another. They follow the standard +//! Rust conventions of `as`/`to`/`into`/`from`. + +#![unstable(feature = "convert", + reason = "recently added, experimental traits")] + +use marker::Sized; + +/// A cheap, reference-to-reference conversion. +pub trait AsRef { + /// Perform the conversion. + fn as_ref(&self) -> &T; +} + +/// A cheap, mutable reference-to-mutable reference conversion. +pub trait AsMut { + /// Perform the conversion. + fn as_mut(&mut self) -> &mut T; +} + +/// A conversion that consumes `self`, which may or may not be +/// expensive. +pub trait Into: Sized { + /// Perform the conversion. + fn into(self) -> T; +} + +/// Construct `Self` via a conversion. +pub trait From { + /// Perform the conversion. + fn from(T) -> Self; +} + +//////////////////////////////////////////////////////////////////////////////// +// GENERIC IMPLS +//////////////////////////////////////////////////////////////////////////////// + +// As implies Into +impl<'a, T: ?Sized, U: ?Sized> Into<&'a U> for &'a T where T: AsRef { + fn into(self) -> &'a U { + self.as_ref() + } +} + +// As lifts over & +impl<'a, T: ?Sized, U: ?Sized> AsRef for &'a T where T: AsRef { + fn as_ref(&self) -> &U { + >::as_ref(*self) + } +} + +// As lifts over &mut +impl<'a, T: ?Sized, U: ?Sized> AsRef for &'a mut T where T: AsRef { + fn as_ref(&self) -> &U { + >::as_ref(*self) + } +} + +// AsMut implies Into +impl<'a, T: ?Sized, U: ?Sized> Into<&'a mut U> for &'a mut T where T: AsMut { + fn into(self) -> &'a mut U { + (*self).as_mut() + } +} + +// AsMut lifts over &mut +impl<'a, T: ?Sized, U: ?Sized> AsMut for &'a mut T where T: AsMut { + fn as_mut(&mut self) -> &mut U { + (*self).as_mut() + } +} + +// From implies Into +impl Into for T where U: From { + fn into(self) -> U { + U::from(self) + } +} + +//////////////////////////////////////////////////////////////////////////////// +// CONCRETE IMPLS +//////////////////////////////////////////////////////////////////////////////// + +impl AsRef<[T]> for [T] { + fn as_ref(&self) -> &[T] { + self + } +} + +impl AsMut<[T]> for [T] { + fn as_mut(&mut self) -> &mut [T] { + self + } +} + +impl AsRef for str { + fn as_ref(&self) -> &str { + self + } +} diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 29cc11d5a60..e31542c183a 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -125,6 +125,7 @@ pub mod ops; pub mod cmp; pub mod clone; pub mod default; +pub mod convert; /* Core types and methods on primitives */ diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 455c68d4319..4a1e24c1f40 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -154,6 +154,7 @@ use mem; use ops::{Deref, FnOnce}; use result::Result::{Ok, Err}; use result::Result; +#[allow(deprecated)] use slice::AsSlice; use slice; @@ -701,6 +702,19 @@ impl Option { pub fn take(&mut self) -> Option { mem::replace(self, None) } + + /// Convert from `Option` to `&[T]` (without copying) + #[inline] + #[unstable(feature = "as_slice", since = "unsure of the utility here")] + pub fn as_slice<'a>(&'a self) -> &'a [T] { + match *self { + Some(ref x) => slice::ref_slice(x), + None => { + let result: &[_] = &[]; + result + } + } + } } impl<'a, T: Clone, D: Deref> Option { @@ -752,6 +766,9 @@ impl Option { #[unstable(feature = "core", reason = "waiting on the stability of the trait itself")] +#[deprecated(since = "1.0.0", + reason = "use the inherent method instead")] +#[allow(deprecated)] impl AsSlice for Option { /// Convert from `Option` to `&[T]` (without copying) #[inline] diff --git a/src/libcore/prelude.rs b/src/libcore/prelude.rs index 4bf7f85284c..424829939b9 100644 --- a/src/libcore/prelude.rs +++ b/src/libcore/prelude.rs @@ -36,6 +36,7 @@ pub use mem::drop; pub use char::CharExt; pub use clone::Clone; pub use cmp::{PartialEq, PartialOrd, Eq, Ord}; +pub use convert::{AsRef, AsMut, Into, From}; pub use iter::{Extend, IteratorExt}; pub use iter::{Iterator, DoubleEndedIterator}; pub use iter::{ExactSizeIterator}; diff --git a/src/libcore/result.rs b/src/libcore/result.rs index bc8d53e2a57..4b3cda46c1d 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -240,6 +240,7 @@ use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator, ExactSizeIterator, IntoIterator}; use ops::{FnMut, FnOnce}; use option::Option::{self, None, Some}; +#[allow(deprecated)] use slice::AsSlice; use slice; @@ -408,6 +409,20 @@ impl Result { } } + /// Convert from `Result` to `&[T]` (without copying) + #[inline] + #[unstable(feature = "as_slice", since = "unsure of the utility here")] + pub fn as_slice(&self) -> &[T] { + match *self { + Ok(ref x) => slice::ref_slice(x), + Err(_) => { + // work around lack of implicit coercion from fixed-size array to slice + let emp: &[_] = &[]; + emp + } + } + } + /// Convert from `Result` to `&mut [T]` (without copying) /// /// ``` @@ -788,10 +803,14 @@ impl Result { // Trait implementations ///////////////////////////////////////////////////////////////////////////// +#[unstable(feature = "core", + reason = "waiting on the stability of the trait itself")] +#[deprecated(since = "1.0.0", + reason = "use inherent method instead")] +#[allow(deprecated)] impl AsSlice for Result { /// Convert from `Result` to `&[T]` (without copying) #[inline] - #[stable(feature = "rust1", since = "1.0.0")] fn as_slice<'a>(&'a self) -> &'a [T] { match *self { Ok(ref x) => slice::ref_slice(x), diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 907b2eba80c..e7535ae1d17 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -596,24 +596,29 @@ impl ops::IndexMut for [T] { /// Data that is viewable as a slice. #[unstable(feature = "core", reason = "will be replaced by slice syntax")] +#[deprecated(since = "1.0.0", + reason = "use std::convert::AsRef<[T]> instead")] pub trait AsSlice { /// Work with `self` as a slice. fn as_slice<'a>(&'a self) -> &'a [T]; } #[unstable(feature = "core", reason = "trait is experimental")] +#[allow(deprecated)] impl AsSlice for [T] { #[inline(always)] fn as_slice<'a>(&'a self) -> &'a [T] { self } } #[unstable(feature = "core", reason = "trait is experimental")] +#[allow(deprecated)] impl<'a, T, U: ?Sized + AsSlice> AsSlice for &'a U { #[inline(always)] fn as_slice(&self) -> &[T] { AsSlice::as_slice(*self) } } #[unstable(feature = "core", reason = "trait is experimental")] +#[allow(deprecated)] impl<'a, T, U: ?Sized + AsSlice> AsSlice for &'a mut U { #[inline(always)] fn as_slice(&self) -> &[T] { AsSlice::as_slice(*self) } diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index e8181395b5c..e31aebbd74e 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -1275,16 +1275,20 @@ mod traits { reason = "Instead of taking this bound generically, this trait will be \ replaced with one of slicing syntax (&foo[..]), deref coercions, or \ a more generic conversion trait")] +#[deprecated(since = "1.0.0", + reason = "use std::convert::AsRef instead")] pub trait Str { /// Work with `self` as a slice. fn as_slice<'a>(&'a self) -> &'a str; } +#[allow(deprecated)] impl Str for str { #[inline] fn as_slice<'a>(&'a self) -> &'a str { self } } +#[allow(deprecated)] impl<'a, S: ?Sized> Str for &'a S where S: Str { #[inline] fn as_slice(&self) -> &str { Str::as_slice(*self) } diff --git a/src/libgraphviz/lib.rs b/src/libgraphviz/lib.rs index 0e080459344..6d95d5e0724 100644 --- a/src/libgraphviz/lib.rs +++ b/src/libgraphviz/lib.rs @@ -280,6 +280,7 @@ html_root_url = "http://doc.rust-lang.org/nightly/")] #![feature(int_uint)] #![feature(collections)] +#![feature(into_cow)] use self::LabelText::*; diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 97ed391fdfc..793eff6a9da 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -43,6 +43,8 @@ #![feature(path_ext)] #![feature(str_words)] #![feature(str_char)] +#![feature(convert)] +#![feature(into_cow)] #![cfg_attr(test, feature(test))] extern crate arena; diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs index 47ec31c0f1a..dc9d1e11e8e 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc/metadata/cstore.rs @@ -243,7 +243,7 @@ impl crate_metadata { impl MetadataBlob { pub fn as_slice<'a>(&'a self) -> &'a [u8] { let slice = match *self { - MetadataVec(ref vec) => vec.as_slice(), + MetadataVec(ref vec) => &vec[..], MetadataArchive(ref ar) => ar.as_slice(), }; if slice.len() < 4 { diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index 22a4a6fc978..284e76b328a 100644 --- a/src/librustc/metadata/filesearch.rs +++ b/src/librustc/metadata/filesearch.rs @@ -156,7 +156,7 @@ impl<'a> FileSearch<'a> { // Returns a list of directories where target-specific tool binaries are located. pub fn get_tools_search_paths(&self) -> Vec { - let mut p = PathBuf::new(self.sysroot); + let mut p = PathBuf::from(self.sysroot); p.push(&find_libdir(self.sysroot)); p.push(&rustlibdir()); p.push(&self.triple); @@ -166,7 +166,7 @@ impl<'a> FileSearch<'a> { } pub fn relative_target_lib_path(sysroot: &Path, target_triple: &str) -> PathBuf { - let mut p = PathBuf::new(&find_libdir(sysroot)); + let mut p = PathBuf::from(&find_libdir(sysroot)); assert!(p.is_relative()); p.push(&rustlibdir()); p.push(target_triple); @@ -224,7 +224,7 @@ pub fn rust_path() -> Vec { Some(env_path) => { let env_path_components = env_path.split(PATH_ENTRY_SEPARATOR); - env_path_components.map(|s| PathBuf::new(s)).collect() + env_path_components.map(|s| PathBuf::from(s)).collect() } None => Vec::new() }; diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index e466dc8a3a0..7854db81146 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -628,7 +628,7 @@ impl<'a> Context<'a> { let mut rlibs = HashMap::new(); let mut dylibs = HashMap::new(); { - let locs = locs.iter().map(|l| PathBuf::new(&l[..])).filter(|loc| { + let locs = locs.iter().map(|l| PathBuf::from(l)).filter(|loc| { if !loc.exists() { sess.err(&format!("extern location for {} does not exist: {}", self.crate_name, loc.display())); diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs index 7dfbccea0dc..882caecb382 100644 --- a/src/librustc/middle/traits/select.rs +++ b/src/librustc/middle/traits/select.rs @@ -1762,7 +1762,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { match obligations { Ok(mut obls) => { - obls.push_all(normalized.obligations.as_slice()); + obls.push_all(&normalized.obligations); obls }, Err(ErrorReported) => Vec::new() diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index e368a669133..a7c67a08631 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -907,7 +907,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { let cg = build_codegen_options(matches); - let sysroot_opt = matches.opt_str("sysroot").map(|m| PathBuf::new(&m)); + let sysroot_opt = matches.opt_str("sysroot").map(|m| PathBuf::from(&m)); let target = matches.opt_str("target").unwrap_or( host_triple().to_string()); let opt_level = { diff --git a/src/librustc/session/search_paths.rs b/src/librustc/session/search_paths.rs index 3c5d9744505..3dc31f9524e 100644 --- a/src/librustc/session/search_paths.rs +++ b/src/librustc/session/search_paths.rs @@ -54,7 +54,7 @@ impl SearchPaths { if path.is_empty() { early_error("empty search path given via `-L`"); } - self.paths.push((kind, PathBuf::new(path))); + self.paths.push((kind, PathBuf::from(path))); } pub fn iter(&self, kind: PathKind) -> Iter { diff --git a/src/librustc_back/archive.rs b/src/librustc_back/archive.rs index aec8ac38a5a..2cc51a723f2 100644 --- a/src/librustc_back/archive.rs +++ b/src/librustc_back/archive.rs @@ -319,7 +319,7 @@ impl<'a> ArchiveBuilder<'a> { }; let new_filename = self.work_dir.path().join(&filename[..]); try!(fs::rename(&file, &new_filename)); - self.members.push(PathBuf::new(&filename)); + self.members.push(PathBuf::from(filename)); } Ok(()) } diff --git a/src/librustc_back/fs.rs b/src/librustc_back/fs.rs index c29cbb352a3..6d8891dd4fe 100644 --- a/src/librustc_back/fs.rs +++ b/src/librustc_back/fs.rs @@ -19,7 +19,7 @@ use std::path::{Path, PathBuf}; pub fn realpath(original: &Path) -> io::Result { let old = old_path::Path::new(original.to_str().unwrap()); match old_realpath(&old) { - Ok(p) => Ok(PathBuf::new(p.as_str().unwrap())), + Ok(p) => Ok(PathBuf::from(p.as_str().unwrap())), Err(e) => Err(io::Error::new(io::ErrorKind::Other, "realpath error", Some(e.to_string()))) diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs index 99d24a60130..086742f740c 100644 --- a/src/librustc_back/lib.rs +++ b/src/librustc_back/lib.rs @@ -49,6 +49,7 @@ #![feature(std_misc)] #![feature(path_relative_from)] #![feature(step_by)] +#![feature(convert)] extern crate syntax; extern crate serialize; diff --git a/src/librustc_back/rpath.rs b/src/librustc_back/rpath.rs index 4f9f1447d8a..8dd65c5b893 100644 --- a/src/librustc_back/rpath.rs +++ b/src/librustc_back/rpath.rs @@ -106,7 +106,7 @@ fn get_rpath_relative_to_output(config: &mut RPathConfig, lib: &Path) -> String } fn relativize(path: &Path, rel: &Path) -> PathBuf { - let mut res = PathBuf::new(""); + let mut res = PathBuf::new(); let mut cur = rel; while !path.starts_with(cur) { res.push(".."); diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index 4663901a7b4..c464658f447 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -393,11 +393,11 @@ impl Target { let path = { let mut target = target.to_string(); target.push_str(".json"); - PathBuf::new(&target) + PathBuf::from(target) }; let target_path = env::var_os("RUST_TARGET_PATH") - .unwrap_or(OsString::from_str("")); + .unwrap_or(OsString::new()); // FIXME 16351: add a sane default search path? diff --git a/src/librustc_borrowck/lib.rs b/src/librustc_borrowck/lib.rs index e09457970e1..e927ea5b86c 100644 --- a/src/librustc_borrowck/lib.rs +++ b/src/librustc_borrowck/lib.rs @@ -28,6 +28,7 @@ #![feature(rustc_private)] #![feature(staged_api)] #![feature(unsafe_destructor)] +#![feature(into_cow)] #[macro_use] extern crate log; #[macro_use] extern crate syntax; diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index dc27a301109..4c654cbf27d 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -468,7 +468,7 @@ pub fn phase_2_configure_and_expand(sess: &Session, // dependent dlls. Note that this uses cfg!(windows) as opposed to // targ_cfg because syntax extensions are always loaded for the host // compiler, not for the target. - let mut _old_path = OsString::from_str(""); + let mut _old_path = OsString::new(); if cfg!(windows) { _old_path = env::var_os("PATH").unwrap_or(_old_path); let mut new_path = sess.host_filesearch(PathKind::All).get_dylib_search_paths(); @@ -752,7 +752,7 @@ pub fn phase_5_run_llvm_passes(sess: &Session, pub fn phase_6_link_output(sess: &Session, trans: &trans::CrateTranslation, outputs: &OutputFilenames) { - let old_path = env::var_os("PATH").unwrap_or(OsString::from_str("")); + let old_path = env::var_os("PATH").unwrap_or(OsString::new()); let mut new_path = sess.host_filesearch(PathKind::All).get_tools_search_paths(); new_path.extend(env::split_paths(&old_path)); env::set_var("PATH", &env::join_paths(new_path.iter()).unwrap()); @@ -927,7 +927,7 @@ pub fn build_output_filenames(input: &Input, // We want to toss everything after the final '.' let dirpath = match *odir { Some(ref d) => d.clone(), - None => PathBuf::new("") + None => PathBuf::new() }; // If a crate name is present, we use it as the link name diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 0071e4434ef..5e6f2fb835b 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -39,6 +39,7 @@ #![feature(io)] #![feature(set_stdio)] #![feature(unicode)] +#![feature(convert)] extern crate arena; extern crate flate; @@ -163,8 +164,8 @@ pub fn run_compiler<'a>(args: &[String], // Extract output directory and file from matches. fn make_output(matches: &getopts::Matches) -> (Option, Option) { - let odir = matches.opt_str("out-dir").map(|o| PathBuf::new(&o)); - let ofile = matches.opt_str("o").map(|o| PathBuf::new(&o)); + let odir = matches.opt_str("out-dir").map(|o| PathBuf::from(&o)); + let ofile = matches.opt_str("o").map(|o| PathBuf::from(&o)); (odir, ofile) } @@ -177,7 +178,7 @@ fn make_input(free_matches: &[String]) -> Option<(Input, Option)> { io::stdin().read_to_string(&mut src).unwrap(); Some((Input::Str(src), None)) } else { - Some((Input::File(PathBuf::new(ifile)), Some(PathBuf::new(ifile)))) + Some((Input::File(PathBuf::from(ifile)), Some(PathBuf::from(ifile)))) } } else { None @@ -858,9 +859,9 @@ pub fn diagnostics_registry() -> diagnostics::registry::Registry { use syntax::diagnostics::registry::Registry; let all_errors = Vec::new() + - rustc::diagnostics::DIAGNOSTICS.as_slice() + - rustc_typeck::diagnostics::DIAGNOSTICS.as_slice() + - rustc_resolve::diagnostics::DIAGNOSTICS.as_slice(); + &rustc::diagnostics::DIAGNOSTICS[..] + + &rustc_typeck::diagnostics::DIAGNOSTICS[..] + + &rustc_resolve::diagnostics::DIAGNOSTICS[..]; Registry::new(&*all_errors) } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index f6f82c65374..7958dabe74e 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -2056,7 +2056,7 @@ impl LintPass for InvalidNoMangleItems { } }, ast::ItemStatic(..) => { - if attr::contains_name(it.attrs.as_slice(), "no_mangle") && + if attr::contains_name(&it.attrs, "no_mangle") && !cx.exported_items.contains(&it.id) { let msg = format!("static {} is marked #[no_mangle], but not exported", it.ident); @@ -2064,7 +2064,7 @@ impl LintPass for InvalidNoMangleItems { } }, ast::ItemConst(..) => { - if attr::contains_name(it.attrs.as_slice(), "no_mangle") { + if attr::contains_name(&it.attrs, "no_mangle") { // Const items do not refer to a particular location in memory, and therefore // don't have anything to attach a symbol to let msg = "const items should never be #[no_mangle], consider instead using \ diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index 34a23f3efac..c0a2e24d6f5 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -877,7 +877,7 @@ fn link_args(cmd: &mut Command, if t.options.is_like_osx { let morestack = lib_path.join("libmorestack.a"); - let mut v = OsString::from_str("-Wl,-force_load,"); + let mut v = OsString::from("-Wl,-force_load,"); v.push(&morestack); cmd.arg(&v); } else { @@ -1002,7 +1002,7 @@ fn link_args(cmd: &mut Command, cmd.args(&["-dynamiclib", "-Wl,-dylib"]); if sess.opts.cg.rpath { - let mut v = OsString::from_str("-Wl,-install_name,@rpath/"); + let mut v = OsString::from("-Wl,-install_name,@rpath/"); v.push(out_filename.file_name().unwrap()); cmd.arg(&v); } @@ -1020,7 +1020,7 @@ fn link_args(cmd: &mut Command, let mut get_install_prefix_lib_path = || { let install_prefix = option_env!("CFG_PREFIX").expect("CFG_PREFIX"); let tlib = filesearch::relative_target_lib_path(sysroot, target_triple); - let mut path = PathBuf::new(install_prefix); + let mut path = PathBuf::from(install_prefix); path.push(&tlib); path @@ -1102,7 +1102,7 @@ fn add_local_native_libraries(cmd: &mut Command, sess: &Session) { &sess.target.target.options.staticlib_suffix, &search_path[..], &sess.diagnostic().handler); - let mut v = OsString::from_str("-Wl,-force_load,"); + let mut v = OsString::from("-Wl,-force_load,"); v.push(&lib); cmd.arg(&v); } diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index efc81da560b..176e3805a31 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -41,6 +41,7 @@ #![feature(path_ext)] #![feature(fs)] #![feature(hash)] +#![feature(convert)] #![feature(path_relative_from)] extern crate arena; diff --git a/src/librustc_trans/save/mod.rs b/src/librustc_trans/save/mod.rs index 83bb5efb425..765e93f5b82 100644 --- a/src/librustc_trans/save/mod.rs +++ b/src/librustc_trans/save/mod.rs @@ -1509,10 +1509,10 @@ pub fn process_crate(sess: &Session, // find a path to dump our data to let mut root_path = match env::var_os("DXR_RUST_TEMP_FOLDER") { - Some(val) => PathBuf::new(&val), + Some(val) => PathBuf::from(val), None => match odir { Some(val) => val.join("dxr"), - None => PathBuf::new("dxr-temp"), + None => PathBuf::from("dxr-temp"), }, }; diff --git a/src/librustc_trans/trans/debuginfo.rs b/src/librustc_trans/trans/debuginfo.rs index 3e8cc46e255..b9c59a0bc78 100644 --- a/src/librustc_trans/trans/debuginfo.rs +++ b/src/librustc_trans/trans/debuginfo.rs @@ -1695,7 +1695,7 @@ fn declare_local<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, }; let name = CString::new(name.as_bytes()).unwrap(); - match (variable_access, [].as_slice()) { + match (variable_access, &[][..]) { (DirectVariable { alloca }, address_operations) | (IndirectVariable {alloca, address_operations}, _) => { let metadata = unsafe { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 97cc3ac7c48..f1352cacae4 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -690,7 +690,7 @@ fn convert_field<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, } } -fn convert_associated_type<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, +fn as_refsociated_type<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, container: ImplOrTraitItemContainer, ident: ast::Ident, id: ast::NodeId, @@ -835,7 +835,7 @@ fn convert_item(ccx: &CrateCtxt, it: &ast::Item) { "associated items are not allowed in inherent impls"); } - convert_associated_type(ccx, ImplContainer(local_def(it.id)), + as_refsociated_type(ccx, ImplContainer(local_def(it.id)), impl_item.ident, impl_item.id, impl_item.vis); let typ = ccx.icx(&ty_predicates).to_ty(&ExplicitRscope, ty); @@ -917,7 +917,7 @@ fn convert_item(ccx: &CrateCtxt, it: &ast::Item) { match trait_item.node { ast::MethodTraitItem(..) => {} ast::TypeTraitItem(..) => { - convert_associated_type(ccx, TraitContainer(local_def(it.id)), + as_refsociated_type(ccx, TraitContainer(local_def(it.id)), trait_item.ident, trait_item.id, ast::Public); } } @@ -1987,7 +1987,7 @@ fn conv_param_bounds<'a,'tcx>(astconv: &AstConv<'tcx>, builtin_bounds, trait_bounds, region_bounds - } = astconv::partition_bounds(tcx, span, ast_bounds.as_slice()); + } = astconv::partition_bounds(tcx, span, &ast_bounds); let mut projection_bounds = Vec::new(); diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 421549f8b7e..8e9408c9ebc 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -188,7 +188,7 @@ impl<'a, 'tcx> Clean for visit_ast::RustdocVisitor<'a, 'tcx> { let src = match cx.input { Input::File(ref path) => path.clone(), - Input::Str(_) => PathBuf::new("") // FIXME: this is wrong + Input::Str(_) => PathBuf::new() // FIXME: this is wrong }; Crate { diff --git a/src/librustdoc/externalfiles.rs b/src/librustdoc/externalfiles.rs index c2b6c940cae..57cb87e1b2d 100644 --- a/src/librustdoc/externalfiles.rs +++ b/src/librustdoc/externalfiles.rs @@ -47,7 +47,7 @@ pub fn load_string(input: &Path) -> io::Result> { macro_rules! load_or_return { ($input: expr, $cant_read: expr, $not_utf8: expr) => { { - let input = PathBuf::new($input); + let input = PathBuf::from(&$input[..]); match ::externalfiles::load_string(&input) { Err(e) => { let _ = writeln!(&mut io::stderr(), diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 81daac7b90f..d9b40fb6ba6 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -300,7 +300,7 @@ pub fn run(mut krate: clean::Crate, passes: HashSet) -> io::Result<()> { let src_root = match krate.src.parent() { Some(p) => p.to_path_buf(), - None => PathBuf::new(""), + None => PathBuf::new(), }; let mut cx = Context { dst: dst, @@ -784,7 +784,7 @@ impl<'a> DocFolder for SourceCollector<'a> { impl<'a> SourceCollector<'a> { /// Renders the given filename into its corresponding HTML source file. fn emit_source(&mut self, filename: &str) -> io::Result<()> { - let p = PathBuf::new(filename); + let p = PathBuf::from(filename); // If we couldn't open this file, then just returns because it // probably means that it's some standard library macro thing and we @@ -819,7 +819,7 @@ impl<'a> SourceCollector<'a> { let mut fname = p.file_name().expect("source has no filename") .to_os_string(); fname.push(".html"); - cur.push(&fname); + cur.push(&fname[..]); let mut w = BufWriter::new(try!(File::create(&cur))); let title = format!("{} -- source", cur.file_name().unwrap() diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index d747ed3f119..12baa849cc9 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -38,6 +38,7 @@ #![feature(file_path)] #![feature(path_ext)] #![feature(path_relative_from)] +#![feature(convert)] extern crate arena; extern crate getopts; @@ -251,7 +252,7 @@ pub fn main_args(args: &[String]) -> int { let should_test = matches.opt_present("test"); let markdown_input = input.ends_with(".md") || input.ends_with(".markdown"); - let output = matches.opt_str("o").map(|s| PathBuf::new(&s)); + let output = matches.opt_str("o").map(|s| PathBuf::from(&s)); let cfgs = matches.opt_strs("cfg"); let external_html = match ExternalHtml::load( @@ -271,7 +272,7 @@ pub fn main_args(args: &[String]) -> int { return test::run(input, cfgs, libs, externs, test_args, crate_name) } (false, true) => return markdown::render(input, - output.unwrap_or(PathBuf::new("doc")), + output.unwrap_or(PathBuf::from("doc")), &matches, &external_html, !matches.opt_present("markdown-no-toc")), (false, false) => {} @@ -289,7 +290,7 @@ pub fn main_args(args: &[String]) -> int { match matches.opt_str("w").as_ref().map(|s| &**s) { Some("html") | None => { match html::render::run(krate, &external_html, - output.unwrap_or(PathBuf::new("doc")), + output.unwrap_or(PathBuf::from("doc")), passes.into_iter().collect()) { Ok(()) => {} Err(e) => panic!("failed to generate documentation: {}", e), @@ -297,7 +298,7 @@ pub fn main_args(args: &[String]) -> int { } Some("json") => { match json_output(krate, json_plugins, - output.unwrap_or(PathBuf::new("doc.json"))) { + output.unwrap_or(PathBuf::from("doc.json"))) { Ok(()) => {} Err(e) => panic!("failed to write json: {}", e), } @@ -376,7 +377,7 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche let cfgs = matches.opt_strs("cfg"); let triple = matches.opt_str("target"); - let cr = PathBuf::new(cratefile); + let cr = PathBuf::from(cratefile); info!("starting to run rustc"); let (tx, rx) = channel(); diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index e2f8a6f82c6..0b79fa7970d 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -46,7 +46,7 @@ pub fn run(input: &str, mut test_args: Vec, crate_name: Option) -> int { - let input_path = PathBuf::new(input); + let input_path = PathBuf::from(input); let input = config::Input::File(input_path.clone()); let sessopts = config::Options { diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index 90cb88046e5..f320f723c2e 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -37,6 +37,7 @@ Core encoding and decoding interfaces. #![feature(std_misc)] #![feature(unicode)] #![feature(str_char)] +#![feature(convert)] #![cfg_attr(test, feature(test))] // test harness access diff --git a/src/libserialize/serialize.rs b/src/libserialize/serialize.rs index 71f9e01706d..5e9baa9b9e9 100644 --- a/src/libserialize/serialize.rs +++ b/src/libserialize/serialize.rs @@ -579,7 +579,7 @@ impl Encodable for path::PathBuf { impl Decodable for path::PathBuf { fn decode(d: &mut D) -> Result { let bytes: String = try!(Decodable::decode(d)); - Ok(path::PathBuf::new(&bytes)) + Ok(path::PathBuf::from(bytes)) } } diff --git a/src/libstd/env.rs b/src/libstd/env.rs index 24882c7f7ab..9d6933ce9c8 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -23,7 +23,7 @@ use error::Error; use ffi::{OsString, AsOsStr}; use fmt; use io; -use path::{AsPath, PathBuf}; +use path::{self, Path, PathBuf}; use sync::atomic::{AtomicIsize, ATOMIC_ISIZE_INIT, Ordering}; use sync::{StaticMutex, MUTEX_INIT}; use sys::os as os_imp; @@ -67,8 +67,8 @@ pub fn current_dir() -> io::Result { /// println!("Successfully changed working directory to {}!", root.display()); /// ``` #[stable(feature = "env", since = "1.0.0")] -pub fn set_current_dir(p: &P) -> io::Result<()> { - os_imp::chdir(p.as_path()) +pub fn set_current_dir + ?Sized>(p: &P) -> io::Result<()> { + os_imp::chdir(p.as_ref()) } static ENV_LOCK: StaticMutex = MUTEX_INIT; diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index fc4f03ff3a5..1760445a0fc 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -10,6 +10,7 @@ #![unstable(feature = "std_misc")] +use convert::Into; use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering}; use error::{Error, FromError}; use fmt; @@ -130,6 +131,8 @@ pub struct NulError(usize, Vec); /// A conversion trait used by the constructor of `CString` for types that can /// be converted to a vector of bytes. +#[deprecated(since = "1.0.0", reason = "use std::convert::Into> instead")] +#[unstable(feature = "std_misc")] pub trait IntoBytes { /// Consumes this container, returning a vector of bytes. fn into_bytes(self) -> Vec; @@ -163,8 +166,8 @@ impl CString { /// internal 0 byte. The error returned will contain the bytes as well as /// the position of the nul byte. #[stable(feature = "rust1", since = "1.0.0")] - pub fn new(t: T) -> Result { - let bytes = t.into_bytes(); + pub fn new>>(t: T) -> Result { + let bytes = t.into(); match bytes.iter().position(|x| *x == 0) { Some(i) => Err(NulError(i, bytes)), None => Ok(unsafe { CString::from_vec_unchecked(bytes) }), @@ -433,15 +436,19 @@ pub unsafe fn c_str_to_bytes_with_nul<'a>(raw: &'a *const libc::c_char) slice::from_raw_parts(*(raw as *const _ as *const *const u8), len as usize) } +#[allow(deprecated)] impl<'a> IntoBytes for &'a str { fn into_bytes(self) -> Vec { self.as_bytes().to_vec() } } +#[allow(deprecated)] impl<'a> IntoBytes for &'a [u8] { fn into_bytes(self) -> Vec { self.to_vec() } } +#[allow(deprecated)] impl IntoBytes for String { fn into_bytes(self) -> Vec { self.into_bytes() } } +#[allow(deprecated)] impl IntoBytes for Vec { fn into_bytes(self) -> Vec { self } } diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index feacbf1e98b..4d411046632 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -63,16 +63,18 @@ pub struct OsStr { impl OsString { /// Constructs an `OsString` at no cost by consuming a `String`. #[stable(feature = "rust1", since = "1.0.0")] + #[deprecated(since = "1.0.0", reason = "use `from` instead")] pub fn from_string(s: String) -> OsString { - OsString { inner: Buf::from_string(s) } + OsString::from(s) } /// Constructs an `OsString` by copying from a `&str` slice. /// /// Equivalent to: `OsString::from_string(String::from_str(s))`. #[stable(feature = "rust1", since = "1.0.0")] + #[deprecated(since = "1.0.0", reason = "use `from` instead")] pub fn from_str(s: &str) -> OsString { - OsString { inner: Buf::from_str(s) } + OsString::from(s) } /// Constructs a new empty `OsString`. @@ -98,8 +100,36 @@ impl OsString { /// Extend the string with the given `&OsStr` slice. #[stable(feature = "rust1", since = "1.0.0")] - pub fn push(&mut self, s: &T) { - self.inner.push_slice(&s.as_os_str().inner) + pub fn push>(&mut self, s: T) { + self.inner.push_slice(&s.as_ref().inner) + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl From for OsString { + fn from(s: String) -> OsString { + OsString { inner: Buf::from_string(s) } + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl<'a> From<&'a String> for OsString { + fn from(s: &'a String) -> OsString { + OsString { inner: Buf::from_str(s) } + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl<'a> From<&'a str> for OsString { + fn from(s: &'a str) -> OsString { + OsString { inner: Buf::from_str(s) } + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl<'a> From<&'a OsStr> for OsString { + fn from(s: &'a OsStr) -> OsString { + OsString { inner: s.inner.to_owned() } } } @@ -316,37 +346,76 @@ impl ToOwned for OsStr { } #[stable(feature = "rust1", since = "1.0.0")] +#[deprecated(since = "1.0.0", reason = "trait is deprecated")] impl<'a, T: AsOsStr + ?Sized> AsOsStr for &'a T { fn as_os_str(&self) -> &OsStr { (*self).as_os_str() } } +#[stable(feature = "rust1", since = "1.0.0")] +#[deprecated(since = "1.0.0", reason = "trait is deprecated")] impl AsOsStr for OsStr { fn as_os_str(&self) -> &OsStr { self } } +#[stable(feature = "rust1", since = "1.0.0")] +#[deprecated(since = "1.0.0", reason = "trait is deprecated")] impl AsOsStr for OsString { fn as_os_str(&self) -> &OsStr { &self[..] } } +#[stable(feature = "rust1", since = "1.0.0")] +#[deprecated(since = "1.0.0", reason = "trait is deprecated")] impl AsOsStr for str { fn as_os_str(&self) -> &OsStr { OsStr::from_str(self) } } +#[stable(feature = "rust1", since = "1.0.0")] +#[deprecated(since = "1.0.0", reason = "trait is deprecated")] impl AsOsStr for String { fn as_os_str(&self) -> &OsStr { OsStr::from_str(&self[..]) } } +#[stable(feature = "rust1", since = "1.0.0")] +impl AsRef for OsStr { + fn as_ref(&self) -> &OsStr { + self + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl AsRef for OsString { + fn as_ref(&self) -> &OsStr { + self + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl AsRef for str { + fn as_ref(&self) -> &OsStr { + OsStr::from_str(self) + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl AsRef for String { + fn as_ref(&self) -> &OsStr { + OsStr::from_str(&self[..]) + } +} + #[allow(deprecated)] +#[stable(feature = "rust1", since = "1.0.0")] +#[deprecated(since = "1.0.0", reason = "trait is deprecated")] impl AsOsStr for Path { #[cfg(unix)] fn as_os_str(&self) -> &OsStr { diff --git a/src/libstd/fs/mod.rs b/src/libstd/fs/mod.rs index 7df6d6887a2..ab65004f5d1 100644 --- a/src/libstd/fs/mod.rs +++ b/src/libstd/fs/mod.rs @@ -20,7 +20,7 @@ use core::prelude::*; use io::{self, Error, ErrorKind, SeekFrom, Seek, Read, Write}; -use path::{AsPath, Path, PathBuf}; +use path::{Path, PathBuf}; use sys::fs2 as fs_imp; use sys_common::{AsInnerMut, FromInner, AsInner}; use vec::Vec; @@ -129,7 +129,7 @@ impl File { /// This function will return an error if `path` does not already exist. /// Other errors may also be returned according to `OpenOptions::open`. #[stable(feature = "rust1", since = "1.0.0")] - pub fn open(path: P) -> io::Result { + pub fn open>(path: P) -> io::Result { OpenOptions::new().read(true).open(path) } @@ -140,7 +140,7 @@ impl File { /// /// See the `OpenOptions::open` function for more details. #[stable(feature = "rust1", since = "1.0.0")] - pub fn create(path: P) -> io::Result { + pub fn create>(path: P) -> io::Result { OpenOptions::new().write(true).create(true).truncate(true).open(path) } @@ -302,8 +302,8 @@ impl OpenOptions { /// permissions for /// * Filesystem-level errors (full disk, etc) #[stable(feature = "rust1", since = "1.0.0")] - pub fn open(&self, path: P) -> io::Result { - let path = path.as_path(); + pub fn open>(&self, path: P) -> io::Result { + let path = path.as_ref(); let inner = try!(fs_imp::File::open(path, &self.0)); Ok(File { path: path.to_path_buf(), inner: inner }) } @@ -415,8 +415,8 @@ impl DirEntry { /// user lacks permissions to remove the file, or if some other filesystem-level /// error occurs. #[stable(feature = "rust1", since = "1.0.0")] -pub fn remove_file(path: P) -> io::Result<()> { - fs_imp::unlink(path.as_path()) +pub fn remove_file>(path: P) -> io::Result<()> { + fs_imp::unlink(path.as_ref()) } /// Given a path, query the file system to get information about a file, @@ -443,8 +443,8 @@ pub fn remove_file(path: P) -> io::Result<()> { /// permissions to perform a `metadata` call on the given `path` or if there /// is no entry in the filesystem at the provided path. #[stable(feature = "rust1", since = "1.0.0")] -pub fn metadata(path: P) -> io::Result { - fs_imp::stat(path.as_path()).map(Metadata) +pub fn metadata>(path: P) -> io::Result { + fs_imp::stat(path.as_ref()).map(Metadata) } /// Rename a file or directory to a new name. @@ -464,8 +464,8 @@ pub fn metadata(path: P) -> io::Result { /// reside on separate filesystems, or if some other intermittent I/O error /// occurs. #[stable(feature = "rust1", since = "1.0.0")] -pub fn rename(from: P, to: Q) -> io::Result<()> { - fs_imp::rename(from.as_path(), to.as_path()) +pub fn rename, Q: AsRef>(from: P, to: Q) -> io::Result<()> { + fs_imp::rename(from.as_ref(), to.as_ref()) } /// Copies the contents of one file to another. This function will also @@ -494,9 +494,9 @@ pub fn rename(from: P, to: Q) -> io::Result<()> { /// * The current process does not have the permission rights to access /// `from` or write `to` #[stable(feature = "rust1", since = "1.0.0")] -pub fn copy(from: P, to: Q) -> io::Result { - let from = from.as_path(); - let to = to.as_path(); +pub fn copy, Q: AsRef>(from: P, to: Q) -> io::Result { + let from = from.as_ref(); + let to = to.as_ref(); if !from.is_file() { return Err(Error::new(ErrorKind::InvalidInput, "the source path is not an existing file", @@ -517,16 +517,16 @@ pub fn copy(from: P, to: Q) -> io::Result { /// The `dst` path will be a link pointing to the `src` path. Note that systems /// often require these two paths to both be located on the same filesystem. #[stable(feature = "rust1", since = "1.0.0")] -pub fn hard_link(src: P, dst: Q) -> io::Result<()> { - fs_imp::link(src.as_path(), dst.as_path()) +pub fn hard_link, Q: AsRef>(src: P, dst: Q) -> io::Result<()> { + fs_imp::link(src.as_ref(), dst.as_ref()) } /// Creates a new soft link on the filesystem. /// /// The `dst` path will be a soft link pointing to the `src` path. #[stable(feature = "rust1", since = "1.0.0")] -pub fn soft_link(src: P, dst: Q) -> io::Result<()> { - fs_imp::symlink(src.as_path(), dst.as_path()) +pub fn soft_link, Q: AsRef>(src: P, dst: Q) -> io::Result<()> { + fs_imp::symlink(src.as_ref(), dst.as_ref()) } /// Reads a soft link, returning the file that the link points to. @@ -537,8 +537,8 @@ pub fn soft_link(src: P, dst: Q) -> io::Result<()> { /// reading a file that does not exist or reading a file that is not a soft /// link. #[stable(feature = "rust1", since = "1.0.0")] -pub fn read_link(path: P) -> io::Result { - fs_imp::readlink(path.as_path()) +pub fn read_link>(path: P) -> io::Result { + fs_imp::readlink(path.as_ref()) } /// Create a new, empty directory at the provided path @@ -556,8 +556,8 @@ pub fn read_link(path: P) -> io::Result { /// This function will return an error if the user lacks permissions to make a /// new directory at the provided `path`, or if the directory already exists. #[stable(feature = "rust1", since = "1.0.0")] -pub fn create_dir(path: P) -> io::Result<()> { - fs_imp::mkdir(path.as_path()) +pub fn create_dir>(path: P) -> io::Result<()> { + fs_imp::mkdir(path.as_ref()) } /// Recursively create a directory and all of its parent components if they @@ -570,8 +570,8 @@ pub fn create_dir(path: P) -> io::Result<()> { /// error conditions for when a directory is being created (after it is /// determined to not exist) are outlined by `fs::create_dir`. #[stable(feature = "rust1", since = "1.0.0")] -pub fn create_dir_all(path: P) -> io::Result<()> { - let path = path.as_path(); +pub fn create_dir_all>(path: P) -> io::Result<()> { + let path = path.as_ref(); if path.is_dir() { return Ok(()) } if let Some(p) = path.parent() { try!(create_dir_all(p)) } create_dir(path) @@ -592,8 +592,8 @@ pub fn create_dir_all(path: P) -> io::Result<()> { /// This function will return an error if the user lacks permissions to remove /// the directory at the provided `path`, or if the directory isn't empty. #[stable(feature = "rust1", since = "1.0.0")] -pub fn remove_dir(path: P) -> io::Result<()> { - fs_imp::rmdir(path.as_path()) +pub fn remove_dir>(path: P) -> io::Result<()> { + fs_imp::rmdir(path.as_ref()) } /// Removes a directory at this path, after removing all its contents. Use @@ -606,8 +606,8 @@ pub fn remove_dir(path: P) -> io::Result<()> { /// /// See `file::remove_file` and `fs::remove_dir` #[stable(feature = "rust1", since = "1.0.0")] -pub fn remove_dir_all(path: P) -> io::Result<()> { - let path = path.as_path(); +pub fn remove_dir_all>(path: P) -> io::Result<()> { + let path = path.as_ref(); for child in try!(read_dir(path)) { let child = try!(child).path(); let stat = try!(lstat(&*child)); @@ -659,8 +659,8 @@ pub fn remove_dir_all(path: P) -> io::Result<()> { /// the process lacks permissions to view the contents or if the `path` points /// at a non-directory file #[stable(feature = "rust1", since = "1.0.0")] -pub fn read_dir(path: P) -> io::Result { - fs_imp::readdir(path.as_path()).map(ReadDir) +pub fn read_dir>(path: P) -> io::Result { + fs_imp::readdir(path.as_ref()).map(ReadDir) } /// Returns an iterator that will recursively walk the directory structure @@ -675,7 +675,7 @@ pub fn read_dir(path: P) -> io::Result { reason = "the precise semantics and defaults for a recursive walk \ may change and this may end up accounting for files such \ as symlinks differently")] -pub fn walk_dir(path: P) -> io::Result { +pub fn walk_dir>(path: P) -> io::Result { let start = try!(read_dir(path)); Ok(WalkDir { cur: Some(start), stack: Vec::new() }) } @@ -761,9 +761,9 @@ impl PathExt for Path { 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")] -pub fn set_file_times(path: P, accessed: u64, +pub fn set_file_times>(path: P, accessed: u64, modified: u64) -> io::Result<()> { - fs_imp::utimes(path.as_path(), accessed, modified) + fs_imp::utimes(path.as_ref(), accessed, modified) } /// Changes the permissions found on a file or a directory. @@ -790,8 +790,8 @@ pub fn set_file_times(path: P, accessed: u64, reason = "a more granual ability to set specific permissions may \ be exposed on the Permissions structure itself and this \ method may not always exist")] -pub fn set_permissions(path: P, perm: Permissions) -> io::Result<()> { - fs_imp::set_perm(path.as_path(), perm.0) +pub fn set_permissions>(path: P, perm: Permissions) -> io::Result<()> { + fs_imp::set_perm(path.as_ref(), perm.0) } #[cfg(test)] diff --git a/src/libstd/fs/tempdir.rs b/src/libstd/fs/tempdir.rs index 8f32d7a5864..a9717e36323 100644 --- a/src/libstd/fs/tempdir.rs +++ b/src/libstd/fs/tempdir.rs @@ -18,7 +18,7 @@ use prelude::v1::*; use env; use io::{self, Error, ErrorKind}; use fs; -use path::{self, PathBuf, AsPath}; +use path::{self, PathBuf}; use rand::{thread_rng, Rng}; /// A wrapper for a path to temporary directory implementing automatic @@ -43,10 +43,9 @@ impl TempDir { /// /// If no directory can be created, `Err` is returned. #[allow(deprecated)] // rand usage - pub fn new_in(tmpdir: &P, prefix: &str) - -> io::Result { + pub fn new_in>(tmpdir: P, prefix: &str) -> io::Result { let storage; - let mut tmpdir = tmpdir.as_path(); + let mut tmpdir = tmpdir.as_ref(); if !tmpdir.is_absolute() { let cur_dir = try!(env::current_dir()); storage = cur_dir.join(tmpdir); diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index b055796ba54..1488c7969f6 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -126,8 +126,10 @@ #![feature(hash)] #![feature(int_uint)] #![feature(unique)] +#![feature(convert)] #![feature(allow_internal_unstable)] #![feature(str_char)] +#![feature(into_cow)] #![cfg_attr(test, feature(test, rustc_private))] // Don't link to std. We are std. @@ -169,6 +171,7 @@ pub use core::any; pub use core::cell; pub use core::clone; #[cfg(not(test))] pub use core::cmp; +pub use core::convert; pub use core::default; #[allow(deprecated)] pub use core::finally; diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs index 73c2464a6b2..d737ad17ff8 100644 --- a/src/libstd/net/ip.rs +++ b/src/libstd/net/ip.rs @@ -374,7 +374,6 @@ impl fmt::Display for Ipv6Addr { .iter() .map(|&seg| format!("{:x}", seg)) .collect::>() - .as_slice() .connect(":") } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 3870b8614ff..72f9338b456 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -38,6 +38,7 @@ use self::MapError::*; use boxed::Box; use clone::Clone; +use convert::From; use env; use error::{FromError, Error}; use ffi::{OsString, OsStr}; @@ -79,12 +80,12 @@ fn err2old(new: ::io::Error) -> IoError { #[cfg(windows)] fn path2new(path: &Path) -> PathBuf { - PathBuf::new(path.as_str().unwrap()) + PathBuf::from(path.as_str().unwrap()) } #[cfg(unix)] fn path2new(path: &Path) -> PathBuf { use os::unix::prelude::*; - PathBuf::new(::from_bytes(path.as_vec())) + PathBuf::from(::from_bytes(path.as_vec())) } #[cfg(unix)] diff --git a/src/libstd/path.rs b/src/libstd/path.rs index ddceed14cc6..25372c1cb7c 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -106,6 +106,7 @@ use cmp; use iter::{self, IntoIterator}; use mem; use ops::{self, Deref}; +use string::String; use vec::Vec; use fmt; @@ -527,6 +528,13 @@ impl<'a> Component<'a> { } } +#[stable(feature = "rust1", since = "1.0.0")] +impl<'a> AsRef for Component<'a> { + fn as_ref(&self) -> &OsStr { + self.as_os_str() + } +} + /// The core iterator giving the components of a path. /// /// See the module documentation for an in-depth explanation of components and @@ -601,6 +609,7 @@ impl<'a> Components<'a> { } /// Extract a slice corresponding to the portion of the path remaining for iteration. + #[stable(feature = "rust1", since = "1.0.0")] pub fn as_path(&self) -> &'a Path { let mut comps = self.clone(); if comps.front == State::Body { comps.trim_left(); } @@ -695,6 +704,20 @@ impl<'a> Components<'a> { } } +#[stable(feature = "rust1", since = "1.0.0")] +impl<'a> AsRef for Components<'a> { + fn as_ref(&self) -> &Path { + self.as_path() + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl<'a> AsRef for Components<'a> { + fn as_ref(&self) -> &OsStr { + self.as_path().as_os_str() + } +} + impl<'a> Iter<'a> { /// Extract a slice corresponding to the portion of the path remaining for iteration. #[stable(feature = "rust1", since = "1.0.0")] @@ -703,6 +726,20 @@ impl<'a> Iter<'a> { } } +#[stable(feature = "rust1", since = "1.0.0")] +impl<'a> AsRef for Iter<'a> { + fn as_ref(&self) -> &Path { + self.as_path() + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl<'a> AsRef for Iter<'a> { + fn as_ref(&self) -> &OsStr { + self.as_path().as_os_str() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<'a> Iterator for Iter<'a> { type Item = &'a OsStr; @@ -873,11 +910,10 @@ impl PathBuf { unsafe { mem::transmute(self) } } - /// Allocate a `PathBuf` with initial contents given by the - /// argument. + /// Allocate an empty `PathBuf`. #[stable(feature = "rust1", since = "1.0.0")] - pub fn new(s: S) -> PathBuf { - PathBuf { inner: s.as_os_str().to_os_string() } + pub fn new() -> PathBuf { + PathBuf { inner: OsString::new() } } /// Extend `self` with `path`. @@ -890,8 +926,8 @@ impl PathBuf { /// replaces everything except for the prefix (if any) of `self`. /// * if `path` has a prefix but no root, it replaces `self. #[stable(feature = "rust1", since = "1.0.0")] - pub fn push(&mut self, path: P) { - let path = path.as_path(); + pub fn push>(&mut self, path: P) { + let path = path.as_ref(); // in general, a separator is needed if the rightmost byte is not a separator let mut need_sep = self.as_mut_vec().last().map(|c| !is_sep_byte(*c)).unwrap_or(false); @@ -958,12 +994,12 @@ impl PathBuf { /// assert!(buf == PathBuf::new("/baz.txt")); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn set_file_name(&mut self, file_name: S) { + pub fn set_file_name>(&mut self, file_name: S) { if self.file_name().is_some() { let popped = self.pop(); debug_assert!(popped); } - self.push(file_name.as_os_str()); + self.push(file_name.as_ref()); } /// Updates `self.extension()` to `extension`. @@ -973,15 +1009,15 @@ impl PathBuf { /// Otherwise, returns `true`; if `self.extension()` is `None`, the extension /// is added; otherwise it is replaced. #[stable(feature = "rust1", since = "1.0.0")] - pub fn set_extension(&mut self, extension: S) -> bool { + pub fn set_extension>(&mut self, extension: S) -> bool { if self.file_name().is_none() { return false; } let mut stem = match self.file_stem() { Some(stem) => stem.to_os_string(), - None => OsString::from_str(""), + None => OsString::new(), }; - let extension = extension.as_os_str(); + let extension = extension.as_ref(); if os_str_as_u8_slice(extension).len() > 0 { stem.push("."); stem.push(extension); @@ -999,16 +1035,65 @@ impl PathBuf { } #[stable(feature = "rust1", since = "1.0.0")] -impl iter::FromIterator

for PathBuf { +impl<'a> From<&'a Path> for PathBuf { + fn from(s: &'a Path) -> PathBuf { + s.to_path_buf() + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl<'a> From<&'a str> for PathBuf { + fn from(s: &'a str) -> PathBuf { + PathBuf::from(OsString::from(s)) + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl<'a> From<&'a String> for PathBuf { + fn from(s: &'a String) -> PathBuf { + PathBuf::from(OsString::from(s)) + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl From for PathBuf { + fn from(s: String) -> PathBuf { + PathBuf::from(OsString::from(s)) + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl<'a> From<&'a OsStr> for PathBuf { + fn from(s: &'a OsStr) -> PathBuf { + PathBuf::from(OsString::from(s)) + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl<'a> From<&'a OsString> for PathBuf { + fn from(s: &'a OsString) -> PathBuf { + PathBuf::from(s.to_os_string()) + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl From for PathBuf { + fn from(s: OsString) -> PathBuf { + PathBuf { inner: s } + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl> iter::FromIterator

for PathBuf { fn from_iter>(iter: I) -> PathBuf { - let mut buf = PathBuf::new(""); + let mut buf = PathBuf::new(); buf.extend(iter); buf } } #[stable(feature = "rust1", since = "1.0.0")] -impl iter::Extend

for PathBuf { +impl> iter::Extend

for PathBuf { fn extend>(&mut self, iter: I) { for p in iter { self.push(p) @@ -1084,12 +1169,27 @@ impl cmp::Ord for PathBuf { } #[stable(feature = "rust1", since = "1.0.0")] +impl AsRef for PathBuf { + fn as_ref(&self) -> &OsStr { + &self.inner[..] + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +#[deprecated(since = "1.0.0", reason = "trait is deprecated")] impl AsOsStr for PathBuf { fn as_os_str(&self) -> &OsStr { &self.inner[..] } } +#[stable(feature = "rust1", since = "1.0.0")] +impl Into for PathBuf { + fn into(self) -> OsString { + self.inner + } +} + /// A slice of a path (akin to `str`). /// /// This type supports a number of operations for inspecting a path, including @@ -1133,8 +1233,14 @@ impl Path { /// /// This is a cost-free conversion. #[stable(feature = "rust1", since = "1.0.0")] - pub fn new(s: &S) -> &Path { - unsafe { mem::transmute(s.as_os_str()) } + pub fn new + ?Sized>(s: &S) -> &Path { + unsafe { mem::transmute(s.as_ref()) } + } + + /// Yield the underlying `OsStr` slice. + #[stable(feature = "rust1", since = "1.0.0")] + pub fn as_os_str(&self) -> &OsStr { + &self.inner } /// Yield a `&str` slice if the `Path` is valid unicode. @@ -1156,7 +1262,7 @@ impl Path { /// Convert a `Path` to an owned `PathBuf`. #[stable(feature = "rust1", since = "1.0.0")] pub fn to_path_buf(&self) -> PathBuf { - PathBuf::new(self) + PathBuf::from(self.inner.to_os_string()) } /// A path is *absolute* if it is independent of the current directory. @@ -1244,22 +1350,21 @@ impl Path { /// Returns a path that, when joined onto `base`, yields `self`. #[unstable(feature = "path_relative_from", reason = "see #23284")] - pub fn relative_from<'a, P: ?Sized>(&'a self, base: &'a P) -> Option<&Path> where - P: AsPath + pub fn relative_from<'a, P: ?Sized + AsRef>(&'a self, base: &'a P) -> Option<&Path> { - iter_after(self.components(), base.as_path().components()).map(|c| c.as_path()) + iter_after(self.components(), base.as_ref().components()).map(|c| c.as_path()) } /// Determines whether `base` is a prefix of `self`. #[stable(feature = "rust1", since = "1.0.0")] - pub fn starts_with(&self, base: P) -> bool { - iter_after(self.components(), base.as_path().components()).is_some() + pub fn starts_with>(&self, base: P) -> bool { + iter_after(self.components(), base.as_ref().components()).is_some() } /// Determines whether `child` is a suffix of `self`. #[stable(feature = "rust1", since = "1.0.0")] - pub fn ends_with(&self, child: P) -> bool { - iter_after(self.components().rev(), child.as_path().components().rev()).is_some() + pub fn ends_with>(&self, child: P) -> bool { + iter_after(self.components().rev(), child.as_ref().components().rev()).is_some() } /// Extract the stem (non-extension) portion of `self.file()`. @@ -1292,7 +1397,7 @@ impl Path { /// /// See `PathBuf::push` for more details on what it means to adjoin a path. #[stable(feature = "rust1", since = "1.0.0")] - pub fn join(&self, path: P) -> PathBuf { + pub fn join>(&self, path: P) -> PathBuf { let mut buf = self.to_path_buf(); buf.push(path); buf @@ -1302,7 +1407,7 @@ impl Path { /// /// See `PathBuf::set_file_name` for more details. #[stable(feature = "rust1", since = "1.0.0")] - pub fn with_file_name(&self, file_name: S) -> PathBuf { + pub fn with_file_name>(&self, file_name: S) -> PathBuf { let mut buf = self.to_path_buf(); buf.set_file_name(file_name); buf @@ -1312,7 +1417,7 @@ impl Path { /// /// See `PathBuf::set_extension` for more details. #[stable(feature = "rust1", since = "1.0.0")] - pub fn with_extension(&self, extension: S) -> PathBuf { + pub fn with_extension>(&self, extension: S) -> PathBuf { let mut buf = self.to_path_buf(); buf.set_extension(extension); buf @@ -1346,6 +1451,14 @@ impl Path { } #[stable(feature = "rust1", since = "1.0.0")] +impl AsRef for Path { + fn as_ref(&self) -> &OsStr { + &self.inner + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +#[deprecated(since = "1.0.0", reason = "trait is deprecated")] impl AsOsStr for Path { fn as_os_str(&self) -> &OsStr { &self.inner @@ -1405,6 +1518,7 @@ impl cmp::Ord for Path { /// Freely convertible to a `Path`. #[unstable(feature = "std_misc")] +#[deprecated(since = "1.0.0", reason = "use std::convert::AsRef instead")] pub trait AsPath { /// Convert to a `Path`. #[unstable(feature = "std_misc")] @@ -1412,10 +1526,42 @@ pub trait AsPath { } #[unstable(feature = "std_misc")] +#[deprecated(since = "1.0.0", reason = "use std::convert::AsRef instead")] +#[allow(deprecated)] impl AsPath for T { fn as_path(&self) -> &Path { Path::new(self.as_os_str()) } } +#[stable(feature = "rust1", since = "1.0.0")] +impl AsRef for Path { + fn as_ref(&self) -> &Path { self } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl AsRef for OsStr { + fn as_ref(&self) -> &Path { Path::new(self) } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl AsRef for OsString { + fn as_ref(&self) -> &Path { Path::new(self) } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl AsRef for str { + fn as_ref(&self) -> &Path { Path::new(self) } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl AsRef for String { + fn as_ref(&self) -> &Path { Path::new(self) } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl AsRef for PathBuf { + fn as_ref(&self) -> &Path { self } +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/libstd/prelude/v1.rs b/src/libstd/prelude/v1.rs index a0b4c80e9f3..6e12ac1a226 100644 --- a/src/libstd/prelude/v1.rs +++ b/src/libstd/prelude/v1.rs @@ -29,6 +29,8 @@ #[doc(no_inline)] pub use clone::Clone; #[stable(feature = "rust1", since = "1.0.0")] #[doc(no_inline)] pub use cmp::{PartialEq, PartialOrd, Eq, Ord}; +#[unstable(feature = "convert")] +#[doc(no_inline)] pub use convert::{AsRef, AsMut, Into, From}; #[stable(feature = "rust1", since = "1.0.0")] #[doc(no_inline)] pub use iter::DoubleEndedIterator; #[stable(feature = "rust1", since = "1.0.0")] @@ -40,8 +42,10 @@ #[stable(feature = "rust1", since = "1.0.0")] #[doc(no_inline)] pub use result::Result::{self, Ok, Err}; #[stable(feature = "rust1", since = "1.0.0")] +#[allow(deprecated)] #[doc(no_inline)] pub use slice::{SliceConcatExt, AsSlice}; #[stable(feature = "rust1", since = "1.0.0")] +#[allow(deprecated)] #[doc(no_inline)] pub use str::Str; #[stable(feature = "rust1", since = "1.0.0")] #[doc(no_inline)] pub use string::{String, ToString}; diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 6b09636c1df..d11c3d22144 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -19,8 +19,8 @@ use io::prelude::*; use ffi::AsOsStr; use fmt; use io::{self, Error, ErrorKind}; -use path::AsPath; use libc; +use path; use sync::mpsc::{channel, Receiver}; use sys::pipe2::{self, AnonPipe}; use sys::process2::Process as ProcessImp; @@ -198,8 +198,8 @@ impl Command { /// Set the working directory for the child process. #[stable(feature = "process", since = "1.0.0")] - pub fn current_dir(&mut self, dir: P) -> &mut Command { - self.inner.cwd(dir.as_path().as_os_str()); + pub fn current_dir>(&mut self, dir: P) -> &mut Command { + self.inner.cwd(dir.as_ref().as_os_str()); self } diff --git a/src/libstd/sys/unix/fs2.rs b/src/libstd/sys/unix/fs2.rs index ea74aab3331..202e5ddaec4 100644 --- a/src/libstd/sys/unix/fs2.rs +++ b/src/libstd/sys/unix/fs2.rs @@ -338,8 +338,7 @@ pub fn readlink(p: &Path) -> io::Result { })); buf.set_len(n as usize); } - let s: OsString = OsStringExt::from_vec(buf); - Ok(PathBuf::new(&s)) + Ok(PathBuf::from(OsString::from_vec(buf))) } pub fn symlink(src: &Path, dst: &Path) -> io::Result<()> { diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index a5a2f71acb7..6c191689255 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -36,7 +36,7 @@ const BUF_BYTES: usize = 2048; const TMPBUF_SZ: usize = 128; fn bytes2path(b: &[u8]) -> PathBuf { - PathBuf::new(::from_bytes(b)) + PathBuf::from(::from_bytes(b)) } fn os2path(os: OsString) -> PathBuf { @@ -253,7 +253,7 @@ pub fn current_exe() -> io::Result { let err = _NSGetExecutablePath(v.as_mut_ptr() as *mut i8, &mut sz); if err != 0 { return Err(io::Error::last_os_error()); } v.set_len(sz as uint - 1); // chop off trailing NUL - Ok(PathBuf::new(OsString::from_vec(v))) + Ok(PathBuf::from(OsString::from_vec(v))) } } @@ -466,9 +466,9 @@ pub fn page_size() -> usize { pub fn temp_dir() -> PathBuf { getenv("TMPDIR".as_os_str()).map(os2path).unwrap_or_else(|| { if cfg!(target_os = "android") { - PathBuf::new("/data/local/tmp") + PathBuf::from("/data/local/tmp") } else { - PathBuf::new("/tmp") + PathBuf::from("/tmp") } }) } diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 70aab26092c..1abe8d0a3c1 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -351,8 +351,7 @@ impl Encodable for FileMap { let max_line_length = if lines.len() == 1 { 0 } else { - lines.as_slice() - .windows(2) + lines.windows(2) .map(|w| w[1] - w[0]) .map(|bp| bp.to_usize()) .max() diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index c61aec0069d..31d8b207bb9 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -194,7 +194,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) fn res_rel_file(cx: &mut ExtCtxt, sp: codemap::Span, arg: &Path) -> PathBuf { // NB: relative paths are resolved relative to the compilation unit if !arg.is_absolute() { - let mut cu = PathBuf::new(&cx.codemap().span_to_filename(sp)); + let mut cu = PathBuf::from(&cx.codemap().span_to_filename(sp)); cu.pop(); cu.push(arg); cu diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 9f217bba00a..9af7b9ab633 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -39,6 +39,8 @@ #![feature(unicode)] #![feature(path_ext)] #![feature(str_char)] +#![feature(convert)] +#![feature(into_cow)] extern crate arena; extern crate fmt_macros; diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 667af642744..e77786c1347 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -5064,8 +5064,8 @@ impl<'a> Parser<'a> { outer_attrs: &[ast::Attribute], id_sp: Span) -> (ast::Item_, Vec ) { - let mut prefix = PathBuf::new(&self.sess.span_diagnostic.cm - .span_to_filename(self.span)); + let mut prefix = PathBuf::from(&self.sess.span_diagnostic.cm + .span_to_filename(self.span)); prefix.pop(); let mut dir_path = prefix; for part in &self.mod_path_stack { diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index f517dca53cd..8e3c00bb805 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -62,6 +62,7 @@ #![feature(std_misc)] #![feature(str_char)] #![feature(path_ext)] +#![feature(convert)] #![cfg_attr(windows, feature(libc))] #[macro_use] extern crate log; diff --git a/src/libterm/terminfo/searcher.rs b/src/libterm/terminfo/searcher.rs index f47921cbf5e..66ee2b1ba87 100644 --- a/src/libterm/terminfo/searcher.rs +++ b/src/libterm/terminfo/searcher.rs @@ -31,7 +31,7 @@ pub fn get_dbpath_for_term(term: &str) -> Option> { // Find search directory match env::var_os("TERMINFO") { - Some(dir) => dirs_to_search.push(PathBuf::new(&dir)), + Some(dir) => dirs_to_search.push(PathBuf::from(dir)), None => { if homedir.is_some() { // ncurses compatibility; @@ -40,9 +40,9 @@ pub fn get_dbpath_for_term(term: &str) -> Option> { match env::var("TERMINFO_DIRS") { Ok(dirs) => for i in dirs.split(':') { if i == "" { - dirs_to_search.push(PathBuf::new("/usr/share/terminfo")); + dirs_to_search.push(PathBuf::from("/usr/share/terminfo")); } else { - dirs_to_search.push(PathBuf::new(i)); + dirs_to_search.push(PathBuf::from(i)); } }, // Found nothing in TERMINFO_DIRS, use the default paths: @@ -50,9 +50,9 @@ pub fn get_dbpath_for_term(term: &str) -> Option> { // ~/.terminfo, ncurses will search /etc/terminfo, then // /lib/terminfo, and eventually /usr/share/terminfo. Err(..) => { - dirs_to_search.push(PathBuf::new("/etc/terminfo")); - dirs_to_search.push(PathBuf::new("/lib/terminfo")); - dirs_to_search.push(PathBuf::new("/usr/share/terminfo")); + dirs_to_search.push(PathBuf::from("/etc/terminfo")); + dirs_to_search.push(PathBuf::from("/lib/terminfo")); + dirs_to_search.push(PathBuf::from("/usr/share/terminfo")); } } } diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 51decbab858..94944453eda 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -45,6 +45,7 @@ #![feature(libc)] #![feature(set_stdio)] #![feature(os)] +#![feature(convert)] extern crate getopts; extern crate serialize; @@ -382,7 +383,7 @@ pub fn parse_opts(args: &[String]) -> Option { let run_ignored = matches.opt_present("ignored"); let logfile = matches.opt_str("logfile"); - let logfile = logfile.map(|s| PathBuf::new(&s)); + let logfile = logfile.map(|s| PathBuf::from(&s)); let run_benchmarks = matches.opt_present("bench"); let run_tests = ! run_benchmarks || @@ -696,7 +697,7 @@ pub fn run_tests_console(opts: &TestOpts, tests: Vec ) -> io::Res match tests.iter().max_by(|t|len_if_padded(*t)) { Some(t) => { let n = t.desc.name.as_slice(); - st.max_name_len = n.as_slice().len(); + st.max_name_len = n.len(); }, None => {} } diff --git a/src/rustbook/book.rs b/src/rustbook/book.rs index ac7f2f824cb..a08481f8be9 100644 --- a/src/rustbook/book.rs +++ b/src/rustbook/book.rs @@ -102,8 +102,8 @@ pub fn parse_summary(input: &mut Read, src: &Path) -> Result> // always include the introduction top_items.push(BookItem { title: "Introduction".to_string(), - path: PathBuf::new("README.md"), - path_to_root: PathBuf::new("."), + path: PathBuf::from("README.md"), + path_to_root: PathBuf::from("."), children: vec!(), }); @@ -133,10 +133,10 @@ pub fn parse_summary(input: &mut Read, src: &Path) -> Result> errors.push(format!("paths in SUMMARY.md must be relative, \ but path '{}' for section '{}' is not.", given_path, title)); - PathBuf::new("") + PathBuf::new() } }; - let path_to_root = PathBuf::new(&iter::repeat("../") + let path_to_root = PathBuf::from(&iter::repeat("../") .take(path_from_root.components().count() - 1) .collect::()); let item = BookItem { diff --git a/src/rustbook/build.rs b/src/rustbook/build.rs index 731773917e0..f06290b27cb 100644 --- a/src/rustbook/build.rs +++ b/src/rustbook/build.rs @@ -87,7 +87,7 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> { if env::args().len() < 3 { src = env::current_dir().unwrap().clone(); } else { - src = PathBuf::new(&env::args().nth(2).unwrap()); + src = PathBuf::from(&env::args().nth(2).unwrap()); } // preprocess the markdown, rerouting markdown references to html references let mut markdown_data = String::new(); @@ -164,13 +164,13 @@ impl Subcommand for Build { if env::args().len() < 3 { src = cwd.clone(); } else { - src = PathBuf::new(&env::args().nth(2).unwrap()); + src = PathBuf::from(&env::args().nth(2).unwrap()); } if env::args().len() < 4 { tgt = cwd.join("_book"); } else { - tgt = PathBuf::new(&env::args().nth(3).unwrap()); + tgt = PathBuf::from(&env::args().nth(3).unwrap()); } try!(fs::create_dir(&tgt)); diff --git a/src/rustbook/main.rs b/src/rustbook/main.rs index 09fcd518c1e..4a652f846ed 100644 --- a/src/rustbook/main.rs +++ b/src/rustbook/main.rs @@ -15,6 +15,7 @@ #![feature(rustdoc)] #![feature(rustc_private)] #![feature(path_relative_from)] +#![feature(convert)] extern crate rustdoc; extern crate rustc_back; diff --git a/src/test/run-pass/env-home-dir.rs b/src/test/run-pass/env-home-dir.rs index 5d68a25a14a..cd614750451 100644 --- a/src/test/run-pass/env-home-dir.rs +++ b/src/test/run-pass/env-home-dir.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(convert)] + use std::env::*; use std::path::PathBuf; @@ -16,7 +18,7 @@ fn main() { let oldhome = var("HOME"); set_var("HOME", "/home/MountainView"); - assert!(home_dir() == Some(PathBuf::new("/home/MountainView"))); + assert!(home_dir() == Some(PathBuf::from("/home/MountainView"))); remove_var("HOME"); if cfg!(target_os = "android") { @@ -37,14 +39,14 @@ fn main() { assert!(home_dir().is_some()); set_var("HOME", "/home/MountainView"); - assert!(home_dir() == Some(PathBuf::new("/home/MountainView"))); + assert!(home_dir() == Some(PathBuf::from("/home/MountainView"))); remove_var("HOME"); set_var("USERPROFILE", "/home/MountainView"); - assert!(home_dir() == Some(PathBuf::new("/home/MountainView"))); + assert!(home_dir() == Some(PathBuf::from("/home/MountainView"))); set_var("HOME", "/home/MountainView"); set_var("USERPROFILE", "/home/PaloAlto"); - assert!(home_dir() == Some(PathBuf::new("/home/MountainView"))); + assert!(home_dir() == Some(PathBuf::from("/home/MountainView"))); } -- cgit 1.4.1-3-g733a5 From 04e667a6b15bb83f16f03a0dd3c4b8612ba5c8b7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 23 Mar 2015 15:18:40 -0700 Subject: Test fixes and rebase conflicts, round 1 --- src/librustc_back/rpath.rs | 2 +- src/libstd/env.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libstd') diff --git a/src/librustc_back/rpath.rs b/src/librustc_back/rpath.rs index 68d21abb50e..10d17e266ed 100644 --- a/src/librustc_back/rpath.rs +++ b/src/librustc_back/rpath.rs @@ -115,7 +115,7 @@ fn path_relative_from(path: &Path, base: &Path) -> Option { if path.is_absolute() != base.is_absolute() { if path.is_absolute() { - Some(PathBuf::new(path)) + Some(PathBuf::from(path)) } else { None } diff --git a/src/libstd/env.rs b/src/libstd/env.rs index 9d6933ce9c8..00ce6917835 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -23,7 +23,7 @@ use error::Error; use ffi::{OsString, AsOsStr}; use fmt; use io; -use path::{self, Path, PathBuf}; +use path::{Path, PathBuf}; use sync::atomic::{AtomicIsize, ATOMIC_ISIZE_INIT, Ordering}; use sync::{StaticMutex, MUTEX_INIT}; use sys::os as os_imp; -- cgit 1.4.1-3-g733a5 From 29b54387b88bdf43c00849e3483c2297723f5a73 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 23 Mar 2015 15:54:39 -0700 Subject: Test fixes and rebase conflicts, round 2 --- src/doc/trpl/documentation.md | 3 +- src/liballoc/arc.rs | 76 +++++++++++++----------- src/liballoc/rc.rs | 90 ++++++++++++++++------------- src/libcollections/vec.rs | 32 ++++++---- src/libcollectionstest/lib.rs | 1 + src/libgraphviz/lib.rs | 40 ++++++------- src/librustc_back/lib.rs | 1 - src/librustc_back/rpath.rs | 4 +- src/librustc_lint/lib.rs | 1 - src/librustc_trans/trans/asm.rs | 2 +- src/librustc_typeck/lib.rs | 1 - src/libstd/env.rs | 5 +- src/libstd/path.rs | 23 ++++---- src/libstd/process.rs | 2 +- src/libstd/sys/unix/thread.rs | 5 +- src/libstd/sys/windows/fs2.rs | 2 +- src/libstd/sys/windows/mod.rs | 4 +- src/libstd/sys/windows/os.rs | 5 +- src/libstd/thread/scoped.rs | 6 +- src/test/run-make/issue-19371/foo.rs | 6 +- src/test/run-pass/create-dir-all-bare.rs | 2 + src/test/run-pass/issue-20797.rs | 8 +-- src/test/run-pass/send_str_hashmap.rs | 2 +- src/test/run-pass/send_str_treemap.rs | 2 +- src/test/run-pass/tcp-stress.rs | 3 + src/test/run-pass/ufcs-polymorphic-paths.rs | 2 +- 26 files changed, 179 insertions(+), 149 deletions(-) (limited to 'src/libstd') diff --git a/src/doc/trpl/documentation.md b/src/doc/trpl/documentation.md index 7a459ad354d..54821e3ce30 100644 --- a/src/doc/trpl/documentation.md +++ b/src/doc/trpl/documentation.md @@ -361,7 +361,8 @@ Here’s an example of documenting a macro: #[macro_export] macro_rules! panic_unless { ($condition:expr, $($rest:expr),+) => ({ if ! $condition { panic!($($rest),+); } }); -} +} +# fn main() {} ``` You’ll note three things: we need to add our own `extern crate` line, so that diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 97d3f78f67c..c9bbc0d74cd 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -128,8 +128,8 @@ unsafe impl Sync for Arc { } /// A weak pointer to an `Arc`. /// -/// Weak pointers will not keep the data inside of the `Arc` alive, and can be used to break cycles -/// between `Arc` pointers. +/// Weak pointers will not keep the data inside of the `Arc` alive, and can be +/// used to break cycles between `Arc` pointers. #[unsafe_no_drop_flag] #[unstable(feature = "alloc", reason = "Weak pointers may not belong in this module.")] @@ -218,8 +218,8 @@ impl Arc { unsafe fn drop_slow(&mut self) { let ptr = *self._ptr; - // Destroy the data at this time, even though we may not free the box allocation itself - // (there may still be weak pointers lying around). + // Destroy the data at this time, even though we may not free the box + // allocation itself (there may still be weak pointers lying around). drop(ptr::read(&self.inner().data)); if self.inner().weak.fetch_sub(1, Release) == 1 { @@ -286,8 +286,8 @@ impl Deref for Arc { impl Arc { /// Make a mutable reference from the given `Arc`. /// - /// This is also referred to as a copy-on-write operation because the inner data is cloned if - /// the reference count is greater than one. + /// This is also referred to as a copy-on-write operation because the inner + /// data is cloned if the reference count is greater than one. /// /// # Examples /// @@ -302,16 +302,18 @@ impl Arc { #[inline] #[unstable(feature = "alloc")] pub fn make_unique(&mut self) -> &mut T { - // Note that we hold a strong reference, which also counts as a weak reference, so we only - // clone if there is an additional reference of either kind. + // Note that we hold a strong reference, which also counts as a weak + // reference, so we only clone if there is an additional reference of + // either kind. if self.inner().strong.load(SeqCst) != 1 || self.inner().weak.load(SeqCst) != 1 { *self = Arc::new((**self).clone()) } - // This unsafety is ok because we're guaranteed that the pointer returned is the *only* - // pointer that will ever be returned to T. Our reference count is guaranteed to be 1 at - // this point, and we required the Arc itself to be `mut`, so we're returning the only - // possible reference to the inner data. + // This unsafety is ok because we're guaranteed that the pointer + // returned is the *only* pointer that will ever be returned to T. Our + // reference count is guaranteed to be 1 at this point, and we required + // the Arc itself to be `mut`, so we're returning the only possible + // reference to the inner data. let inner = unsafe { &mut **self._ptr }; &mut inner.data } @@ -322,8 +324,9 @@ impl Arc { impl Drop for Arc { /// Drops the `Arc`. /// - /// This will decrement the strong reference count. If the strong reference count becomes zero - /// and the only other references are `Weak` ones, `drop`s the inner value. + /// This will decrement the strong reference count. If the strong reference + /// count becomes zero and the only other references are `Weak` ones, + /// `drop`s the inner value. /// /// # Examples /// @@ -347,29 +350,32 @@ impl Drop for Arc { /// ``` #[inline] fn drop(&mut self) { - // This structure has #[unsafe_no_drop_flag], so this drop glue may run more than once (but - // it is guaranteed to be zeroed after the first if it's run more than once) + // This structure has #[unsafe_no_drop_flag], so this drop glue may run + // more than once (but it is guaranteed to be zeroed after the first if + // it's run more than once) let ptr = *self._ptr; if ptr.is_null() { return } - // Because `fetch_sub` is already atomic, we do not need to synchronize with other threads - // unless we are going to delete the object. This same logic applies to the below - // `fetch_sub` to the `weak` count. + // Because `fetch_sub` is already atomic, we do not need to synchronize + // with other threads unless we are going to delete the object. This + // same logic applies to the below `fetch_sub` to the `weak` count. if self.inner().strong.fetch_sub(1, Release) != 1 { return } - // This fence is needed to prevent reordering of use of the data and deletion of the data. - // Because it is marked `Release`, the decreasing of the reference count synchronizes with - // this `Acquire` fence. This means that use of the data happens before decreasing the - // reference count, which happens before this fence, which happens before the deletion of - // the data. + // This fence is needed to prevent reordering of use of the data and + // deletion of the data. Because it is marked `Release`, the decreasing + // of the reference count synchronizes with this `Acquire` fence. This + // means that use of the data happens before decreasing the reference + // count, which happens before this fence, which happens before the + // deletion of the data. // // As explained in the [Boost documentation][1], // - // > It is important to enforce any possible access to the object in one thread (through an - // > existing reference) to *happen before* deleting the object in a different thread. This - // > is achieved by a "release" operation after dropping a reference (any access to the - // > object through this reference must obviously happened before), and an "acquire" - // > operation before deleting the object. + // > It is important to enforce any possible access to the object in one + // > thread (through an existing reference) to *happen before* deleting + // > the object in a different thread. This is achieved by a "release" + // > operation after dropping a reference (any access to the object + // > through this reference must obviously happened before), and an + // > "acquire" operation before deleting the object. // // [1]: (www.boost.org/doc/libs/1_55_0/doc/html/atomic/usage_examples.html) atomic::fence(Acquire); @@ -387,7 +393,8 @@ impl Weak { /// /// Upgrades the `Weak` reference to an `Arc`, if possible. /// - /// Returns `None` if there were no strong references and the data was destroyed. + /// Returns `None` if there were no strong references and the data was + /// destroyed. /// /// # Examples /// @@ -402,8 +409,8 @@ impl Weak { /// let strong_five: Option> = weak_five.upgrade(); /// ``` pub fn upgrade(&self) -> Option> { - // We use a CAS loop to increment the strong count instead of a fetch_add because once the - // count hits 0 is must never be above 0. + // We use a CAS loop to increment the strong count instead of a + // fetch_add because once the count hits 0 is must never be above 0. let inner = self.inner(); loop { let n = inner.strong.load(SeqCst); @@ -480,8 +487,9 @@ impl Drop for Weak { // see comments above for why this check is here if ptr.is_null() { return } - // If we find out that we were the last weak pointer, then its time to deallocate the data - // entirely. See the discussion in Arc::drop() about the memory orderings + // If we find out that we were the last weak pointer, then its time to + // deallocate the data entirely. See the discussion in Arc::drop() about + // the memory orderings if self.inner().weak.fetch_sub(1, Release) == 1 { atomic::fence(Acquire); unsafe { deallocate(ptr as *mut u8, size_of::>(), diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index e4b09bba529..eb3c5c16726 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -59,12 +59,12 @@ //! //! drop(gadget_owner); //! -//! // Despite dropping gadget_owner, we're still able to print out the name of -//! // the Owner of the Gadgets. This is because we've only dropped the +//! // Despite dropping gadget_owner, we're still able to print out the name +//! // of the Owner of the Gadgets. This is because we've only dropped the //! // reference count object, not the Owner it wraps. As long as there are -//! // other `Rc` objects pointing at the same Owner, it will remain allocated. Notice -//! // that the `Rc` wrapper around Gadget.owner gets automatically dereferenced -//! // for us. +//! // other `Rc` objects pointing at the same Owner, it will remain +//! // allocated. Notice that the `Rc` wrapper around Gadget.owner gets +//! // automatically dereferenced for us. //! println!("Gadget {} owned by {}", gadget1.id, gadget1.owner.name); //! println!("Gadget {} owned by {}", gadget2.id, gadget2.owner.name); //! @@ -74,19 +74,22 @@ //! } //! ``` //! -//! If our requirements change, and we also need to be able to traverse from Owner → Gadget, we -//! will run into problems: an `Rc` pointer from Owner → Gadget introduces a cycle between the -//! objects. This means that their reference counts can never reach 0, and the objects will remain -//! allocated: a memory leak. In order to get around this, we can use `Weak` pointers. These -//! pointers don't contribute to the total count. +//! If our requirements change, and we also need to be able to traverse from +//! Owner → Gadget, we will run into problems: an `Rc` pointer from Owner +//! → Gadget introduces a cycle between the objects. This means that their +//! reference counts can never reach 0, and the objects will remain allocated: a +//! memory leak. In order to get around this, we can use `Weak` pointers. +//! These pointers don't contribute to the total count. //! -//! Rust actually makes it somewhat difficult to produce this loop in the first place: in order to -//! end up with two objects that point at each other, one of them needs to be mutable. This is -//! problematic because `Rc` enforces memory safety by only giving out shared references to the -//! object it wraps, and these don't allow direct mutation. We need to wrap the part of the object -//! we wish to mutate in a `RefCell`, which provides *interior mutability*: a method to achieve -//! mutability through a shared reference. `RefCell` enforces Rust's borrowing rules at runtime. -//! Read the `Cell` documentation for more details on interior mutability. +//! Rust actually makes it somewhat difficult to produce this loop in the first +//! place: in order to end up with two objects that point at each other, one of +//! them needs to be mutable. This is problematic because `Rc` enforces +//! memory safety by only giving out shared references to the object it wraps, +//! and these don't allow direct mutation. We need to wrap the part of the +//! object we wish to mutate in a `RefCell`, which provides *interior +//! mutability*: a method to achieve mutability through a shared reference. +//! `RefCell` enforces Rust's borrowing rules at runtime. Read the `Cell` +//! documentation for more details on interior mutability. //! //! ```rust //! # #![feature(alloc)] @@ -130,9 +133,10 @@ //! for gadget_opt in gadget_owner.gadgets.borrow().iter() { //! //! // gadget_opt is a Weak. Since weak pointers can't guarantee -//! // that their object is still allocated, we need to call upgrade() on them -//! // to turn them into a strong reference. This returns an Option, which -//! // contains a reference to our object if it still exists. +//! // that their object is still allocated, we need to call upgrade() +//! // on them to turn them into a strong reference. This returns an +//! // Option, which contains a reference to our object if it still +//! // exists. //! let gadget = gadget_opt.upgrade().unwrap(); //! println!("Gadget {} owned by {}", gadget.id, gadget.owner.name); //! } @@ -180,8 +184,8 @@ struct RcBox { #[unsafe_no_drop_flag] #[stable(feature = "rust1", since = "1.0.0")] pub struct Rc { - // FIXME #12808: strange names to try to avoid interfering with field accesses of the contained - // type via Deref + // FIXME #12808: strange names to try to avoid interfering with field + // accesses of the contained type via Deref _ptr: NonZero<*mut RcBox>, } @@ -203,9 +207,10 @@ impl Rc { pub fn new(value: T) -> Rc { unsafe { Rc { - // there is an implicit weak pointer owned by all the strong pointers, which - // ensures that the weak destructor never frees the allocation while the strong - // destructor is running, even if the weak pointer is stored inside the strong one. + // there is an implicit weak pointer owned by all the strong + // pointers, which ensures that the weak destructor never frees + // the allocation while the strong destructor is running, even + // if the weak pointer is stored inside the strong one. _ptr: NonZero::new(boxed::into_raw(box RcBox { value: value, strong: Cell::new(1), @@ -245,7 +250,8 @@ pub fn weak_count(this: &Rc) -> usize { this.weak() - 1 } #[unstable(feature = "alloc")] pub fn strong_count(this: &Rc) -> usize { this.strong() } -/// Returns true if there are no other `Rc` or `Weak` values that share the same inner value. +/// Returns true if there are no other `Rc` or `Weak` values that share the +/// same inner value. /// /// # Examples /// @@ -330,8 +336,8 @@ pub fn get_mut<'a, T>(rc: &'a mut Rc) -> Option<&'a mut T> { impl Rc { /// Make a mutable reference from the given `Rc`. /// - /// This is also referred to as a copy-on-write operation because the inner data is cloned if - /// the reference count is greater than one. + /// This is also referred to as a copy-on-write operation because the inner + /// data is cloned if the reference count is greater than one. /// /// # Examples /// @@ -349,10 +355,11 @@ impl Rc { if !is_unique(self) { *self = Rc::new((**self).clone()) } - // This unsafety is ok because we're guaranteed that the pointer returned is the *only* - // pointer that will ever be returned to T. Our reference count is guaranteed to be 1 at - // this point, and we required the `Rc` itself to be `mut`, so we're returning the only - // possible reference to the inner value. + // This unsafety is ok because we're guaranteed that the pointer + // returned is the *only* pointer that will ever be returned to T. Our + // reference count is guaranteed to be 1 at this point, and we required + // the `Rc` itself to be `mut`, so we're returning the only possible + // reference to the inner value. let inner = unsafe { &mut **self._ptr }; &mut inner.value } @@ -373,8 +380,9 @@ impl Deref for Rc { impl Drop for Rc { /// Drops the `Rc`. /// - /// This will decrement the strong reference count. If the strong reference count becomes zero - /// and the only other references are `Weak` ones, `drop`s the inner value. + /// This will decrement the strong reference count. If the strong reference + /// count becomes zero and the only other references are `Weak` ones, + /// `drop`s the inner value. /// /// # Examples /// @@ -404,8 +412,8 @@ impl Drop for Rc { if self.strong() == 0 { ptr::read(&**self); // destroy the contained object - // remove the implicit "strong weak" pointer now that we've destroyed the - // contents. + // remove the implicit "strong weak" pointer now that we've + // destroyed the contents. self.dec_weak(); if self.weak() == 0 { @@ -627,7 +635,8 @@ impl fmt::Debug for Rc { /// A weak version of `Rc`. /// -/// Weak references do not count when determining if the inner value should be dropped. +/// Weak references do not count when determining if the inner value should be +/// dropped. /// /// See the [module level documentation](./index.html) for more. #[unsafe_no_drop_flag] @@ -652,7 +661,8 @@ impl Weak { /// /// Upgrades the `Weak` reference to an `Rc`, if possible. /// - /// Returns `None` if there were no strong references and the data was destroyed. + /// Returns `None` if there were no strong references and the data was + /// destroyed. /// /// # Examples /// @@ -710,8 +720,8 @@ impl Drop for Weak { let ptr = *self._ptr; if !ptr.is_null() { self.dec_weak(); - // the weak count starts at 1, and will only go to zero if all the strong pointers - // have disappeared. + // the weak count starts at 1, and will only go to zero if all + // the strong pointers have disappeared. if self.weak() == 0 { deallocate(ptr as *mut u8, size_of::>(), min_align_of::>()) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index e360c0b840b..59819d01bc6 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -8,7 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! A growable list type with heap-allocated contents, written `Vec` but pronounced 'vector.' +//! A growable list type with heap-allocated contents, written `Vec` but +//! pronounced 'vector.' //! //! Vectors have `O(1)` indexing, push (to the end) and pop (from the end). //! @@ -124,17 +125,19 @@ use borrow::{Cow, IntoCow}; /// /// # Capacity and reallocation /// -/// The capacity of a vector is the amount of space allocated for any future elements that will be -/// added onto the vector. This is not to be confused with the *length* of a vector, which -/// specifies the number of actual elements within the vector. If a vector's length exceeds its -/// capacity, its capacity will automatically be increased, but its elements will have to be +/// The capacity of a vector is the amount of space allocated for any future +/// elements that will be added onto the vector. This is not to be confused with +/// the *length* of a vector, which specifies the number of actual elements +/// within the vector. If a vector's length exceeds its capacity, its capacity +/// will automatically be increased, but its elements will have to be /// reallocated. /// -/// For example, a vector with capacity 10 and length 0 would be an empty vector with space for 10 -/// more elements. Pushing 10 or fewer elements onto the vector will not change its capacity or -/// cause reallocation to occur. However, if the vector's length is increased to 11, it will have -/// to reallocate, which can be slow. For this reason, it is recommended to use -/// `Vec::with_capacity` whenever possible to specify how big the vector is expected to get. +/// For example, a vector with capacity 10 and length 0 would be an empty vector +/// with space for 10 more elements. Pushing 10 or fewer elements onto the +/// vector will not change its capacity or cause reallocation to occur. However, +/// if the vector's length is increased to 11, it will have to reallocate, which +/// can be slow. For this reason, it is recommended to use `Vec::with_capacity` +/// whenever possible to specify how big the vector is expected to get. #[unsafe_no_drop_flag] #[stable(feature = "rust1", since = "1.0.0")] pub struct Vec { @@ -1429,7 +1432,7 @@ impl ops::Index for Vec { #[cfg(not(stage0))] #[inline] fn index(&self, _index: ops::RangeFull) -> &[T] { - self.as_slice() + self } } @@ -1733,15 +1736,20 @@ impl AsRef<[T]> for Vec { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T: Clone> From<&'a [T]> for Vec { + #[cfg(not(test))] fn from(s: &'a [T]) -> Vec { s.to_vec() } + #[cfg(test)] + fn from(s: &'a [T]) -> Vec { + ::slice::to_vec(s) + } } #[stable(feature = "rust1", since = "1.0.0")] impl<'a> From<&'a str> for Vec { fn from(s: &'a str) -> Vec { - s.as_bytes().to_vec() + From::from(s.as_bytes()) } } diff --git a/src/libcollectionstest/lib.rs b/src/libcollectionstest/lib.rs index 365ef637a4c..f03a073e274 100644 --- a/src/libcollectionstest/lib.rs +++ b/src/libcollectionstest/lib.rs @@ -20,6 +20,7 @@ #![feature(unboxed_closures)] #![feature(unicode)] #![feature(unsafe_destructor)] +#![feature(into_cow)] #![cfg_attr(test, feature(str_char))] #[macro_use] extern crate log; diff --git a/src/libgraphviz/lib.rs b/src/libgraphviz/lib.rs index 9a6e77af28e..ccf4a3f48d9 100644 --- a/src/libgraphviz/lib.rs +++ b/src/libgraphviz/lib.rs @@ -47,13 +47,13 @@ //! which is cyclic. //! //! ```rust -//! # #![feature(rustc_private, core)] +//! # #![feature(rustc_private, core, into_cow)] //! use std::borrow::IntoCow; //! use std::io::Write; //! use graphviz as dot; //! -//! type Nd = int; -//! type Ed = (int,int); +//! type Nd = isize; +//! type Ed = (isize,isize); //! struct Edges(Vec); //! //! pub fn render_to(output: &mut W) { @@ -133,7 +133,7 @@ //! direct reference to the `(source,target)` pair stored in the graph's //! internal vector (rather than passing around a copy of the pair //! itself). Note that this implies that `fn edges(&'a self)` must -//! construct a fresh `Vec<&'a (uint,uint)>` from the `Vec<(uint,uint)>` +//! construct a fresh `Vec<&'a (usize,usize)>` from the `Vec<(usize,usize)>` //! edges stored in `self`. //! //! Since both the set of nodes and the set of edges are always @@ -149,14 +149,14 @@ //! entity `&sube`). //! //! ```rust -//! # #![feature(rustc_private, core)] +//! # #![feature(rustc_private, core, into_cow)] //! use std::borrow::IntoCow; //! use std::io::Write; //! use graphviz as dot; //! -//! type Nd = uint; -//! type Ed<'a> = &'a (uint, uint); -//! struct Graph { nodes: Vec<&'static str>, edges: Vec<(uint,uint)> } +//! type Nd = usize; +//! type Ed<'a> = &'a (usize, usize); +//! struct Graph { nodes: Vec<&'static str>, edges: Vec<(usize,usize)> } //! //! pub fn render_to(output: &mut W) { //! let nodes = vec!("{x,y}","{x}","{y}","{}"); @@ -207,14 +207,14 @@ //! Hasse-diagram for the subsets of the set `{x, y}`. //! //! ```rust -//! # #![feature(rustc_private, core)] +//! # #![feature(rustc_private, core, into_cow)] //! use std::borrow::IntoCow; //! use std::io::Write; //! use graphviz as dot; //! -//! type Nd<'a> = (uint, &'a str); +//! type Nd<'a> = (usize, &'a str); //! type Ed<'a> = (Nd<'a>, Nd<'a>); -//! struct Graph { nodes: Vec<&'static str>, edges: Vec<(uint,uint)> } +//! struct Graph { nodes: Vec<&'static str>, edges: Vec<(usize,usize)> } //! //! pub fn render_to(output: &mut W) { //! let nodes = vec!("{x,y}","{x}","{y}","{}"); @@ -231,7 +231,7 @@ //! } //! fn node_label<'b>(&'b self, n: &Nd<'b>) -> dot::LabelText<'b> { //! let &(i, _) = n; -//! dot::LabelText::LabelStr(self.nodes[i].as_slice().into_cow()) +//! dot::LabelText::LabelStr(self.nodes[i].into_cow()) //! } //! fn edge_label<'b>(&'b self, _: &Ed<'b>) -> dot::LabelText<'b> { //! dot::LabelText::LabelStr("⊆".into_cow()) @@ -240,12 +240,12 @@ //! //! impl<'a> dot::GraphWalk<'a, Nd<'a>, Ed<'a>> for Graph { //! fn nodes(&'a self) -> dot::Nodes<'a,Nd<'a>> { -//! self.nodes.iter().map(|s|s.as_slice()).enumerate().collect() +//! self.nodes.iter().map(|s| &s[..]).enumerate().collect() //! } //! fn edges(&'a self) -> dot::Edges<'a,Ed<'a>> { //! self.edges.iter() -//! .map(|&(i,j)|((i, self.nodes[i].as_slice()), -//! (j, self.nodes[j].as_slice()))) +//! .map(|&(i,j)|((i, &self.nodes[i][..]), +//! (j, &self.nodes[j][..]))) //! .collect() //! } //! fn source(&self, e: &Ed<'a>) -> Nd<'a> { let &(s,_) = e; s } @@ -385,7 +385,7 @@ impl<'a> Id<'a> { is_letter_or_underscore(c) || in_range('0', c, '9') } fn in_range(low: char, c: char, high: char) -> bool { - low as uint <= c as uint && c as uint <= high as uint + low as usize <= c as usize && c as usize <= high as usize } } @@ -602,12 +602,12 @@ mod tests { use std::iter::repeat; /// each node is an index in a vector in the graph. - type Node = uint; + type Node = usize; struct Edge { - from: uint, to: uint, label: &'static str + from: usize, to: usize, label: &'static str } - fn edge(from: uint, to: uint, label: &'static str) -> Edge { + fn edge(from: usize, to: usize, label: &'static str) -> Edge { Edge { from: from, to: to, label: label } } @@ -637,7 +637,7 @@ mod tests { enum NodeLabels { AllNodesLabelled(Vec), - UnlabelledNodes(uint), + UnlabelledNodes(usize), SomeNodesLabelled(Vec>), } diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs index b2e12a91ec8..63727a573a3 100644 --- a/src/librustc_back/lib.rs +++ b/src/librustc_back/lib.rs @@ -47,7 +47,6 @@ #![feature(rand)] #![feature(path_ext)] #![feature(std_misc)] -#![feature(path_relative_from)] #![feature(step_by)] #![feature(convert)] #![cfg_attr(test, feature(test, rand))] diff --git a/src/librustc_back/rpath.rs b/src/librustc_back/rpath.rs index 10d17e266ed..ff3f0b78f91 100644 --- a/src/librustc_back/rpath.rs +++ b/src/librustc_back/rpath.rs @@ -228,7 +228,7 @@ mod test { used_crates: Vec::new(), has_rpath: true, is_like_osx: true, - out_filename: PathBuf::new("bin/rustc"), + out_filename: PathBuf::from("bin/rustc"), get_install_prefix_lib_path: &mut || panic!(), realpath: &mut |p| Ok(p.to_path_buf()), }; @@ -238,7 +238,7 @@ mod test { } else { let config = &mut RPathConfig { used_crates: Vec::new(), - out_filename: PathBuf::new("bin/rustc"), + out_filename: PathBuf::from("bin/rustc"), get_install_prefix_lib_path: &mut || panic!(), has_rpath: true, is_like_osx: false, diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 99b3393c003..ef65acf8b13 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -40,7 +40,6 @@ #![feature(rustc_private)] #![feature(unsafe_destructor)] #![feature(staged_api)] -#![feature(std_misc)] #![feature(str_char)] #![cfg_attr(test, feature(test))] diff --git a/src/librustc_trans/trans/asm.rs b/src/librustc_trans/trans/asm.rs index 33817bb952e..d6c85e8b173 100644 --- a/src/librustc_trans/trans/asm.rs +++ b/src/librustc_trans/trans/asm.rs @@ -81,7 +81,7 @@ pub fn trans_inline_asm<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ia: &ast::InlineAsm) // Default per-arch clobbers // Basically what clang does - let arch_clobbers = match bcx.sess().target.target.arch.as_slice() { + let arch_clobbers = match &bcx.sess().target.target.arch[..] { "x86" | "x86_64" => vec!("~{dirflag}", "~{fpsr}", "~{flags}"), _ => Vec::new() }; diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 6bdfb17ec1c..4e7e63a5d77 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -80,7 +80,6 @@ This API is completely unstable and subject to change. #![feature(collections)] #![feature(core)] #![feature(int_uint)] -#![feature(std_misc)] #![feature(quote)] #![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] diff --git a/src/libstd/env.rs b/src/libstd/env.rs index 00ce6917835..fd7532ea4a7 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -327,12 +327,13 @@ pub struct JoinPathsError { /// # Examples /// /// ``` +/// # #![feature(convert)] /// use std::env; /// use std::path::PathBuf; /// /// if let Some(path) = env::var_os("PATH") { /// let mut paths = env::split_paths(&path).collect::>(); -/// paths.push(PathBuf::new("/home/xyz/bin")); +/// paths.push(PathBuf::from("/home/xyz/bin")); /// let new_path = env::join_paths(paths.iter()).unwrap(); /// env::set_var("PATH", &new_path); /// } @@ -853,7 +854,7 @@ mod tests { fn split_paths_unix() { fn check_parse(unparsed: &str, parsed: &[&str]) -> bool { split_paths(unparsed).collect::>() == - parsed.iter().map(|s| PathBuf::new(*s)).collect::>() + parsed.iter().map(|s| PathBuf::from(*s)).collect::>() } assert!(check_parse("", &mut [""])); diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 8ee33e94fe7..50f79967f55 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -35,9 +35,10 @@ //! To build or modify paths, use `PathBuf`: //! //! ```rust +//! # #![feature(convert)] //! use std::path::PathBuf; //! -//! let mut path = PathBuf::new("c:\\"); +//! let mut path = PathBuf::from("c:\\"); //! path.push("windows"); //! path.push("system32"); //! path.set_extension("dll"); @@ -892,9 +893,10 @@ impl<'a> cmp::Ord for Components<'a> { /// # Examples /// /// ``` +/// # #![feature(convert)] /// use std::path::PathBuf; /// -/// let mut path = PathBuf::new("c:\\"); +/// let mut path = PathBuf::from("c:\\"); /// path.push("windows"); /// path.push("system32"); /// path.set_extension("dll"); @@ -983,15 +985,16 @@ impl PathBuf { /// # Examples /// /// ``` + /// # #![feature(convert)] /// use std::path::PathBuf; /// - /// let mut buf = PathBuf::new("/"); + /// let mut buf = PathBuf::from("/"); /// assert!(buf.file_name() == None); /// buf.set_file_name("bar"); - /// assert!(buf == PathBuf::new("/bar")); + /// assert!(buf == PathBuf::from("/bar")); /// assert!(buf.file_name().is_some()); /// buf.set_file_name("baz.txt"); - /// assert!(buf == PathBuf::new("/baz.txt")); + /// assert!(buf == PathBuf::from("/baz.txt")); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn set_file_name>(&mut self, file_name: S) { @@ -1661,7 +1664,7 @@ mod tests { let static_path = Path::new("/home/foo"); let static_cow_path: Cow<'static, Path> = static_path.into_cow(); - let pathbuf = PathBuf::new("/home/foo"); + let pathbuf = PathBuf::from("/home/foo"); { let path: &Path = &pathbuf; @@ -2543,7 +2546,7 @@ mod tests { pub fn test_push() { macro_rules! tp( ($path:expr, $push:expr, $expected:expr) => ( { - let mut actual = PathBuf::new($path); + let mut actual = PathBuf::from($path); actual.push($push); assert!(actual.to_str() == Some($expected), "pushing {:?} onto {:?}: Expected {:?}, got {:?}", @@ -2631,7 +2634,7 @@ mod tests { pub fn test_pop() { macro_rules! tp( ($path:expr, $expected:expr, $output:expr) => ( { - let mut actual = PathBuf::new($path); + let mut actual = PathBuf::from($path); let output = actual.pop(); assert!(actual.to_str() == Some($expected) && output == $output, "popping from {:?}: Expected {:?}/{:?}, got {:?}/{:?}", @@ -2685,7 +2688,7 @@ mod tests { pub fn test_set_file_name() { macro_rules! tfn( ($path:expr, $file:expr, $expected:expr) => ( { - let mut p = PathBuf::new($path); + let mut p = PathBuf::from($path); p.set_file_name($file); assert!(p.to_str() == Some($expected), "setting file name of {:?} to {:?}: Expected {:?}, got {:?}", @@ -2719,7 +2722,7 @@ mod tests { pub fn test_set_extension() { macro_rules! tfe( ($path:expr, $ext:expr, $expected:expr, $output:expr) => ( { - let mut p = PathBuf::new($path); + let mut p = PathBuf::from($path); let output = p.set_extension($ext); assert!(p.to_str() == Some($expected) && output == $output, "setting extension of {:?} to {:?}: Expected {:?}/{:?}, got {:?}/{:?}", diff --git a/src/libstd/process.rs b/src/libstd/process.rs index d11c3d22144..553412c8371 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -770,7 +770,7 @@ mod tests { // test changing to the parent of os::getcwd() because we know // the path exists (and os::getcwd() is not expected to be root) let parent_dir = os::getcwd().unwrap().dir_path(); - let result = pwd_cmd().current_dir(&parent_dir).output().unwrap(); + let result = pwd_cmd().current_dir(parent_dir.as_str().unwrap()).output().unwrap(); let output = String::from_utf8(result.stdout).unwrap(); let child_dir = old_path::Path::new(output.trim()); diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index eb2a6dc08bf..eb61f21aacd 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -13,14 +13,12 @@ use core::prelude::*; use cmp; -use dynamic_lib::DynamicLibrary; use ffi::CString; use io; use libc::consts::os::posix01::PTHREAD_STACK_MIN; use libc; use mem; use ptr; -use sync::{Once, ONCE_INIT}; use sys::os; use thunk::Thunk; use time::Duration; @@ -322,6 +320,9 @@ pub fn sleep(dur: Duration) { // dependency on libc6 (#23628). #[cfg(target_os = "linux")] fn min_stack_size(attr: *const libc::pthread_attr_t) -> libc::size_t { + use dynamic_lib::DynamicLibrary; + use sync::{Once, ONCE_INIT}; + type F = unsafe extern "C" fn(*const libc::pthread_attr_t) -> libc::size_t; static INIT: Once = ONCE_INIT; static mut __pthread_get_minstack: Option = None; diff --git a/src/libstd/sys/windows/fs2.rs b/src/libstd/sys/windows/fs2.rs index 117f819eeeb..99835265111 100644 --- a/src/libstd/sys/windows/fs2.rs +++ b/src/libstd/sys/windows/fs2.rs @@ -372,7 +372,7 @@ pub fn readlink(p: &Path) -> io::Result { sz - 1, libc::VOLUME_NAME_DOS) }, |s| OsStringExt::from_wide(s))); - Ok(PathBuf::new(&ret)) + Ok(PathBuf::from(&ret)) } pub fn symlink(src: &Path, dst: &Path) -> io::Result<()> { diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs index eeaf4ced072..b1ceac9b902 100644 --- a/src/libstd/sys/windows/mod.rs +++ b/src/libstd/sys/windows/mod.rs @@ -304,9 +304,7 @@ fn fill_utf16_buf_new(f1: F1, f2: F2) -> io::Result } fn os2path(s: &[u16]) -> PathBuf { - let os = ::from_wide(s); - // FIXME(#22751) should consume `os` - PathBuf::new(&os) + PathBuf::from(OsString::from_wide(s)) } pub fn truncate_utf16_at_nul<'a>(v: &'a [u16]) -> &'a [u16] { diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index 4f6c4c9aab3..83d06371734 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -363,10 +363,7 @@ pub fn temp_dir() -> PathBuf { pub fn home_dir() -> Option { getenv("HOME".as_os_str()).or_else(|| { getenv("USERPROFILE".as_os_str()) - }).map(|os| { - // FIXME(#22751) should consume `os` - PathBuf::new(&os) - }).or_else(|| unsafe { + }).map(PathBuf::from).or_else(|| unsafe { let me = c::GetCurrentProcess(); let mut token = ptr::null_mut(); if c::OpenProcessToken(me, c::TOKEN_READ, &mut token) == 0 { diff --git a/src/libstd/thread/scoped.rs b/src/libstd/thread/scoped.rs index d57535391fd..b384879d7a9 100644 --- a/src/libstd/thread/scoped.rs +++ b/src/libstd/thread/scoped.rs @@ -24,7 +24,7 @@ //! # Examples //! //! ``` -//! # #![feature(std_misc)] +//! # #![feature(scoped_tls)] //! scoped_thread_local!(static FOO: u32); //! //! // Initially each scoped slot is empty. @@ -147,7 +147,7 @@ impl ScopedKey { /// # Examples /// /// ``` - /// # #![feature(std_misc)] + /// # #![feature(scoped_tls)] /// scoped_thread_local!(static FOO: u32); /// /// FOO.set(&100, || { @@ -200,7 +200,7 @@ impl ScopedKey { /// # Examples /// /// ```no_run - /// # #![feature(std_misc)] + /// # #![feature(scoped_tls)] /// scoped_thread_local!(static FOO: u32); /// /// FOO.with(|slot| { diff --git a/src/test/run-make/issue-19371/foo.rs b/src/test/run-make/issue-19371/foo.rs index b089b9269a2..0d42e0be58d 100644 --- a/src/test/run-make/issue-19371/foo.rs +++ b/src/test/run-make/issue-19371/foo.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(rustc_private, path)] +#![feature(rustc_private, path, convert)] extern crate rustc; extern crate rustc_driver; @@ -33,9 +33,9 @@ fn main() { panic!("expected rustc path"); } - let tmpdir = PathBuf::new(&args[1]); + let tmpdir = PathBuf::from(&args[1]); - let mut sysroot = PathBuf::new(&args[3]); + let mut sysroot = PathBuf::from(&args[3]); sysroot.pop(); sysroot.pop(); diff --git a/src/test/run-pass/create-dir-all-bare.rs b/src/test/run-pass/create-dir-all-bare.rs index 3a4286c2927..475df629f63 100644 --- a/src/test/run-pass/create-dir-all-bare.rs +++ b/src/test/run-pass/create-dir-all-bare.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(tempdir)] + use std::env; use std::fs::{self, TempDir}; diff --git a/src/test/run-pass/issue-20797.rs b/src/test/run-pass/issue-20797.rs index 4dbe7c968a7..d0720ec593f 100644 --- a/src/test/run-pass/issue-20797.rs +++ b/src/test/run-pass/issue-20797.rs @@ -12,12 +12,12 @@ // pretty-expanded FIXME #23616 -#![feature(old_io, old_path)] +#![feature(convert)] use std::default::Default; use std::io; use std::fs; -use std::path::{PathBuf, Path}; +use std::path::PathBuf; pub trait PathExtensions { fn is_dir(&self) -> bool { false } @@ -98,8 +98,8 @@ impl Iterator for Subpaths { } } -fn foo() { - let mut walker: Subpaths = Subpaths::walk(&PathBuf::new("/home")).unwrap(); +fn _foo() { + let _walker: Subpaths = Subpaths::walk(&PathBuf::from("/home")).unwrap(); } fn main() {} diff --git a/src/test/run-pass/send_str_hashmap.rs b/src/test/run-pass/send_str_hashmap.rs index 7bef36d0656..d109f7abde4 100644 --- a/src/test/run-pass/send_str_hashmap.rs +++ b/src/test/run-pass/send_str_hashmap.rs @@ -10,7 +10,7 @@ // pretty-expanded FIXME #23616 -#![feature(collections)] +#![feature(collections, into_cow)] extern crate collections; diff --git a/src/test/run-pass/send_str_treemap.rs b/src/test/run-pass/send_str_treemap.rs index 04a4a239b0f..07dd5443348 100644 --- a/src/test/run-pass/send_str_treemap.rs +++ b/src/test/run-pass/send_str_treemap.rs @@ -10,7 +10,7 @@ // pretty-expanded FIXME #23616 -#![feature(collections)] +#![feature(collections, into_cow)] extern crate collections; diff --git a/src/test/run-pass/tcp-stress.rs b/src/test/run-pass/tcp-stress.rs index e06e6883a75..489abf163c0 100644 --- a/src/test/run-pass/tcp-stress.rs +++ b/src/test/run-pass/tcp-stress.rs @@ -13,6 +13,9 @@ // ignore-openbsd system ulimit (Too many open files) // exec-env:RUST_LOG=debug +#![feature(rustc_private, libc, old_io, io, std_misc)] +#![allow(deprecated, unused_must_use)] + #[macro_use] extern crate log; extern crate libc; diff --git a/src/test/run-pass/ufcs-polymorphic-paths.rs b/src/test/run-pass/ufcs-polymorphic-paths.rs index e05a60dbc7f..a6ea0f76dc2 100644 --- a/src/test/run-pass/ufcs-polymorphic-paths.rs +++ b/src/test/run-pass/ufcs-polymorphic-paths.rs @@ -10,7 +10,7 @@ // pretty-expanded FIXME #23616 -#![feature(collections, rand)] +#![feature(collections, rand, into_cow)] use std::borrow::{Cow, IntoCow}; use std::collections::BitVec; -- cgit 1.4.1-3-g733a5 From c5c3de0cf4efba1517009ee6ef2da66f03b490b9 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 23 Mar 2015 17:29:51 -0700 Subject: Test fixes and rebase conflicts, round 3 --- src/librustc_back/lib.rs | 1 - src/librustc_trans/lib.rs | 1 - src/libstd/env.rs | 2 +- src/libstd/lib.rs | 2 -- src/test/debuginfo/function-prologue-stepping-regular.rs | 1 + src/test/run-pass/out-of-stack-no-split.rs | 2 +- 6 files changed, 3 insertions(+), 6 deletions(-) (limited to 'src/libstd') diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs index 63727a573a3..f7ee76c0a43 100644 --- a/src/librustc_back/lib.rs +++ b/src/librustc_back/lib.rs @@ -36,7 +36,6 @@ #![feature(collections)] #![feature(core)] #![feature(old_fs)] -#![feature(hash)] #![feature(int_uint)] #![feature(io)] #![feature(old_io)] diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index 176e3805a31..b9ec22b86f0 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -40,7 +40,6 @@ #![feature(unicode)] #![feature(path_ext)] #![feature(fs)] -#![feature(hash)] #![feature(convert)] #![feature(path_relative_from)] diff --git a/src/libstd/env.rs b/src/libstd/env.rs index fd7532ea4a7..71f072302fb 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -834,7 +834,7 @@ mod tests { fn split_paths_windows() { fn check_parse(unparsed: &str, parsed: &[&str]) -> bool { split_paths(unparsed).collect::>() == - parsed.iter().map(|s| PathBuf::new(*s)).collect::>() + parsed.iter().map(|s| PathBuf::from(*s)).collect::>() } assert!(check_parse("", &mut [""])); diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index f44256125cd..90eca6168f2 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -111,7 +111,6 @@ #![feature(box_syntax)] #![feature(collections)] #![feature(core)] -#![feature(hash)] #![feature(lang_items)] #![feature(libc)] #![feature(linkage, thread_local, asm)] @@ -124,7 +123,6 @@ #![feature(unsafe_destructor)] #![feature(unsafe_no_drop_flag)] #![feature(macro_reexport)] -#![feature(hash)] #![feature(int_uint)] #![feature(unique)] #![feature(convert)] diff --git a/src/test/debuginfo/function-prologue-stepping-regular.rs b/src/test/debuginfo/function-prologue-stepping-regular.rs index 14433fbcd23..8312d16bcac 100644 --- a/src/test/debuginfo/function-prologue-stepping-regular.rs +++ b/src/test/debuginfo/function-prologue-stepping-regular.rs @@ -126,6 +126,7 @@ // lldb-command:continue #![allow(unused_variables)] +#![feature(old_io)] #![omit_gdb_pretty_printer_section] fn immediate_args(a: int, b: bool, c: f64) { diff --git a/src/test/run-pass/out-of-stack-no-split.rs b/src/test/run-pass/out-of-stack-no-split.rs index e4c7f4ef095..8887e1937c6 100644 --- a/src/test/run-pass/out-of-stack-no-split.rs +++ b/src/test/run-pass/out-of-stack-no-split.rs @@ -15,7 +15,7 @@ //ignore-dragonfly //ignore-bitrig -#![feature(asm)] +#![feature(asm, old_io)] use std::old_io::process::Command; use std::env; -- cgit 1.4.1-3-g733a5