diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-01 04:49:31 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-01 04:49:31 +0100 |
| commit | 3db3f156f11cd16fe07a0b90c26740737e29be60 (patch) | |
| tree | f710d1d16b622b45c84364e6cbfc6e4259f1841d /src/liballoc/tests | |
| parent | d4f59564e7898adcce6eaf432e710337ba8cca4c (diff) | |
| parent | 1c4d4539690fe841aefea2f54c243be5f0579970 (diff) | |
| download | rust-3db3f156f11cd16fe07a0b90c26740737e29be60.tar.gz rust-3db3f156f11cd16fe07a0b90c26740737e29be60.zip | |
Rollup merge of #66890 - dtolnay:fmt4, r=Dylan-DPC
Format liballoc with rustfmt
Same strategy as #66691 -- as with my previous formatting PRs, I am avoiding causing merge conflicts in other PRs by only touches those files that are not involved in any currently open PR. Files that appear in new PRs between when this PR is opened and when it makes it to the top of the bors queue will be reverted from this PR.
The list of files involved in open PRs is determined by querying GitHub's GraphQL API [with this script](https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8).
With the list of files from the script in outstanding_files, the relevant commands were:
```
$ find src/liballoc -name '*.rs' \
| xargs rustfmt --edition=2018 --unstable-features --skip-children
$ rg liballoc outstanding_files | xargs git checkout --
```
To confirm no funny business:
```
$ git checkout $THIS_COMMIT^
$ git show --pretty= --name-only $THIS_COMMIT \
| xargs rustfmt --edition=2018 --unstable-features --skip-children
$ git diff $THIS_COMMIT # there should be no difference
```
r? @Dylan-DPC
Diffstat (limited to 'src/liballoc/tests')
| -rw-r--r-- | src/liballoc/tests/arc.rs | 39 | ||||
| -rw-r--r-- | src/liballoc/tests/boxed.rs | 2 | ||||
| -rw-r--r-- | src/liballoc/tests/btree/mod.rs | 7 | ||||
| -rw-r--r-- | src/liballoc/tests/linked_list.rs | 75 | ||||
| -rw-r--r-- | src/liballoc/tests/rc.rs | 41 | ||||
| -rw-r--r-- | src/liballoc/tests/vec_deque.rs | 166 |
6 files changed, 144 insertions, 186 deletions
diff --git a/src/liballoc/tests/arc.rs b/src/liballoc/tests/arc.rs index cf2ad2a8e60..2fbb59b0419 100644 --- a/src/liballoc/tests/arc.rs +++ b/src/liballoc/tests/arc.rs @@ -1,9 +1,9 @@ use std::any::Any; -use std::sync::{Arc, Weak}; use std::cell::RefCell; use std::cmp::PartialEq; use std::iter::TrustedLen; use std::mem; +use std::sync::{Arc, Weak}; #[test] fn uninhabited() { @@ -12,7 +12,7 @@ fn uninhabited() { a = a.clone(); assert!(a.upgrade().is_none()); - let mut a: Weak<dyn Any> = a; // Unsizing + let mut a: Weak<dyn Any> = a; // Unsizing a = a.clone(); assert!(a.upgrade().is_none()); } @@ -20,8 +20,8 @@ fn uninhabited() { #[test] fn slice() { let a: Arc<[u32; 3]> = Arc::new([3, 2, 1]); - let a: Arc<[u32]> = a; // Unsizing - let b: Arc<[u32]> = Arc::from(&[3, 2, 1][..]); // Conversion + let a: Arc<[u32]> = a; // Unsizing + let b: Arc<[u32]> = Arc::from(&[3, 2, 1][..]); // Conversion assert_eq!(a, b); // Exercise is_dangling() with a DST @@ -33,7 +33,7 @@ fn slice() { #[test] fn trait_object() { let a: Arc<u32> = Arc::new(4); - let a: Arc<dyn Any> = a; // Unsizing + let a: Arc<dyn Any> = a; // Unsizing // Exercise is_dangling() with a DST let mut a = Arc::downgrade(&a); @@ -43,7 +43,7 @@ fn trait_object() { let mut b = Weak::<u32>::new(); b = b.clone(); assert!(b.upgrade().is_none()); - let mut b: Weak<dyn Any> = b; // Unsizing + let mut b: Weak<dyn Any> = b; // Unsizing b = b.clone(); assert!(b.upgrade().is_none()); } @@ -57,7 +57,7 @@ fn float_nan_ne() { #[test] fn partial_eq() { - struct TestPEq (RefCell<usize>); + struct TestPEq(RefCell<usize>); impl PartialEq for TestPEq { fn eq(&self, other: &TestPEq) -> bool { *self.0.borrow_mut() += 1; @@ -74,7 +74,7 @@ fn partial_eq() { #[test] fn eq() { #[derive(Eq)] - struct TestEq (RefCell<usize>); + struct TestEq(RefCell<usize>); impl PartialEq for TestEq { fn eq(&self, other: &TestEq) -> bool { *self.0.borrow_mut() += 1; @@ -160,13 +160,10 @@ fn shared_from_iter_trustedlen_normal() { fn shared_from_iter_trustedlen_panic() { // Exercise the `TrustedLen` implementation when `size_hint()` matches // `(_, Some(exact_len))` but where `.next()` drops before the last iteration. - let iter = (0..SHARED_ITER_MAX) - .map(|val| { - match val { - 98 => panic!("I've almost got 99 problems."), - _ => Box::new(val), - } - }); + let iter = (0..SHARED_ITER_MAX).map(|val| match val { + 98 => panic!("I've almost got 99 problems."), + _ => Box::new(val), + }); assert_trusted_len(&iter); let _ = iter.collect::<Rc<[_]>>(); @@ -193,16 +190,8 @@ fn shared_from_iter_trustedlen_no_fuse() { } } - let vec = vec![ - Some(Box::new(42)), - Some(Box::new(24)), - None, - Some(Box::new(12)), - ]; + let vec = vec![Some(Box::new(42)), Some(Box::new(24)), None, Some(Box::new(12))]; let iter = Iter(vec.into_iter()); assert_trusted_len(&iter); - assert_eq!( - &[Box::new(42), Box::new(24)], - &*iter.collect::<Rc<[_]>>() - ); + assert_eq!(&[Box::new(42), Box::new(24)], &*iter.collect::<Rc<[_]>>()); } diff --git a/src/liballoc/tests/boxed.rs b/src/liballoc/tests/boxed.rs index bc3d53bf30d..66782ecbeb7 100644 --- a/src/liballoc/tests/boxed.rs +++ b/src/liballoc/tests/boxed.rs @@ -1,5 +1,5 @@ -use std::ptr::NonNull; use std::mem::MaybeUninit; +use std::ptr::NonNull; #[test] fn unitialized_zero_size_box() { diff --git a/src/liballoc/tests/btree/mod.rs b/src/liballoc/tests/btree/mod.rs index 4c704d0f8c2..1d08ae13e05 100644 --- a/src/liballoc/tests/btree/mod.rs +++ b/src/liballoc/tests/btree/mod.rs @@ -11,12 +11,7 @@ struct DeterministicRng { impl DeterministicRng { fn new() -> Self { - DeterministicRng { - x: 0x193a6754, - y: 0xa8a7d469, - z: 0x97830e05, - w: 0x113ba7bb, - } + DeterministicRng { x: 0x193a6754, y: 0xa8a7d469, z: 0x97830e05, w: 0x113ba7bb } } fn next(&mut self) -> u32 { diff --git a/src/liballoc/tests/linked_list.rs b/src/liballoc/tests/linked_list.rs index 8a26454c389..daa49c48c6a 100644 --- a/src/liballoc/tests/linked_list.rs +++ b/src/liballoc/tests/linked_list.rs @@ -102,7 +102,6 @@ fn test_split_off() { assert_eq!(m.back(), Some(&1)); assert_eq!(m.front(), Some(&1)); } - } #[test] @@ -305,8 +304,7 @@ fn test_show() { assert_eq!(format!("{:?}", list), "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"); let list: LinkedList<_> = vec!["just", "one", "test", "more"].iter().cloned().collect(); - assert_eq!(format!("{:?}", list), - "[\"just\", \"one\", \"test\", \"more\"]"); + assert_eq!(format!("{:?}", list), "[\"just\", \"one\", \"test\", \"more\"]"); } #[test] @@ -446,19 +444,14 @@ fn drain_filter_true() { #[test] fn drain_filter_complex() { - - { // [+xxx++++++xxxxx++++x+x++] + { + // [+xxx++++++xxxxx++++x+x++] let mut list = vec![ - 1, - 2, 4, 6, - 7, 9, 11, 13, 15, 17, - 18, 20, 22, 24, 26, - 27, 29, 31, 33, - 34, - 35, - 36, - 37, 39 - ].into_iter().collect::<LinkedList<_>>(); + 1, 2, 4, 6, 7, 9, 11, 13, 15, 17, 18, 20, 22, 24, 26, 27, 29, 31, 33, 34, 35, 36, 37, + 39, + ] + .into_iter() + .collect::<LinkedList<_>>(); let removed = list.drain_filter(|x| *x % 2 == 0).collect::<Vec<_>>(); assert_eq!(removed.len(), 10); @@ -471,17 +464,13 @@ fn drain_filter_complex() { ); } - { // [xxx++++++xxxxx++++x+x++] + { + // [xxx++++++xxxxx++++x+x++] let mut list = vec![ - 2, 4, 6, - 7, 9, 11, 13, 15, 17, - 18, 20, 22, 24, 26, - 27, 29, 31, 33, - 34, - 35, - 36, - 37, 39 - ].into_iter().collect::<LinkedList<_>>(); + 2, 4, 6, 7, 9, 11, 13, 15, 17, 18, 20, 22, 24, 26, 27, 29, 31, 33, 34, 35, 36, 37, 39, + ] + .into_iter() + .collect::<LinkedList<_>>(); let removed = list.drain_filter(|x| *x % 2 == 0).collect::<Vec<_>>(); assert_eq!(removed.len(), 10); @@ -494,16 +483,12 @@ fn drain_filter_complex() { ); } - { // [xxx++++++xxxxx++++x+x] - let mut list = vec![ - 2, 4, 6, - 7, 9, 11, 13, 15, 17, - 18, 20, 22, 24, 26, - 27, 29, 31, 33, - 34, - 35, - 36 - ].into_iter().collect::<LinkedList<_>>(); + { + // [xxx++++++xxxxx++++x+x] + let mut list = + vec![2, 4, 6, 7, 9, 11, 13, 15, 17, 18, 20, 22, 24, 26, 27, 29, 31, 33, 34, 35, 36] + .into_iter() + .collect::<LinkedList<_>>(); let removed = list.drain_filter(|x| *x % 2 == 0).collect::<Vec<_>>(); assert_eq!(removed.len(), 10); @@ -516,11 +501,11 @@ fn drain_filter_complex() { ); } - { // [xxxxxxxxxx+++++++++++] - let mut list = vec![ - 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, - 1, 3, 5, 7, 9, 11, 13, 15, 17, 19 - ].into_iter().collect::<LinkedList<_>>(); + { + // [xxxxxxxxxx+++++++++++] + let mut list = vec![2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19] + .into_iter() + .collect::<LinkedList<_>>(); let removed = list.drain_filter(|x| *x % 2 == 0).collect::<Vec<_>>(); assert_eq!(removed.len(), 10); @@ -530,11 +515,11 @@ fn drain_filter_complex() { assert_eq!(list.into_iter().collect::<Vec<_>>(), vec![1, 3, 5, 7, 9, 11, 13, 15, 17, 19]); } - { // [+++++++++++xxxxxxxxxx] - let mut list = vec![ - 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, - 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 - ].into_iter().collect::<LinkedList<_>>(); + { + // [+++++++++++xxxxxxxxxx] + let mut list = vec![1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20] + .into_iter() + .collect::<LinkedList<_>>(); let removed = list.drain_filter(|x| *x % 2 == 0).collect::<Vec<_>>(); assert_eq!(removed.len(), 10); diff --git a/src/liballoc/tests/rc.rs b/src/liballoc/tests/rc.rs index 7854ca0fc16..e77c57d9a5a 100644 --- a/src/liballoc/tests/rc.rs +++ b/src/liballoc/tests/rc.rs @@ -1,9 +1,9 @@ use std::any::Any; -use std::rc::{Rc, Weak}; use std::cell::RefCell; use std::cmp::PartialEq; -use std::mem; use std::iter::TrustedLen; +use std::mem; +use std::rc::{Rc, Weak}; #[test] fn uninhabited() { @@ -12,7 +12,7 @@ fn uninhabited() { a = a.clone(); assert!(a.upgrade().is_none()); - let mut a: Weak<dyn Any> = a; // Unsizing + let mut a: Weak<dyn Any> = a; // Unsizing a = a.clone(); assert!(a.upgrade().is_none()); } @@ -20,8 +20,8 @@ fn uninhabited() { #[test] fn slice() { let a: Rc<[u32; 3]> = Rc::new([3, 2, 1]); - let a: Rc<[u32]> = a; // Unsizing - let b: Rc<[u32]> = Rc::from(&[3, 2, 1][..]); // Conversion + let a: Rc<[u32]> = a; // Unsizing + let b: Rc<[u32]> = Rc::from(&[3, 2, 1][..]); // Conversion assert_eq!(a, b); // Exercise is_dangling() with a DST @@ -33,7 +33,7 @@ fn slice() { #[test] fn trait_object() { let a: Rc<u32> = Rc::new(4); - let a: Rc<dyn Any> = a; // Unsizing + let a: Rc<dyn Any> = a; // Unsizing // Exercise is_dangling() with a DST let mut a = Rc::downgrade(&a); @@ -43,7 +43,7 @@ fn trait_object() { let mut b = Weak::<u32>::new(); b = b.clone(); assert!(b.upgrade().is_none()); - let mut b: Weak<dyn Any> = b; // Unsizing + let mut b: Weak<dyn Any> = b; // Unsizing b = b.clone(); assert!(b.upgrade().is_none()); } @@ -57,7 +57,7 @@ fn float_nan_ne() { #[test] fn partial_eq() { - struct TestPEq (RefCell<usize>); + struct TestPEq(RefCell<usize>); impl PartialEq for TestPEq { fn eq(&self, other: &TestPEq) -> bool { *self.0.borrow_mut() += 1; @@ -74,7 +74,7 @@ fn partial_eq() { #[test] fn eq() { #[derive(Eq)] - struct TestEq (RefCell<usize>); + struct TestEq(RefCell<usize>); impl PartialEq for TestEq { fn eq(&self, other: &TestEq) -> bool { *self.0.borrow_mut() += 1; @@ -156,13 +156,10 @@ fn shared_from_iter_trustedlen_normal() { fn shared_from_iter_trustedlen_panic() { // Exercise the `TrustedLen` implementation when `size_hint()` matches // `(_, Some(exact_len))` but where `.next()` drops before the last iteration. - let iter = (0..SHARED_ITER_MAX) - .map(|val| { - match val { - 98 => panic!("I've almost got 99 problems."), - _ => Box::new(val), - } - }); + let iter = (0..SHARED_ITER_MAX).map(|val| match val { + 98 => panic!("I've almost got 99 problems."), + _ => Box::new(val), + }); assert_trusted_len(&iter); let _ = iter.collect::<Rc<[_]>>(); @@ -189,16 +186,8 @@ fn shared_from_iter_trustedlen_no_fuse() { } } - let vec = vec![ - Some(Box::new(42)), - Some(Box::new(24)), - None, - Some(Box::new(12)), - ]; + let vec = vec![Some(Box::new(42)), Some(Box::new(24)), None, Some(Box::new(12))]; let iter = Iter(vec.into_iter()); assert_trusted_len(&iter); - assert_eq!( - &[Box::new(42), Box::new(24)], - &*iter.collect::<Rc<[_]>>() - ); + assert_eq!(&[Box::new(42), Box::new(24)], &*iter.collect::<Rc<[_]>>()); } diff --git a/src/liballoc/tests/vec_deque.rs b/src/liballoc/tests/vec_deque.rs index d49b553fc02..5a0162a5361 100644 --- a/src/liballoc/tests/vec_deque.rs +++ b/src/liballoc/tests/vec_deque.rs @@ -1,8 +1,8 @@ -use std::fmt::Debug; -use std::collections::{VecDeque, vec_deque::Drain}; use std::collections::TryReserveError::*; +use std::collections::{vec_deque::Drain, VecDeque}; +use std::fmt::Debug; use std::mem::size_of; -use std::{usize, isize}; +use std::{isize, usize}; use crate::hash; @@ -148,34 +148,20 @@ fn test_param_taggy() { #[test] fn test_param_taggypar() { - test_parameterized::<Taggypar<i32>>(Onepar::<i32>(1), - Twopar::<i32>(1, 2), - Threepar::<i32>(1, 2, 3), - Twopar::<i32>(17, 42)); + test_parameterized::<Taggypar<i32>>( + Onepar::<i32>(1), + Twopar::<i32>(1, 2), + Threepar::<i32>(1, 2, 3), + Twopar::<i32>(17, 42), + ); } #[test] fn test_param_reccy() { - let reccy1 = RecCy { - x: 1, - y: 2, - t: One(1), - }; - let reccy2 = RecCy { - x: 345, - y: 2, - t: Two(1, 2), - }; - let reccy3 = RecCy { - x: 1, - y: 777, - t: Three(1, 2, 3), - }; - let reccy4 = RecCy { - x: 19, - y: 252, - t: Two(17, 42), - }; + let reccy1 = RecCy { x: 1, y: 2, t: One(1) }; + let reccy2 = RecCy { x: 345, y: 2, t: Two(1, 2) }; + let reccy3 = RecCy { x: 1, y: 777, t: Three(1, 2, 3) }; + let reccy4 = RecCy { x: 19, y: 252, t: Two(17, 42) }; test_parameterized::<RecCy>(reccy1, reccy2, reccy3, reccy4); } @@ -320,8 +306,7 @@ fn test_mut_rev_iter_wrap() { assert_eq!(d.pop_front(), Some(1)); d.push_back(4); - assert_eq!(d.iter_mut().rev().map(|x| *x).collect::<Vec<_>>(), - vec![4, 3, 2]); + assert_eq!(d.iter_mut().rev().map(|x| *x).collect::<Vec<_>>(), vec![4, 3, 2]); } #[test] @@ -372,7 +357,6 @@ fn test_mut_rev_iter() { #[test] fn test_into_iter() { - // Empty iter { let d: VecDeque<i32> = VecDeque::new(); @@ -431,7 +415,6 @@ fn test_into_iter() { #[test] fn test_drain() { - // Empty iter { let mut d: VecDeque<i32> = VecDeque::new(); @@ -650,12 +633,8 @@ fn test_show() { let ringbuf: VecDeque<_> = (0..10).collect(); assert_eq!(format!("{:?}", ringbuf), "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"); - let ringbuf: VecDeque<_> = vec!["just", "one", "test", "more"] - .iter() - .cloned() - .collect(); - assert_eq!(format!("{:?}", ringbuf), - "[\"just\", \"one\", \"test\", \"more\"]"); + let ringbuf: VecDeque<_> = vec!["just", "one", "test", "more"].iter().cloned().collect(); + assert_eq!(format!("{:?}", ringbuf), "[\"just\", \"one\", \"test\", \"more\"]"); } #[test] @@ -955,7 +934,6 @@ fn test_append_permutations() { // doesn't pop more values than are pushed for src_pop_back in 0..(src_push_back + src_push_front) { for src_pop_front in 0..(src_push_back + src_push_front - src_pop_back) { - let src = construct_vec_deque( src_push_back, src_pop_back, @@ -966,8 +944,8 @@ fn test_append_permutations() { for dst_push_back in 0..MAX { for dst_push_front in 0..MAX { for dst_pop_back in 0..(dst_push_back + dst_push_front) { - for dst_pop_front - in 0..(dst_push_back + dst_push_front - dst_pop_back) + for dst_pop_front in + 0..(dst_push_back + dst_push_front - dst_pop_back) { let mut dst = construct_vec_deque( dst_push_back, @@ -1124,7 +1102,6 @@ fn test_reserve_exact_2() { #[test] #[cfg(not(miri))] // Miri does not support signalling OOM fn test_try_reserve() { - // These are the interesting cases: // * exactly isize::MAX should never trigger a CapacityOverflow (can be OOM) // * > isize::MAX should always fail @@ -1158,22 +1135,27 @@ fn test_try_reserve() { if guards_against_isize { // Check isize::MAX + 1 does count as overflow if let Err(CapacityOverflow) = empty_bytes.try_reserve(MAX_CAP + 1) { - } else { panic!("isize::MAX + 1 should trigger an overflow!") } + } else { + panic!("isize::MAX + 1 should trigger an overflow!") + } // Check usize::MAX does count as overflow if let Err(CapacityOverflow) = empty_bytes.try_reserve(MAX_USIZE) { - } else { panic!("usize::MAX should trigger an overflow!") } + } else { + panic!("usize::MAX should trigger an overflow!") + } } else { // Check isize::MAX is an OOM // VecDeque starts with capacity 7, always adds 1 to the capacity // and also rounds the number to next power of 2 so this is the // furthest we can go without triggering CapacityOverflow if let Err(AllocError { .. }) = empty_bytes.try_reserve(MAX_CAP) { - } else { panic!("isize::MAX + 1 should trigger an OOM!") } + } else { + panic!("isize::MAX + 1 should trigger an OOM!") + } } } - { // Same basic idea, but with non-zero len let mut ten_bytes: VecDeque<u8> = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10].into_iter().collect(); @@ -1186,33 +1168,42 @@ fn test_try_reserve() { } if guards_against_isize { if let Err(CapacityOverflow) = ten_bytes.try_reserve(MAX_CAP - 9) { - } else { panic!("isize::MAX + 1 should trigger an overflow!"); } + } else { + panic!("isize::MAX + 1 should trigger an overflow!"); + } } else { if let Err(AllocError { .. }) = ten_bytes.try_reserve(MAX_CAP - 9) { - } else { panic!("isize::MAX + 1 should trigger an OOM!") } + } else { + panic!("isize::MAX + 1 should trigger an OOM!") + } } // Should always overflow in the add-to-len if let Err(CapacityOverflow) = ten_bytes.try_reserve(MAX_USIZE) { - } else { panic!("usize::MAX should trigger an overflow!") } + } else { + panic!("usize::MAX should trigger an overflow!") + } } - { // Same basic idea, but with interesting type size let mut ten_u32s: VecDeque<u32> = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10].into_iter().collect(); - if let Err(CapacityOverflow) = ten_u32s.try_reserve(MAX_CAP/4 - 10) { + if let Err(CapacityOverflow) = ten_u32s.try_reserve(MAX_CAP / 4 - 10) { panic!("isize::MAX shouldn't trigger an overflow!"); } - if let Err(CapacityOverflow) = ten_u32s.try_reserve(MAX_CAP/4 - 10) { + if let Err(CapacityOverflow) = ten_u32s.try_reserve(MAX_CAP / 4 - 10) { panic!("isize::MAX shouldn't trigger an overflow!"); } if guards_against_isize { - if let Err(CapacityOverflow) = ten_u32s.try_reserve(MAX_CAP/4 - 9) { - } else { panic!("isize::MAX + 1 should trigger an overflow!"); } + if let Err(CapacityOverflow) = ten_u32s.try_reserve(MAX_CAP / 4 - 9) { + } else { + panic!("isize::MAX + 1 should trigger an overflow!"); + } } else { - if let Err(AllocError { .. }) = ten_u32s.try_reserve(MAX_CAP/4 - 9) { - } else { panic!("isize::MAX + 1 should trigger an OOM!") } + if let Err(AllocError { .. }) = ten_u32s.try_reserve(MAX_CAP / 4 - 9) { + } else { + panic!("isize::MAX + 1 should trigger an OOM!") + } } // Should fail in the mul-by-size if let Err(CapacityOverflow) = ten_u32s.try_reserve(MAX_USIZE - 20) { @@ -1220,13 +1211,11 @@ fn test_try_reserve() { panic!("usize::MAX should trigger an overflow!"); } } - } #[test] #[cfg(not(miri))] // Miri does not support signalling OOM fn test_try_reserve_exact() { - // This is exactly the same as test_try_reserve with the method changed. // See that test for comments. @@ -1247,21 +1236,26 @@ fn test_try_reserve_exact() { if guards_against_isize { if let Err(CapacityOverflow) = empty_bytes.try_reserve_exact(MAX_CAP + 1) { - } else { panic!("isize::MAX + 1 should trigger an overflow!") } + } else { + panic!("isize::MAX + 1 should trigger an overflow!") + } if let Err(CapacityOverflow) = empty_bytes.try_reserve_exact(MAX_USIZE) { - } else { panic!("usize::MAX should trigger an overflow!") } + } else { + panic!("usize::MAX should trigger an overflow!") + } } else { // Check isize::MAX is an OOM // VecDeque starts with capacity 7, always adds 1 to the capacity // and also rounds the number to next power of 2 so this is the // furthest we can go without triggering CapacityOverflow if let Err(AllocError { .. }) = empty_bytes.try_reserve_exact(MAX_CAP) { - } else { panic!("isize::MAX + 1 should trigger an OOM!") } + } else { + panic!("isize::MAX + 1 should trigger an OOM!") + } } } - { let mut ten_bytes: VecDeque<u8> = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10].into_iter().collect(); @@ -1273,36 +1267,46 @@ fn test_try_reserve_exact() { } if guards_against_isize { if let Err(CapacityOverflow) = ten_bytes.try_reserve_exact(MAX_CAP - 9) { - } else { panic!("isize::MAX + 1 should trigger an overflow!"); } + } else { + panic!("isize::MAX + 1 should trigger an overflow!"); + } } else { if let Err(AllocError { .. }) = ten_bytes.try_reserve_exact(MAX_CAP - 9) { - } else { panic!("isize::MAX + 1 should trigger an OOM!") } + } else { + panic!("isize::MAX + 1 should trigger an OOM!") + } } if let Err(CapacityOverflow) = ten_bytes.try_reserve_exact(MAX_USIZE) { - } else { panic!("usize::MAX should trigger an overflow!") } + } else { + panic!("usize::MAX should trigger an overflow!") + } } - { let mut ten_u32s: VecDeque<u32> = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10].into_iter().collect(); - if let Err(CapacityOverflow) = ten_u32s.try_reserve_exact(MAX_CAP/4 - 10) { + if let Err(CapacityOverflow) = ten_u32s.try_reserve_exact(MAX_CAP / 4 - 10) { panic!("isize::MAX shouldn't trigger an overflow!"); } - if let Err(CapacityOverflow) = ten_u32s.try_reserve_exact(MAX_CAP/4 - 10) { + if let Err(CapacityOverflow) = ten_u32s.try_reserve_exact(MAX_CAP / 4 - 10) { panic!("isize::MAX shouldn't trigger an overflow!"); } if guards_against_isize { - if let Err(CapacityOverflow) = ten_u32s.try_reserve_exact(MAX_CAP/4 - 9) { - } else { panic!("isize::MAX + 1 should trigger an overflow!"); } + if let Err(CapacityOverflow) = ten_u32s.try_reserve_exact(MAX_CAP / 4 - 9) { + } else { + panic!("isize::MAX + 1 should trigger an overflow!"); + } } else { - if let Err(AllocError { .. }) = ten_u32s.try_reserve_exact(MAX_CAP/4 - 9) { - } else { panic!("isize::MAX + 1 should trigger an OOM!") } + if let Err(AllocError { .. }) = ten_u32s.try_reserve_exact(MAX_CAP / 4 - 9) { + } else { + panic!("isize::MAX + 1 should trigger an OOM!") + } } if let Err(CapacityOverflow) = ten_u32s.try_reserve_exact(MAX_USIZE - 20) { - } else { panic!("usize::MAX should trigger an overflow!") } + } else { + panic!("usize::MAX should trigger an overflow!") + } } - } #[test] @@ -1404,9 +1408,8 @@ fn test_rotate_right_parts() { #[test] fn test_rotate_left_random() { let shifts = [ - 6, 1, 0, 11, 12, 1, 11, 7, 9, 3, 6, 1, - 4, 0, 5, 1, 3, 1, 12, 8, 3, 1, 11, 11, - 9, 4, 12, 3, 12, 9, 11, 1, 7, 9, 7, 2, + 6, 1, 0, 11, 12, 1, 11, 7, 9, 3, 6, 1, 4, 0, 5, 1, 3, 1, 12, 8, 3, 1, 11, 11, 9, 4, 12, 3, + 12, 9, 11, 1, 7, 9, 7, 2, ]; let n = 12; let mut v: VecDeque<_> = (0..n).collect(); @@ -1423,9 +1426,8 @@ fn test_rotate_left_random() { #[test] fn test_rotate_right_random() { let shifts = [ - 6, 1, 0, 11, 12, 1, 11, 7, 9, 3, 6, 1, - 4, 0, 5, 1, 3, 1, 12, 8, 3, 1, 11, 11, - 9, 4, 12, 3, 12, 9, 11, 1, 7, 9, 7, 2, + 6, 1, 0, 11, 12, 1, 11, 7, 9, 3, 6, 1, 4, 0, 5, 1, 3, 1, 12, 8, 3, 1, 11, 11, 9, 4, 12, 3, + 12, 9, 11, 1, 7, 9, 7, 2, ]; let n = 12; let mut v: VecDeque<_> = (0..n).collect(); @@ -1447,8 +1449,7 @@ fn test_try_fold_empty() { #[test] fn test_try_fold_none() { let v: VecDeque<u32> = (0..12).collect(); - assert_eq!(None, v.into_iter().try_fold(0, |a, b| - if b < 11 { Some(a + b) } else { None })); + assert_eq!(None, v.into_iter().try_fold(0, |a, b| if b < 11 { Some(a + b) } else { None })); } #[test] @@ -1463,7 +1464,6 @@ fn test_try_fold_unit() { assert_eq!(Some(()), v.into_iter().try_fold((), |(), ()| Some(()))); } - #[test] fn test_try_fold_unit_none() { let v: std::collections::VecDeque<()> = [(); 10].iter().cloned().collect(); @@ -1534,7 +1534,7 @@ fn test_try_rfold_rotated() { #[test] fn test_try_rfold_moves_iter() { - let v : VecDeque<_> = [10, 20, 30, 40, 100, 60, 70, 80, 90].iter().collect(); + let v: VecDeque<_> = [10, 20, 30, 40, 100, 60, 70, 80, 90].iter().collect(); let mut iter = v.into_iter(); assert_eq!(iter.try_rfold(0_i8, |acc, &x| acc.checked_add(x)), None); assert_eq!(iter.next_back(), Some(&70)); |
