Skip to content

Commit

Permalink
Use Box::new() instead of box syntax in core tests
Browse files Browse the repository at this point in the history
  • Loading branch information
est31 committed May 28, 2022
1 parent d75c60f commit cdb8e64
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
9 changes: 6 additions & 3 deletions library/core/tests/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ fn any_referenced() {

#[test]
fn any_owning() {
let (a, b, c) =
(box 5_usize as Box<dyn Any>, box TEST as Box<dyn Any>, box Test as Box<dyn Any>);
let (a, b, c) = (
Box::new(5_usize) as Box<dyn Any>,
Box::new(TEST) as Box<dyn Any>,
Box::new(Test) as Box<dyn Any>,
);

assert!(a.is::<usize>());
assert!(!b.is::<usize>());
Expand Down Expand Up @@ -58,7 +61,7 @@ fn any_downcast_ref() {
#[test]
fn any_downcast_mut() {
let mut a = 5_usize;
let mut b: Box<_> = box 7_usize;
let mut b: Box<_> = Box::new(7_usize);

let a_r = &mut a as &mut dyn Any;
let tmp: &mut usize = &mut *b;
Expand Down
4 changes: 2 additions & 2 deletions library/core/tests/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ fn test_borrowed_clone() {

#[test]
fn test_clone_from() {
let a = box 5;
let mut b = box 10;
let a = Box::new(5);
let mut b = Box::new(10);
b.clone_from(&a);
assert_eq!(*b, 5);
}
3 changes: 2 additions & 1 deletion library/core/tests/iter/traits/double_ended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ fn test_rev_rposition() {
#[test]
#[should_panic]
fn test_rposition_panic() {
let v: [(Box<_>, Box<_>); 4] = [(box 0, box 0), (box 0, box 0), (box 0, box 0), (box 0, box 0)];
let u = (Box::new(0), Box::new(0));
let v: [(Box<_>, Box<_>); 4] = [u.clone(), u.clone(), u.clone(), u];
let mut i = 0;
v.iter().rposition(|_elt| {
if i == 2 {
Expand Down
1 change: 0 additions & 1 deletion library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#![feature(array_methods)]
#![feature(array_windows)]
#![feature(bench_black_box)]
#![feature(box_syntax)]
#![feature(cell_update)]
#![feature(const_assume)]
#![feature(const_black_box)]
Expand Down
4 changes: 2 additions & 2 deletions library/core/tests/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use core::option::*;
#[test]
fn test_get_ptr() {
unsafe {
let x: Box<_> = box 0;
let x: Box<_> = Box::new(0);
let addr_x: *const isize = mem::transmute(&*x);
let opt = Some(x);
let y = opt.unwrap();
Expand Down Expand Up @@ -315,7 +315,7 @@ fn test_collect() {

// test that it does not take more elements than it needs
let mut functions: [Box<dyn Fn() -> Option<()>>; 3] =
[box || Some(()), box || None, box || panic!()];
[Box::new(|| Some(())), Box::new(|| None), Box::new(|| panic!())];

let v: Option<Vec<()>> = functions.iter_mut().map(|f| (*f)()).collect();

Expand Down
2 changes: 1 addition & 1 deletion library/core/tests/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn test_collect() {

// test that it does not take more elements than it needs
let mut functions: [Box<dyn Fn() -> Result<(), isize>>; 3] =
[box || Ok(()), box || Err(1), box || panic!()];
[Box::new(|| Ok(())), Box::new(|| Err(1)), Box::new(|| panic!())];

let v: Result<Vec<()>, isize> = functions.iter_mut().map(|f| (*f)()).collect();
assert!(v == Err(1));
Expand Down

0 comments on commit cdb8e64

Please sign in to comment.