From 7230a15c32d01e1653d98c39ddd79097a59b550c Mon Sep 17 00:00:00 2001 From: est31 Date: Sat, 28 May 2022 23:22:07 +0200 Subject: [PATCH] Use Box::new() instead of box syntax in alloc tests --- library/alloc/src/alloc/tests.rs | 2 +- .../src/collections/binary_heap/tests.rs | 12 +++++----- library/alloc/src/collections/linked_list.rs | 4 ++-- .../src/collections/linked_list/tests.rs | 22 +++++++++---------- library/alloc/src/rc.rs | 7 +++--- library/alloc/src/rc/tests.rs | 12 +++++----- library/alloc/src/sync.rs | 8 +++---- library/alloc/src/sync/tests.rs | 10 ++++----- library/alloc/tests/slice.rs | 14 ++++++------ library/alloc/tests/vec.rs | 10 ++++----- 10 files changed, 51 insertions(+), 50 deletions(-) diff --git a/library/alloc/src/alloc/tests.rs b/library/alloc/src/alloc/tests.rs index 94e05fa448f..7d560964d85 100644 --- a/library/alloc/src/alloc/tests.rs +++ b/library/alloc/src/alloc/tests.rs @@ -25,6 +25,6 @@ fn allocate_zeroed() { #[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks fn alloc_owned_small(b: &mut Bencher) { b.iter(|| { - let _: Box<_> = box 10; + let _: Box<_> = Box::new(10); }) } diff --git a/library/alloc/src/collections/binary_heap/tests.rs b/library/alloc/src/collections/binary_heap/tests.rs index 7c758dbb3ab..5a05215aeed 100644 --- a/library/alloc/src/collections/binary_heap/tests.rs +++ b/library/alloc/src/collections/binary_heap/tests.rs @@ -183,22 +183,22 @@ fn test_push() { #[test] fn test_push_unique() { - let mut heap = BinaryHeap::>::from(vec![box 2, box 4, box 9]); + let mut heap = BinaryHeap::>::from(vec![Box::new(2), Box::new(4), Box::new(9)]); assert_eq!(heap.len(), 3); assert!(**heap.peek().unwrap() == 9); - heap.push(box 11); + heap.push(Box::new(11)); assert_eq!(heap.len(), 4); assert!(**heap.peek().unwrap() == 11); - heap.push(box 5); + heap.push(Box::new(5)); assert_eq!(heap.len(), 5); assert!(**heap.peek().unwrap() == 11); - heap.push(box 27); + heap.push(Box::new(27)); assert_eq!(heap.len(), 6); assert!(**heap.peek().unwrap() == 27); - heap.push(box 3); + heap.push(Box::new(3)); assert_eq!(heap.len(), 7); assert!(**heap.peek().unwrap() == 27); - heap.push(box 103); + heap.push(Box::new(103)); assert_eq!(heap.len(), 8); assert!(**heap.peek().unwrap() == 103); } diff --git a/library/alloc/src/collections/linked_list.rs b/library/alloc/src/collections/linked_list.rs index 67dc4f30f31..e21c8aa3bd5 100644 --- a/library/alloc/src/collections/linked_list.rs +++ b/library/alloc/src/collections/linked_list.rs @@ -791,7 +791,7 @@ pub fn back_mut(&mut self) -> Option<&mut T> { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn push_front(&mut self, elt: T) { - self.push_front_node(box Node::new(elt)); + self.push_front_node(Box::new(Node::new(elt))); } /// Removes the first element and returns it, or `None` if the list is @@ -834,7 +834,7 @@ pub fn pop_front(&mut self) -> Option { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn push_back(&mut self, elt: T) { - self.push_back_node(box Node::new(elt)); + self.push_back_node(Box::new(Node::new(elt))); } /// Removes the last element from a list and returns it, or `None` if diff --git a/library/alloc/src/collections/linked_list/tests.rs b/library/alloc/src/collections/linked_list/tests.rs index 38c702aa387..f8fbfa1bfbc 100644 --- a/library/alloc/src/collections/linked_list/tests.rs +++ b/library/alloc/src/collections/linked_list/tests.rs @@ -12,20 +12,20 @@ fn test_basic() { assert_eq!(m.pop_front(), None); assert_eq!(m.pop_back(), None); assert_eq!(m.pop_front(), None); - m.push_front(box 1); - assert_eq!(m.pop_front(), Some(box 1)); - m.push_back(box 2); - m.push_back(box 3); + m.push_front(Box::new(1)); + assert_eq!(m.pop_front(), Some(Box::new(1))); + m.push_back(Box::new(2)); + m.push_back(Box::new(3)); assert_eq!(m.len(), 2); - assert_eq!(m.pop_front(), Some(box 2)); - assert_eq!(m.pop_front(), Some(box 3)); + assert_eq!(m.pop_front(), Some(Box::new(2))); + assert_eq!(m.pop_front(), Some(Box::new(3))); assert_eq!(m.len(), 0); assert_eq!(m.pop_front(), None); - m.push_back(box 1); - m.push_back(box 3); - m.push_back(box 5); - m.push_back(box 7); - assert_eq!(m.pop_front(), Some(box 1)); + m.push_back(Box::new(1)); + m.push_back(Box::new(3)); + m.push_back(Box::new(5)); + m.push_back(Box::new(7)); + assert_eq!(m.pop_front(), Some(Box::new(1))); let mut n = LinkedList::new(); n.push_front(2); diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 52957456473..2b3736019ba 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -369,7 +369,8 @@ pub fn new(value: T) -> Rc { // if the weak pointer is stored inside the strong one. unsafe { Self::from_inner( - Box::leak(box RcBox { strong: Cell::new(1), weak: Cell::new(1), value }).into(), + Box::leak(Box::new(RcBox { strong: Cell::new(1), weak: Cell::new(1), value })) + .into(), ) } } @@ -433,11 +434,11 @@ pub fn new_cyclic(data_fn: F) -> Rc { // Construct the inner in the "uninitialized" state with a single // weak reference. - let uninit_ptr: NonNull<_> = Box::leak(box RcBox { + let uninit_ptr: NonNull<_> = Box::leak(Box::new(RcBox { strong: Cell::new(0), weak: Cell::new(1), value: mem::MaybeUninit::::uninit(), - }) + })) .into(); let init_ptr: NonNull> = uninit_ptr.cast(); diff --git a/library/alloc/src/rc/tests.rs b/library/alloc/src/rc/tests.rs index d7c28f80633..32433cfbdcf 100644 --- a/library/alloc/src/rc/tests.rs +++ b/library/alloc/src/rc/tests.rs @@ -32,7 +32,7 @@ fn test_simple_clone() { #[test] fn test_destructor() { - let x: Rc> = Rc::new(box 5); + let x: Rc> = Rc::new(Box::new(5)); assert_eq!(**x, 5); } @@ -153,7 +153,7 @@ fn try_unwrap() { #[test] fn into_from_raw() { - let x = Rc::new(box "hello"); + let x = Rc::new(Box::new("hello")); let y = x.clone(); let x_ptr = Rc::into_raw(x); @@ -192,7 +192,7 @@ fn test_into_from_raw_unsized() { #[test] fn into_from_weak_raw() { - let x = Rc::new(box "hello"); + let x = Rc::new(Box::new("hello")); let y = Rc::downgrade(&x); let y_ptr = Weak::into_raw(y); @@ -409,7 +409,7 @@ fn clone(&self) -> Fail { #[test] fn test_from_box() { - let b: Box = box 123; + let b: Box = Box::new(123); let r: Rc = Rc::from(b); assert_eq!(*r, 123); @@ -438,7 +438,7 @@ fn test_from_box_trait() { use std::fmt::Display; use std::string::ToString; - let b: Box = box 123; + let b: Box = Box::new(123); let r: Rc = Rc::from(b); assert_eq!(r.to_string(), "123"); @@ -448,7 +448,7 @@ fn test_from_box_trait() { fn test_from_box_trait_zero_sized() { use std::fmt::Debug; - let b: Box = box (); + let b: Box = Box::new(()); let r: Rc = Rc::from(b); assert_eq!(format!("{r:?}"), "()"); diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 06aecd9cc1e..d5ed3fd18c3 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -343,11 +343,11 @@ impl Arc { pub fn new(data: T) -> Arc { // 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<_> = box ArcInner { + let x: Box<_> = Box::new(ArcInner { strong: atomic::AtomicUsize::new(1), weak: atomic::AtomicUsize::new(1), data, - }; + }); unsafe { Self::from_inner(Box::leak(x).into()) } } @@ -411,11 +411,11 @@ pub fn new_cyclic(data_fn: F) -> Arc { // Construct the inner in the "uninitialized" state with a single // weak reference. - let uninit_ptr: NonNull<_> = Box::leak(box ArcInner { + let uninit_ptr: NonNull<_> = Box::leak(Box::new(ArcInner { strong: atomic::AtomicUsize::new(0), weak: atomic::AtomicUsize::new(1), data: mem::MaybeUninit::::uninit(), - }) + })) .into(); let init_ptr: NonNull> = uninit_ptr.cast(); diff --git a/library/alloc/src/sync/tests.rs b/library/alloc/src/sync/tests.rs index 452a8877301..202d0e7f020 100644 --- a/library/alloc/src/sync/tests.rs +++ b/library/alloc/src/sync/tests.rs @@ -103,7 +103,7 @@ fn try_unwrap() { #[test] fn into_from_raw() { - let x = Arc::new(box "hello"); + let x = Arc::new(Box::new("hello")); let y = x.clone(); let x_ptr = Arc::into_raw(x); @@ -142,7 +142,7 @@ fn test_into_from_raw_unsized() { #[test] fn into_from_weak_raw() { - let x = Arc::new(box "hello"); + let x = Arc::new(Box::new("hello")); let y = Arc::downgrade(&x); let y_ptr = Weak::into_raw(y); @@ -467,7 +467,7 @@ fn clone(&self) -> Fail { #[test] fn test_from_box() { - let b: Box = box 123; + let b: Box = Box::new(123); let r: Arc = Arc::from(b); assert_eq!(*r, 123); @@ -496,7 +496,7 @@ fn test_from_box_trait() { use std::fmt::Display; use std::string::ToString; - let b: Box = box 123; + let b: Box = Box::new(123); let r: Arc = Arc::from(b); assert_eq!(r.to_string(), "123"); @@ -506,7 +506,7 @@ fn test_from_box_trait() { fn test_from_box_trait_zero_sized() { use std::fmt::Debug; - let b: Box = box (); + let b: Box = Box::new(()); let r: Arc = Arc::from(b); assert_eq!(format!("{r:?}"), "()"); diff --git a/library/alloc/tests/slice.rs b/library/alloc/tests/slice.rs index b027a25a146..21f894343be 100644 --- a/library/alloc/tests/slice.rs +++ b/library/alloc/tests/slice.rs @@ -268,9 +268,9 @@ fn test_swap_remove_fail() { fn test_swap_remove_noncopyable() { // Tests that we don't accidentally run destructors twice. let mut v: Vec> = Vec::new(); - v.push(box 0); - v.push(box 0); - v.push(box 0); + v.push(Box::new(0)); + v.push(Box::new(0)); + v.push(Box::new(0)); let mut _e = v.swap_remove(0); assert_eq!(v.len(), 2); _e = v.swap_remove(1); @@ -296,7 +296,7 @@ fn test_push() { #[test] fn test_truncate() { - let mut v: Vec> = vec![box 6, box 5, box 4]; + let mut v: Vec> = vec![Box::new(6), Box::new(5), Box::new(4)]; v.truncate(1); let v = v; assert_eq!(v.len(), 1); @@ -306,7 +306,7 @@ fn test_truncate() { #[test] fn test_clear() { - let mut v: Vec> = vec![box 6, box 5, box 4]; + let mut v: Vec> = vec![Box::new(6), Box::new(5), Box::new(4)]; v.clear(); assert_eq!(v.len(), 0); // If the unsafe block didn't drop things properly, we blow up here. @@ -1516,14 +1516,14 @@ fn test_mut_last() { #[test] fn test_to_vec() { - let xs: Box<_> = box [1, 2, 3]; + let xs: Box<_> = Box::new([1, 2, 3]); let ys = xs.to_vec(); assert_eq!(ys, [1, 2, 3]); } #[test] fn test_in_place_iterator_specialization() { - let src: Box<[usize]> = box [1, 2, 3]; + let src: Box<[usize]> = Box::new([1, 2, 3]); let src_ptr = src.as_ptr(); let sink: Box<_> = src.into_vec().into_iter().map(std::convert::identity).collect(); let sink_ptr = sink.as_ptr(); diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index bc1397146dd..cc768c73c0e 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -266,8 +266,8 @@ fn test_clone() { #[test] fn test_clone_from() { let mut v = vec![]; - let three: Vec> = vec![box 1, box 2, box 3]; - let two: Vec> = vec![box 4, box 5]; + let three: Vec> = vec![Box::new(1), Box::new(2), Box::new(3)]; + let two: Vec> = vec![Box::new(4), Box::new(5)]; // zero, long v.clone_from(&three); assert_eq!(v, three); @@ -407,11 +407,11 @@ fn test_dedup_by() { #[test] fn test_dedup_unique() { - let mut v0: Vec> = vec![box 1, box 1, box 2, box 3]; + let mut v0: Vec> = vec![Box::new(1), Box::new(1), Box::new(2), Box::new(3)]; v0.dedup(); - let mut v1: Vec> = vec![box 1, box 2, box 2, box 3]; + let mut v1: Vec> = vec![Box::new(1), Box::new(2), Box::new(2), Box::new(3)]; v1.dedup(); - let mut v2: Vec> = vec![box 1, box 2, box 3, box 3]; + let mut v2: Vec> = vec![Box::new(1), Box::new(2), Box::new(3), Box::new(3)]; v2.dedup(); // If the boxed pointers were leaked or otherwise misused, valgrind // and/or rt should raise errors. -- 2.44.0