Skip to content

Commit 270f0ee

Browse files
committed
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.
1 parent 14f0942 commit 270f0ee

File tree

164 files changed

+281
-264
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+281
-264
lines changed

src/liballoc/arc.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
//! }
7070
//! ```
7171
72+
use boxed::Box;
73+
7274
use core::prelude::*;
7375

7476
use core::atomic;
@@ -170,7 +172,7 @@ impl<T> Arc<T> {
170172
pub fn new(data: T) -> Arc<T> {
171173
// Start the weak pointer count as 1 which is the weak pointer that's
172174
// held by all the strong pointers (kinda), see std/rc.rs for more info
173-
let x = box ArcInner {
175+
let x: Box<_> = box ArcInner {
174176
strong: atomic::AtomicUsize::new(1),
175177
weak: atomic::AtomicUsize::new(1),
176178
data: data,

src/liballoc/heap.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ mod test {
387387
extern crate test;
388388
use self::test::Bencher;
389389
use core::ptr::PtrExt;
390+
use boxed::Box;
390391
use heap;
391392

392393
#[test]
@@ -404,7 +405,7 @@ mod test {
404405
#[bench]
405406
fn alloc_owned_small(b: &mut Bencher) {
406407
b.iter(|| {
407-
box 10
408+
let _: Box<_> = box 10;
408409
})
409410
}
410411
}

src/liballoc/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,15 @@ pub mod heap;
9696

9797
// Primitive types using the heaps above
9898

99+
// Need to conditionally define the mod from `boxed.rs` to avoid
100+
// duplicating the lang-items when building in test cfg; but also need
101+
// to allow code to have `use boxed::HEAP;`
102+
// and `use boxed::Box;` declarations.
99103
#[cfg(not(test))]
100104
pub mod boxed;
101105
#[cfg(test)]
106+
mod boxed { pub use std::boxed::{Box, HEAP}; }
107+
#[cfg(test)]
102108
mod boxed_test;
103109
pub mod arc;
104110
pub mod rc;

src/liballoc/rc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,7 @@ impl<T> RcBoxPtr<T> for Weak<T> {
795795
#[cfg(test)]
796796
mod tests {
797797
use super::{Rc, Weak, weak_count, strong_count};
798+
use std::boxed::Box;
798799
use std::cell::RefCell;
799800
use std::option::Option;
800801
use std::option::Option::{Some, None};
@@ -826,7 +827,7 @@ mod tests {
826827

827828
#[test]
828829
fn test_destructor() {
829-
let x = Rc::new(box 5);
830+
let x: Rc<Box<_>> = Rc::new(box 5);
830831
assert_eq!(**x, 5);
831832
}
832833

src/libarena/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,11 +581,11 @@ mod tests {
581581
#[bench]
582582
pub fn bench_copy_nonarena(b: &mut Bencher) {
583583
b.iter(|| {
584-
box Point {
584+
let _: Box<_> = box Point {
585585
x: 1,
586586
y: 2,
587587
z: 3,
588-
}
588+
};
589589
})
590590
}
591591

@@ -634,10 +634,10 @@ mod tests {
634634
#[bench]
635635
pub fn bench_noncopy_nonarena(b: &mut Bencher) {
636636
b.iter(|| {
637-
box Noncopy {
637+
let _: Box<_> = box Noncopy {
638638
string: "hello world".to_string(),
639639
array: vec!( 1, 2, 3, 4, 5 ),
640-
}
640+
};
641641
})
642642
}
643643

src/libcollections/binary_heap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ mod tests {
790790

791791
#[test]
792792
fn test_push_unique() {
793-
let mut heap = BinaryHeap::from_vec(vec![box 2, box 4, box 9]);
793+
let mut heap = BinaryHeap::<Box<_>>::from_vec(vec![box 2, box 4, box 9]);
794794
assert_eq!(heap.len(), 3);
795795
assert!(*heap.peek().unwrap() == box 9);
796796
heap.push(box 11);

src/libcollections/linked_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ mod tests {
984984

985985
#[test]
986986
fn test_basic() {
987-
let mut m = LinkedList::new();
987+
let mut m = LinkedList::<Box<_>>::new();
988988
assert_eq!(m.pop_front(), None);
989989
assert_eq!(m.pop_back(), None);
990990
assert_eq!(m.pop_front(), None);

src/libcollections/slice.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,7 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> Order
15091509

15101510
#[cfg(test)]
15111511
mod tests {
1512+
use alloc::boxed::Box;
15121513
use core::cmp::Ordering::{Greater, Less, Equal};
15131514
use core::prelude::{Some, None, Clone};
15141515
use core::prelude::{Iterator, IteratorExt};
@@ -1799,7 +1800,7 @@ mod tests {
17991800
#[test]
18001801
fn test_swap_remove_noncopyable() {
18011802
// Tests that we don't accidentally run destructors twice.
1802-
let mut v = Vec::new();
1803+
let mut v: Vec<Box<_>> = Vec::new();
18031804
v.push(box 0u8);
18041805
v.push(box 0u8);
18051806
v.push(box 0u8);
@@ -1828,7 +1829,7 @@ mod tests {
18281829

18291830
#[test]
18301831
fn test_truncate() {
1831-
let mut v = vec![box 6,box 5,box 4];
1832+
let mut v: Vec<Box<_>> = vec![box 6,box 5,box 4];
18321833
v.truncate(1);
18331834
let v = v;
18341835
assert_eq!(v.len(), 1);
@@ -1838,7 +1839,7 @@ mod tests {
18381839

18391840
#[test]
18401841
fn test_clear() {
1841-
let mut v = vec![box 6,box 5,box 4];
1842+
let mut v: Vec<Box<_>> = vec![box 6,box 5,box 4];
18421843
v.clear();
18431844
assert_eq!(v.len(), 0);
18441845
// If the unsafe block didn't drop things properly, we blow up here.
@@ -1863,11 +1864,11 @@ mod tests {
18631864

18641865
#[test]
18651866
fn test_dedup_unique() {
1866-
let mut v0 = vec![box 1, box 1, box 2, box 3];
1867+
let mut v0: Vec<Box<_>> = vec![box 1, box 1, box 2, box 3];
18671868
v0.dedup();
1868-
let mut v1 = vec![box 1, box 2, box 2, box 3];
1869+
let mut v1: Vec<Box<_>> = vec![box 1, box 2, box 2, box 3];
18691870
v1.dedup();
1870-
let mut v2 = vec![box 1, box 2, box 3, box 3];
1871+
let mut v2: Vec<Box<_>> = vec![box 1, box 2, box 3, box 3];
18711872
v2.dedup();
18721873
/*
18731874
* If the boxed pointers were leaked or otherwise misused, valgrind
@@ -1877,11 +1878,11 @@ mod tests {
18771878

18781879
#[test]
18791880
fn test_dedup_shared() {
1880-
let mut v0 = vec![box 1, box 1, box 2, box 3];
1881+
let mut v0: Vec<Box<_>> = vec![box 1, box 1, box 2, box 3];
18811882
v0.dedup();
1882-
let mut v1 = vec![box 1, box 2, box 2, box 3];
1883+
let mut v1: Vec<Box<_>> = vec![box 1, box 2, box 2, box 3];
18831884
v1.dedup();
1884-
let mut v2 = vec![box 1, box 2, box 3, box 3];
1885+
let mut v2: Vec<Box<_>> = vec![box 1, box 2, box 3, box 3];
18851886
v2.dedup();
18861887
/*
18871888
* If the pointers were leaked or otherwise misused, valgrind and/or
@@ -2254,8 +2255,9 @@ mod tests {
22542255
#[test]
22552256
#[should_fail]
22562257
fn test_permute_fail() {
2257-
let v = [(box 0, Rc::new(0)), (box 0, Rc::new(0)),
2258-
(box 0, Rc::new(0)), (box 0, Rc::new(0))];
2258+
let v: [(Box<_>, Rc<_>); 4] =
2259+
[(box 0, Rc::new(0)), (box 0, Rc::new(0)),
2260+
(box 0, Rc::new(0)), (box 0, Rc::new(0))];
22592261
let mut i = 0;
22602262
for _ in v.permutations() {
22612263
if i == 2 {
@@ -2849,7 +2851,7 @@ mod tests {
28492851

28502852
#[test]
28512853
fn test_to_vec() {
2852-
let xs = box [1, 2, 3];
2854+
let xs: Box<_> = box [1, 2, 3];
28532855
let ys = xs.to_vec();
28542856
assert_eq!(ys, [1, 2, 3]);
28552857
}

src/libcollections/vec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,8 +2130,8 @@ mod tests {
21302130
#[test]
21312131
fn test_clone_from() {
21322132
let mut v = vec!();
2133-
let three = vec!(box 1, box 2, box 3);
2134-
let two = vec!(box 4, box 5);
2133+
let three: Vec<Box<_>> = vec!(box 1, box 2, box 3);
2134+
let two: Vec<Box<_>> = vec!(box 4, box 5);
21352135
// zero, long
21362136
v.clone_from(&three);
21372137
assert_eq!(v, three);

src/libcollections/vec_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ mod test_map {
12051205

12061206
#[test]
12071207
fn test_move_iter() {
1208-
let mut m = VecMap::new();
1208+
let mut m: VecMap<Box<_>> = VecMap::new();
12091209
m.insert(1, box 2);
12101210
let mut called = false;
12111211
for (k, v) in m {

0 commit comments

Comments
 (0)