Skip to content

Commit

Permalink
Auto merge of rust-lang#92998 - Amanieu:hashbrown12, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed Jan 22, 2022
2 parents bfe1564 + 537439c commit 10c4c4a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
16 changes: 12 additions & 4 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,14 @@ source = "registry+https:/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
dependencies = [
"ahash",
]

[[package]]
name = "hashbrown"
version = "0.12.0"
source = "registry+https:/rust-lang/crates.io-index"
checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758"
dependencies = [
"compiler_builtins",
"rustc-std-workspace-alloc",
"rustc-std-workspace-core",
Expand Down Expand Up @@ -1736,7 +1744,7 @@ source = "registry+https:/rust-lang/crates.io-index"
checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
dependencies = [
"autocfg",
"hashbrown",
"hashbrown 0.11.2",
"serde",
]

Expand Down Expand Up @@ -2411,7 +2419,7 @@ checksum = "7ce8b38d41f9f3618fc23f908faae61510f8d8ce2d99cbe910641e8f1971f084"
dependencies = [
"crc32fast",
"flate2",
"hashbrown",
"hashbrown 0.11.2",
"indexmap",
"memchr",
]
Expand Down Expand Up @@ -4814,7 +4822,7 @@ dependencies = [
"core",
"dlmalloc",
"fortanix-sgx-abi",
"hashbrown",
"hashbrown 0.12.0",
"hermit-abi",
"libc",
"miniz_oxide",
Expand Down Expand Up @@ -5096,7 +5104,7 @@ source = "registry+https:/rust-lang/crates.io-index"
checksum = "dd95b4559c196987c8451b4e14d08a4c796c2844f9adf4d2a2dbc9b3142843be"
dependencies = [
"gimli 0.26.1",
"hashbrown",
"hashbrown 0.11.2",
"object 0.28.1",
"tracing",
]
Expand Down
2 changes: 1 addition & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ libc = { version = "0.2.108", default-features = false, features = ['rustc-dep-o
compiler_builtins = { version = "0.1.66" }
profiler_builtins = { path = "../profiler_builtins", optional = true }
unwind = { path = "../unwind" }
hashbrown = { version = "0.11", default-features = false, features = ['rustc-dep-of-std'] }
hashbrown = { version = "0.12", default-features = false, features = ['rustc-dep-of-std'] }
std_detect = { path = "../stdarch/crates/std_detect", default-features = false, features = ['rustc-dep-of-std'] }

# Dependencies of the `backtrace` crate
Expand Down
21 changes: 16 additions & 5 deletions library/std/src/collections/hash/map/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ fn test_retain() {
}

#[test]
#[cfg_attr(target_os = "android", ignore)] // Android used in CI has a broken dlmalloc
fn test_try_reserve() {
let mut empty_bytes: HashMap<u8, u8> = HashMap::new();

Expand All @@ -828,11 +829,21 @@ fn test_try_reserve() {
"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!"
);
if let Err(AllocError { .. }) = empty_bytes.try_reserve(MAX_USIZE / 16).map_err(|e| e.kind()) {
} else {
// This may succeed if there is enough free memory. Attempt to
// allocate a few more hashmaps to ensure the allocation will fail.
let mut empty_bytes2: HashMap<u8, u8> = HashMap::new();
let _ = empty_bytes2.try_reserve(MAX_USIZE / 16);
let mut empty_bytes3: HashMap<u8, u8> = HashMap::new();
let _ = empty_bytes3.try_reserve(MAX_USIZE / 16);
let mut empty_bytes4: HashMap<u8, u8> = HashMap::new();
assert_matches!(
empty_bytes4.try_reserve(MAX_USIZE / 16).map_err(|e| e.kind()),
Err(AllocError { .. }),
"usize::MAX / 16 should trigger an OOM!"
);
}
}

#[test]
Expand Down

0 comments on commit 10c4c4a

Please sign in to comment.