diff options
| author | bors <bors@rust-lang.org> | 2015-03-03 20:17:08 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-03-03 20:17:08 +0000 |
| commit | fed12499e7d91f9cdfba5833e34d20e8fd19b898 (patch) | |
| tree | 2c5b377f6a53498f2555965e4903b77e4c8aad30 /src/liballoc | |
| parent | 129173f1980e9ac03f7ef0fc0193c41235d07649 (diff) | |
| parent | cb1b0dd589c80c3edb94b8982ea33e000978f572 (diff) | |
| download | rust-fed12499e7d91f9cdfba5833e34d20e8fd19b898.tar.gz rust-fed12499e7d91f9cdfba5833e34d20e8fd19b898.zip | |
Auto merge of #23002 - pnkfelix:fsk-box-place-runway, r=nikomatsakis
Runway for RFC 809 (overloaded box/placement-in) by adding type annotations or explicit calls to `Box::new` where I found it necessary on PR #22086. I have broken this up into more than one PR because the entire commit chain (see PR #22086) is long, widespread and unwieldy to rebase frequently. To my knowledge this is not a breaking change. Also, there is in principle nothing stopping someone from reverting some/all of these annotations, since without the rest of the commit chain in #22086, the associated code would continue to compile. All I can do is ask: Try to discourage others from removing seemingly "unnecessary" uses of the `Box` type or the `Box::new()` function, until the rest of RFC 809 lands.
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/arc.rs | 4 | ||||
| -rw-r--r-- | src/liballoc/boxed.rs | 3 | ||||
| -rw-r--r-- | src/liballoc/heap.rs | 3 | ||||
| -rw-r--r-- | src/liballoc/lib.rs | 6 | ||||
| -rw-r--r-- | src/liballoc/rc.rs | 3 |
5 files changed, 15 insertions, 4 deletions
diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index c95b413b397..dc1938cac1a 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -69,6 +69,8 @@ //! } //! ``` +use boxed::Box; + use core::prelude::*; use core::atomic; @@ -170,7 +172,7 @@ impl<T> Arc<T> { pub fn new(data: T) -> Arc<T> { // Start the weak pointer count as 1 which is the weak pointer that's // held by all the strong pointers (kinda), see std/rc.rs for more info - let x = box ArcInner { + let x: Box<_> = box ArcInner { strong: atomic::AtomicUsize::new(1), weak: atomic::AtomicUsize::new(1), data: data, diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index a93872dfe36..630ca837daa 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -94,6 +94,7 @@ impl<T> Box<T> { /// let x = Box::new(5); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[inline(always)] pub fn new(x: T) -> Box<T> { box x } @@ -156,7 +157,7 @@ impl<T: Default> Default for Box<T> { #[stable(feature = "rust1", since = "1.0.0")] impl<T> Default for Box<[T]> { #[stable(feature = "rust1", since = "1.0.0")] - fn default() -> Box<[T]> { box [] } + fn default() -> Box<[T]> { Box::<[T; 0]>::new([]) } } #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/liballoc/heap.rs b/src/liballoc/heap.rs index 726d5c8a23b..3b93171386a 100644 --- a/src/liballoc/heap.rs +++ b/src/liballoc/heap.rs @@ -387,6 +387,7 @@ mod test { extern crate test; use self::test::Bencher; use core::ptr::PtrExt; + use boxed::Box; use heap; #[test] @@ -404,7 +405,7 @@ mod test { #[bench] fn alloc_owned_small(b: &mut Bencher) { b.iter(|| { - box 10 + let _: Box<_> = box 10; }) } } diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 82bd13475c7..b1fdf139b0c 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -96,9 +96,15 @@ pub mod heap; // Primitive types using the heaps above +// Need to conditionally define the mod from `boxed.rs` to avoid +// duplicating the lang-items when building in test cfg; but also need +// to allow code to have `use boxed::HEAP;` +// and `use boxed::Box;` declarations. #[cfg(not(test))] pub mod boxed; #[cfg(test)] +mod boxed { pub use std::boxed::{Box, HEAP}; } +#[cfg(test)] mod boxed_test; pub mod arc; pub mod rc; diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index f57286bbf11..763dcc7f256 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -795,6 +795,7 @@ impl<T> RcBoxPtr<T> for Weak<T> { #[cfg(test)] mod tests { use super::{Rc, Weak, weak_count, strong_count}; + use std::boxed::Box; use std::cell::RefCell; use std::option::Option; use std::option::Option::{Some, None}; @@ -826,7 +827,7 @@ mod tests { #[test] fn test_destructor() { - let x = Rc::new(box 5); + let x: Rc<Box<_>> = Rc::new(box 5); assert_eq!(**x, 5); } |
