Skip to content

Commit 5a6c1df

Browse files
committed
Auto merge of #252 - optimalstrategy:add-alloc-to-clone-impls, r=Amanieu
Add an allocator type parameter to HashMap's and HashSet's Clone impls HashMap's and HashSet's Clone implementations are missing the type parameter for a custom allocator, which makes them a lot less usable with custom allocators. Curiously, the parameter is present on RawTable's Clone implementation, so I figured that this must be an accident. This PR adds the parameter to HashMap and HashSet's Clone impls. Here's a minimal reproducible example: ```rust #![feature(allocator_api)] use std::{ alloc::{AllocError, Allocator, Global, Layout}, ptr::NonNull, }; use hashbrown::HashMap; #[derive(Debug, Clone, Copy)] pub struct DummyAllocator; unsafe impl Allocator for DummyAllocator { fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> { Global.allocate(layout) } unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) { Global.deallocate(ptr, layout) } } fn main() { let map = HashMap::new_in(DummyAllocator); // Error: no method named `clone` found for struct `hashbrown::HashMap<&str, &str, ahash::random_state::RandomState, DummyAllocator>` in the current scope let map2 = map.clone(); } ```
2 parents 85f42d6 + 49b1aeb commit 5a6c1df

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ pub struct HashMap<K, V, S = DefaultHashBuilder, A: Allocator + Clone = Global>
194194
pub(crate) table: RawTable<(K, V), A>,
195195
}
196196

197-
impl<K: Clone, V: Clone, S: Clone> Clone for HashMap<K, V, S> {
197+
impl<K: Clone, V: Clone, S: Clone, A: Allocator + Clone> Clone for HashMap<K, V, S, A> {
198198
fn clone(&self) -> Self {
199199
HashMap {
200200
hash_builder: self.hash_builder.clone(),

src/set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub struct HashSet<T, S = DefaultHashBuilder, A: Allocator + Clone = Global> {
116116
pub(crate) map: HashMap<T, (), S, A>,
117117
}
118118

119-
impl<T: Clone, S: Clone> Clone for HashSet<T, S> {
119+
impl<T: Clone, S: Clone, A: Allocator + Clone> Clone for HashSet<T, S, A> {
120120
fn clone(&self) -> Self {
121121
HashSet {
122122
map: self.map.clone(),

0 commit comments

Comments
 (0)