diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-11-26 09:44:49 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-11-26 16:49:49 -0800 |
| commit | 69e7554a479fc186ee0ef0de2e4c1d9b3300317c (patch) | |
| tree | ce691082adef38868670c10361895a10cb98acd1 /src/libstd | |
| parent | b095eb172095c0a4005ba4f0360186829de5a1a6 (diff) | |
| parent | b1e720fb7e462351b24f1d3eaa8ac21044c41d28 (diff) | |
| download | rust-69e7554a479fc186ee0ef0de2e4c1d9b3300317c.tar.gz rust-69e7554a479fc186ee0ef0de2e4c1d9b3300317c.zip | |
rollup merge of #19301: Gankro/take-fix
Was taking the value out correctly, but then not doing anything to actually fix the table. derp.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/collections/hash/map.rs | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 9c7967d17bb..50a00714ea0 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1376,7 +1376,7 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> { /// Takes the value out of the entry, and returns it pub fn take(self) -> V { - let (_, _, v) = self.elem.take(); + let (_, v) = pop_internal(self.elem); v } } @@ -1433,6 +1433,7 @@ mod test_map { use hash; use iter::{Iterator,range_inclusive,range_step_inclusive}; use cell::RefCell; + use rand::{weak_rng, Rng}; struct KindaIntLike(int); @@ -2073,4 +2074,37 @@ mod test_map { assert_eq!(map.get(&10).unwrap(), &1000); assert_eq!(map.len(), 6); } + + #[test] + fn test_entry_take_doesnt_corrupt() { + // Test for #19292 + fn check(m: &HashMap<int, ()>) { + for k in m.keys() { + assert!(m.contains_key(k), + "{} is in keys() but not in the map?", k); + } + } + + let mut m = HashMap::new(); + let mut rng = weak_rng(); + + // Populate the map with some items. + for _ in range(0u, 50) { + let x = rng.gen_range(-10, 10); + m.insert(x, ()); + } + + for i in range(0u, 1000) { + let x = rng.gen_range(-10, 10); + match m.entry(x) { + Vacant(_) => {}, + Occupied(e) => { + println!("{}: remove {}", i, x); + e.take(); + }, + } + + check(&m); + } + } } |
