diff options
| author | bors <bors@rust-lang.org> | 2021-08-12 01:16:22 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-08-12 01:16:22 +0000 |
| commit | 25d3e14da77f755ef858b976a25c7e856b62b42a (patch) | |
| tree | 51f4f7edc7121c4f27da72f40a5d047bae926782 /library/std/src/collections | |
| parent | ccffcafd55e58f769d4b0efc0064bf65e76998e4 (diff) | |
| parent | 7dca8eb5653fb7ae5efbea2b80941997fead5ce3 (diff) | |
| download | rust-25d3e14da77f755ef858b976a25c7e856b62b42a.tar.gz rust-25d3e14da77f755ef858b976a25c7e856b62b42a.zip | |
Auto merge of #87843 - kornelski:try_reserve, r=m-ou-se
TryReserveErrorKind tests and inline A small follow-up to #87408
Diffstat (limited to 'library/std/src/collections')
| -rw-r--r-- | library/std/src/collections/hash/map/tests.rs | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/library/std/src/collections/hash/map/tests.rs b/library/std/src/collections/hash/map/tests.rs index 18d868d49a6..d9b20aee2d2 100644 --- a/library/std/src/collections/hash/map/tests.rs +++ b/library/std/src/collections/hash/map/tests.rs @@ -1,6 +1,7 @@ use super::Entry::{Occupied, Vacant}; use super::HashMap; use super::RandomState; +use crate::assert_matches::assert_matches; use crate::cell::RefCell; use rand::{thread_rng, Rng}; use realstd::collections::TryReserveErrorKind::*; @@ -821,15 +822,17 @@ fn test_try_reserve() { const MAX_USIZE: usize = usize::MAX; - if let Err(CapacityOverflow) = empty_bytes.try_reserve(MAX_USIZE).map_err(|e| e.kind()) { - } else { - panic!("usize::MAX should trigger an overflow!"); - } - - if let Err(AllocError { .. }) = empty_bytes.try_reserve(MAX_USIZE / 8).map_err(|e| e.kind()) { - } else { - panic!("usize::MAX / 8 should trigger an OOM!") - } + assert_matches!( + empty_bytes.try_reserve(MAX_USIZE).map_err(|e| e.kind()), + Err(CapacityOverflow), + "usize::MAX should trigger an overflow!" + ); + + assert_matches!( + empty_bytes.try_reserve(MAX_USIZE / 8).map_err(|e| e.kind()), + Err(AllocError { .. }), + "usize::MAX / 8 should trigger an OOM!" + ); } #[test] |
