1
Fork 0

Rollup merge of #97494 - est31:remove_box_alloc_tests, r=Dylan-DPC

Use Box::new() instead of box syntax in library tests

The tests inside `library/*` have no reason to use `box` syntax as they have 0 performance relevance. Therefore, we can safely remove them (instead of having to use alternatives like the one in #97293).
This commit is contained in:
Dylan DPC 2022-05-30 14:33:48 +02:00 committed by GitHub
commit 0ed320bdb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 86 additions and 82 deletions

View file

@ -17,10 +17,10 @@ fn test_debug_error() {
let msg = error_string(code);
let kind = decode_error_kind(code);
let err = Error {
repr: Repr::new_custom(box Custom {
repr: Repr::new_custom(Box::new(Custom {
kind: ErrorKind::InvalidInput,
error: box Error { repr: super::Repr::new_os(code) },
}),
error: Box::new(Error { repr: super::Repr::new_os(code) }),
})),
};
let expected = format!(
"Custom {{ \

View file

@ -6,8 +6,8 @@ use crate::thread;
#[test]
fn test_full() {
let q: Queue<Box<_>> = Queue::new();
q.push(box 1);
q.push(box 2);
q.push(Box::new(1));
q.push(Box::new(2));
}
#[test]

View file

@ -47,8 +47,8 @@ fn peek() {
fn drop_full() {
unsafe {
let q: Queue<Box<_>> = Queue::with_additions(0, (), ());
q.push(box 1);
q.push(box 2);
q.push(Box::new(1));
q.push(Box::new(2));
}
}

View file

@ -20,7 +20,7 @@ fn smoke() {
#[test]
fn drop_full() {
let (tx, _rx) = sync_channel::<Box<isize>>(1);
tx.send(box 1).unwrap();
tx.send(Box::new(1)).unwrap();
}
#[test]
@ -238,7 +238,7 @@ fn oneshot_single_thread_send_port_close() {
// Testing that the sender cleans up the payload if receiver is closed
let (tx, rx) = sync_channel::<Box<i32>>(0);
drop(rx);
assert!(tx.send(box 0).is_err());
assert!(tx.send(Box::new(0)).is_err());
}
#[test]
@ -257,7 +257,7 @@ fn oneshot_single_thread_recv_chan_close() {
#[test]
fn oneshot_single_thread_send_then_recv() {
let (tx, rx) = sync_channel::<Box<i32>>(1);
tx.send(box 10).unwrap();
tx.send(Box::new(10)).unwrap();
assert!(*rx.recv().unwrap() == 10);
}
@ -333,7 +333,7 @@ fn oneshot_multi_task_recv_then_send() {
assert!(*rx.recv().unwrap() == 10);
});
tx.send(box 10).unwrap();
tx.send(Box::new(10)).unwrap();
}
#[test]
@ -398,7 +398,7 @@ fn oneshot_multi_thread_send_recv_stress() {
for _ in 0..stress_factor() {
let (tx, rx) = sync_channel::<Box<i32>>(0);
let _t = thread::spawn(move || {
tx.send(box 10).unwrap();
tx.send(Box::new(10)).unwrap();
});
assert!(*rx.recv().unwrap() == 10);
}
@ -418,7 +418,7 @@ fn stream_send_recv_stress() {
}
thread::spawn(move || {
tx.send(box i).unwrap();
tx.send(Box::new(i)).unwrap();
send(tx, i + 1);
});
}

View file

@ -20,7 +20,7 @@ fn smoke() {
#[test]
fn drop_full() {
let (tx, _rx) = channel::<Box<isize>>();
tx.send(box 1).unwrap();
tx.send(Box::new(1)).unwrap();
}
#[test]
@ -28,7 +28,7 @@ fn drop_full_shared() {
let (tx, _rx) = channel::<Box<isize>>();
drop(tx.clone());
drop(tx.clone());
tx.send(box 1).unwrap();
tx.send(Box::new(1)).unwrap();
}
#[test]
@ -229,7 +229,7 @@ fn oneshot_single_thread_send_port_close() {
// Testing that the sender cleans up the payload if receiver is closed
let (tx, rx) = channel::<Box<i32>>();
drop(rx);
assert!(tx.send(box 0).is_err());
assert!(tx.send(Box::new(0)).is_err());
}
#[test]
@ -248,7 +248,7 @@ fn oneshot_single_thread_recv_chan_close() {
#[test]
fn oneshot_single_thread_send_then_recv() {
let (tx, rx) = channel::<Box<i32>>();
tx.send(box 10).unwrap();
tx.send(Box::new(10)).unwrap();
assert!(*rx.recv().unwrap() == 10);
}
@ -309,7 +309,7 @@ fn oneshot_multi_task_recv_then_send() {
assert!(*rx.recv().unwrap() == 10);
});
tx.send(box 10).unwrap();
tx.send(Box::new(10)).unwrap();
}
#[test]
@ -374,7 +374,7 @@ fn oneshot_multi_thread_send_recv_stress() {
for _ in 0..stress_factor() {
let (tx, rx) = channel::<Box<isize>>();
let _t = thread::spawn(move || {
tx.send(box 10).unwrap();
tx.send(Box::new(10)).unwrap();
});
assert!(*rx.recv().unwrap() == 10);
}
@ -394,7 +394,7 @@ fn stream_send_recv_stress() {
}
thread::spawn(move || {
tx.send(box i).unwrap();
tx.send(Box::new(i)).unwrap();
send(tx, i + 1);
});
}

View file

@ -127,7 +127,7 @@ where
{
let (tx, rx) = channel();
let x: Box<_> = box 1;
let x: Box<_> = Box::new(1);
let x_in_parent = (&*x) as *const i32 as usize;
spawnfn(Box::new(move || {
@ -219,7 +219,7 @@ fn test_try_panic_any_message_owned_str() {
#[test]
fn test_try_panic_any_message_any() {
match thread::spawn(move || {
panic_any(box 413u16 as Box<dyn Any + Send>);
panic_any(Box::new(413u16) as Box<dyn Any + Send>);
})
.join()
{