about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2015-02-17 21:41:32 +0100
committerFelix S. Klock II <pnkfelix@pnkfx.org>2015-03-03 20:29:01 +0100
commit270f0eef733a625bcee68019189f19dc119f8f24 (patch)
tree1b58f6d17a7ca5cb04f6124eaa93e0234ff3c906 /src/liballoc
parent14f0942a49b77f81d0bedb3d8b5fb615ef521bb3 (diff)
downloadrust-270f0eef733a625bcee68019189f19dc119f8f24.tar.gz
rust-270f0eef733a625bcee68019189f19dc119f8f24.zip
Add `: Box<_>` or `::Box<_>` type annotations to various places.
This is the kind of change that one is expected to need to make to
accommodate overloaded-`box`.

----

Note that this is not *all* of the changes necessary to accommodate
Issue 22181.  It is merely the subset of those cases where there was
already a let-binding in place that made it easy to add the necesasry
type ascription.

(For unnamed intermediate `Box` values, one must go down a different
route; `Box::new` is the option that maximizes portability, but has
potential inefficiency depending on whether the call is inlined.)

----

There is one place worth note, `run-pass/coerce-match.rs`, where I
used an ugly form of `Box<_>` type ascription where I would have
preferred to use `Box::new` to accommodate overloaded-`box`.  I
deliberately did not use `Box::new` here, because that is already done
in coerce-match-calls.rs.

----

Precursor for overloaded-`box` and placement-`in`; see Issue 22181.
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/arc.rs4
-rw-r--r--src/liballoc/heap.rs3
-rw-r--r--src/liballoc/lib.rs6
-rw-r--r--src/liballoc/rc.rs3
4 files changed, 13 insertions, 3 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/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);
     }