Skip to content

Commit 4331ada

Browse files
committed
Move HashMap to liballoc
1 parent 1edfa6c commit 4331ada

File tree

10 files changed

+59
-47
lines changed

10 files changed

+59
-47
lines changed

src/libstd/collections/hash/map.rs renamed to src/liballoc/collections/hash/map.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ use self::Entry::*;
1212
use self::VacantEntryState::*;
1313

1414
use collections::CollectionAllocErr;
15-
use borrow::Borrow;
16-
use cmp::max;
17-
use fmt::{self, Debug};
15+
use core::borrow::Borrow;
16+
use core::cmp::max;
17+
use core::fmt::{self, Debug};
1818
#[allow(deprecated)]
19-
use hash::{Hash, Hasher, BuildHasher, SipHasher13};
20-
use iter::{FromIterator, FusedIterator};
21-
use mem::{self, replace};
22-
use ops::{Deref, Index};
19+
use core::hash::{Hash, Hasher, BuildHasher, SipHasher13};
20+
use core::iter::{FromIterator, FusedIterator};
21+
use core::mem::{self, replace};
22+
use core::ops::{Deref, Index};
2323

2424
use super::table::{self, Bucket, EmptyBucket, Fallibility, FullBucket, FullBucketMut, RawTable,
2525
SafeHash};
@@ -2559,7 +2559,7 @@ impl<'a, K, V, S> Extend<(&'a K, &'a V)> for HashMap<K, V, S>
25592559
/// instances are unlikely to produce the same result for the same values.
25602560
///
25612561
/// [`HashMap`]: struct.HashMap.html
2562-
/// [`Hasher`]: ../../hash/trait.Hasher.html
2562+
/// [`Hasher`]: ../../../std/hash/trait.Hasher.html
25632563
///
25642564
/// # Examples
25652565
///
@@ -2625,7 +2625,7 @@ impl BuildHasher for RandomState {
26252625
/// not be relied upon over releases.
26262626
///
26272627
/// [`RandomState`]: struct.RandomState.html
2628-
/// [`Hasher`]: ../../hash/trait.Hasher.html
2628+
/// [`Hasher`]: ../../../std/hash/trait.Hasher.html
26292629
#[stable(feature = "hashmap_default_hasher", since = "1.13.0")]
26302630
#[allow(deprecated)]
26312631
#[derive(Clone, Debug)]
@@ -2759,11 +2759,12 @@ mod test_map {
27592759
use super::HashMap;
27602760
use super::Entry::{Occupied, Vacant};
27612761
use super::RandomState;
2762-
use cell::RefCell;
2762+
use core::cell::RefCell;
27632763
use rand::{thread_rng, Rng};
2764-
use realstd::collections::CollectionAllocErr::*;
2765-
use realstd::mem::size_of;
2766-
use realstd::usize;
2764+
use collections::CollectionAllocErr::*;
2765+
use std::mem::size_of;
2766+
use std::usize;
2767+
use vec::Vec;
27672768

27682769
#[test]
27692770
fn test_zero_capacities() {

src/libstd/collections/hash/set.rs renamed to src/liballoc/collections/hash/set.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use borrow::Borrow;
12-
use fmt;
13-
use hash::{Hash, BuildHasher};
14-
use iter::{Chain, FromIterator, FusedIterator};
15-
use ops::{BitOr, BitAnd, BitXor, Sub};
11+
use core::borrow::Borrow;
12+
use core::fmt;
13+
use core::hash::{Hash, BuildHasher};
14+
use core::iter::{Chain, FromIterator, FusedIterator};
15+
use core::ops::{BitOr, BitAnd, BitXor, Sub};
1616

1717
use super::Recover;
1818
use super::map::{self, HashMap, Keys, RandomState};
@@ -1403,6 +1403,7 @@ fn assert_covariance() {
14031403
mod test_set {
14041404
use super::HashSet;
14051405
use super::super::map::RandomState;
1406+
use vec::Vec;
14061407

14071408
#[test]
14081409
fn test_zero_capacities() {
@@ -1712,7 +1713,7 @@ mod test_set {
17121713

17131714
#[test]
17141715
fn test_replace() {
1715-
use hash;
1716+
use core::hash;
17161717

17171718
#[derive(Debug)]
17181719
struct Foo(&'static str, i32);

src/libstd/collections/hash/table.rs renamed to src/liballoc/collections/hash/table.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
use alloc::{Global, Alloc, Layout, LayoutErr, handle_alloc_error};
1212
use collections::CollectionAllocErr;
13-
use hash::{BuildHasher, Hash, Hasher};
14-
use marker;
15-
use mem::{size_of, needs_drop};
16-
use mem;
17-
use ops::{Deref, DerefMut};
18-
use ptr::{self, Unique, NonNull};
19-
use hint;
13+
use core::hash::{BuildHasher, Hash, Hasher};
14+
use core::marker;
15+
use core::mem::{size_of, needs_drop};
16+
use core::mem;
17+
use core::ops::{Deref, DerefMut};
18+
use core::ptr::{self, Unique, NonNull};
19+
use core::hint;
2020

2121
use self::BucketState::*;
2222

src/liballoc/collections/mod.rs

+23
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
pub mod binary_heap;
1616
mod btree;
17+
mod hash;
1718
pub mod linked_list;
1819
pub mod vec_deque;
1920

@@ -31,6 +32,20 @@ pub mod btree_set {
3132
pub use super::btree::set::*;
3233
}
3334

35+
#[stable(feature = "rust1", since = "1.0.0")]
36+
pub mod hash_map {
37+
//! A hash map implemented with linear probing and Robin Hood bucket stealing.
38+
#[stable(feature = "rust1", since = "1.0.0")]
39+
pub use super::hash::map::*;
40+
}
41+
42+
#[stable(feature = "rust1", since = "1.0.0")]
43+
pub mod hash_set {
44+
//! A hash set implemented as a `HashMap` where the value is `()`.
45+
#[stable(feature = "rust1", since = "1.0.0")]
46+
pub use super::hash::set::*;
47+
}
48+
3449
#[stable(feature = "rust1", since = "1.0.0")]
3550
#[doc(no_inline)]
3651
pub use self::binary_heap::BinaryHeap;
@@ -43,6 +58,14 @@ pub use self::btree_map::BTreeMap;
4358
#[doc(no_inline)]
4459
pub use self::btree_set::BTreeSet;
4560

61+
#[stable(feature = "rust1", since = "1.0.0")]
62+
#[doc(no_inline)]
63+
pub use self::hash_map::HashMap;
64+
65+
#[stable(feature = "rust1", since = "1.0.0")]
66+
#[doc(no_inline)]
67+
pub use self::hash_set::HashSet;
68+
4669
#[stable(feature = "rust1", since = "1.0.0")]
4770
#[doc(no_inline)]
4871
pub use self::linked_list::LinkedList;

src/liballoc/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
7070
html_root_url = "https://doc.rust-lang.org/nightly/",
7171
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
72-
test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))]
72+
test(no_crate_inject, attr(allow(unused_variables, unused_mut), deny(warnings))))]
7373
#![no_std]
7474
#![needs_allocator]
7575
#![deny(missing_debug_implementations)]
@@ -122,6 +122,8 @@
122122
#![feature(inclusive_range_methods)]
123123
#![feature(rustc_const_unstable)]
124124
#![feature(const_vec_new)]
125+
#![feature(unwind_attributes)]
126+
#![feature(hashmap_internals)]
125127

126128
#![cfg_attr(not(test), feature(fn_traits, i128))]
127129
#![cfg_attr(test, feature(test))]

src/libstd/collections/mod.rs renamed to src/libstd/collections.rs

+2-19
Original file line numberDiff line numberDiff line change
@@ -431,31 +431,14 @@ pub use alloc_crate::collections::{LinkedList, VecDeque};
431431
pub use alloc_crate::collections::{binary_heap, btree_map, btree_set};
432432
#[stable(feature = "rust1", since = "1.0.0")]
433433
pub use alloc_crate::collections::{linked_list, vec_deque};
434-
435434
#[stable(feature = "rust1", since = "1.0.0")]
436-
pub use self::hash_map::HashMap;
435+
pub use alloc_crate::collections::{HashMap, HashSet};
437436
#[stable(feature = "rust1", since = "1.0.0")]
438-
pub use self::hash_set::HashSet;
437+
pub use alloc_crate::collections::{hash_map, hash_set};
439438

440439
#[unstable(feature = "try_reserve", reason = "new API", issue="48043")]
441440
pub use alloc_crate::collections::CollectionAllocErr;
442441

443-
mod hash;
444-
445-
#[stable(feature = "rust1", since = "1.0.0")]
446-
pub mod hash_map {
447-
//! A hash map implemented with linear probing and Robin Hood bucket stealing.
448-
#[stable(feature = "rust1", since = "1.0.0")]
449-
pub use super::hash::map::*;
450-
}
451-
452-
#[stable(feature = "rust1", since = "1.0.0")]
453-
pub mod hash_set {
454-
//! A hash set implemented as a `HashMap` where the value is `()`.
455-
#[stable(feature = "rust1", since = "1.0.0")]
456-
pub use super::hash::set::*;
457-
}
458-
459442
#[cfg(not(stage0))]
460443
#[cfg_attr(not(test), lang = "hashmap_random_keys")]
461444
#[cfg_attr(test, allow(dead_code))]

src/libstd/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@
264264
#![feature(fnbox)]
265265
#![feature(futures_api)]
266266
#![feature(generator_trait)]
267-
#![feature(hashmap_internals)]
268267
#![feature(int_error_internals)]
269268
#![feature(integer_atomics)]
270269
#![feature(into_cow)]

src/test/ui/missing-allocator.rs

+3
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ fn panic(_: &core::panic::PanicInfo) -> ! {
2323
#[lang = "oom"]
2424
fn oom() {}
2525

26+
#[lang = "hashmap_random_keys"]
27+
fn hashmap_random_keys() {}
28+
2629
extern crate alloc;

0 commit comments

Comments
 (0)