diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-05-30 14:33:48 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-30 14:33:48 +0200 |
| commit | 0ed320bdb9dff0f26f682cd6c9ccd6bfbffe5df8 (patch) | |
| tree | b2aa9546006a30e5d1ae2c9dc1e03b1dc2df6340 /library/std/src | |
| parent | 5c780b98d10f48d6255cf2deb2643194b9221c02 (diff) | |
| parent | cdb8e64bc78400f9366db3b556bb01f470855f55 (diff) | |
| download | rust-0ed320bdb9dff0f26f682cd6c9ccd6bfbffe5df8.tar.gz rust-0ed320bdb9dff0f26f682cd6c9ccd6bfbffe5df8.zip | |
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).
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/io/error/tests.rs | 6 | ||||
| -rw-r--r-- | library/std/src/sync/mpsc/mpsc_queue/tests.rs | 4 | ||||
| -rw-r--r-- | library/std/src/sync/mpsc/spsc_queue/tests.rs | 4 | ||||
| -rw-r--r-- | library/std/src/sync/mpsc/sync_tests.rs | 12 | ||||
| -rw-r--r-- | library/std/src/sync/mpsc/tests.rs | 14 | ||||
| -rw-r--r-- | library/std/src/thread/tests.rs | 4 |
6 files changed, 22 insertions, 22 deletions
diff --git a/library/std/src/io/error/tests.rs b/library/std/src/io/error/tests.rs index 6fd15fa8048..8d7877bcad3 100644 --- a/library/std/src/io/error/tests.rs +++ b/library/std/src/io/error/tests.rs @@ -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 {{ \ diff --git a/library/std/src/sync/mpsc/mpsc_queue/tests.rs b/library/std/src/sync/mpsc/mpsc_queue/tests.rs index 348b83424b0..9f4f31ed051 100644 --- a/library/std/src/sync/mpsc/mpsc_queue/tests.rs +++ b/library/std/src/sync/mpsc/mpsc_queue/tests.rs @@ -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] diff --git a/library/std/src/sync/mpsc/spsc_queue/tests.rs b/library/std/src/sync/mpsc/spsc_queue/tests.rs index e4fd15cbbde..467ef3dbdcb 100644 --- a/library/std/src/sync/mpsc/spsc_queue/tests.rs +++ b/library/std/src/sync/mpsc/spsc_queue/tests.rs @@ -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)); } } diff --git a/library/std/src/sync/mpsc/sync_tests.rs b/library/std/src/sync/mpsc/sync_tests.rs index 0052a38f7bb..e58649bab6e 100644 --- a/library/std/src/sync/mpsc/sync_tests.rs +++ b/library/std/src/sync/mpsc/sync_tests.rs @@ -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); }); } diff --git a/library/std/src/sync/mpsc/tests.rs b/library/std/src/sync/mpsc/tests.rs index 184ce193cbe..4deb3e59615 100644 --- a/library/std/src/sync/mpsc/tests.rs +++ b/library/std/src/sync/mpsc/tests.rs @@ -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); }); } diff --git a/library/std/src/thread/tests.rs b/library/std/src/thread/tests.rs index 7386fe1c442..5b8309cf5d2 100644 --- a/library/std/src/thread/tests.rs +++ b/library/std/src/thread/tests.rs @@ -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() { |
