diff --git a/src/raw/alloc.rs b/src/alloc.rs similarity index 92% rename from src/raw/alloc.rs rename to src/alloc.rs index 87b41218b..cad84df98 100644 --- a/src/raw/alloc.rs +++ b/src/alloc.rs @@ -8,11 +8,11 @@ pub(crate) use self::inner::{Allocator, Global, do_alloc}; // This is used when building for `std`. #[cfg(feature = "nightly")] mod inner { - #[cfg(test)] - pub(crate) use crate::alloc::alloc::AllocError; - use crate::alloc::alloc::Layout; - pub(crate) use crate::alloc::alloc::{Allocator, Global}; use core::ptr::NonNull; + #[cfg(test)] + pub(crate) use stdalloc::alloc::AllocError; + use stdalloc::alloc::Layout; + pub(crate) use stdalloc::alloc::{Allocator, Global}; pub(crate) fn do_alloc(alloc: &A, layout: Layout) -> Result, ()> { match alloc.allocate(layout) { @@ -30,11 +30,11 @@ mod inner { // `core::alloc::Allocator`. #[cfg(all(not(feature = "nightly"), feature = "allocator-api2"))] mod inner { - use crate::alloc::alloc::Layout; #[cfg(test)] pub(crate) use allocator_api2::alloc::AllocError; pub(crate) use allocator_api2::alloc::{Allocator, Global}; use core::ptr::NonNull; + use stdalloc::alloc::Layout; pub(crate) fn do_alloc(alloc: &A, layout: Layout) -> Result, ()> { match alloc.allocate(layout) { @@ -54,8 +54,8 @@ mod inner { // or `nightly` without disturbing users that don't want to use it. #[cfg(not(any(feature = "nightly", feature = "allocator-api2")))] mod inner { - use crate::alloc::alloc::{Layout, alloc, dealloc}; use core::ptr::NonNull; + use stdalloc::alloc::{Layout, alloc, dealloc}; #[expect(clippy::missing_safety_doc)] // not exposed outside of this crate pub unsafe trait Allocator { diff --git a/src/external_trait_impls/rayon/helpers.rs b/src/external_trait_impls/rayon/helpers.rs index d934264c0..b8fb43a37 100644 --- a/src/external_trait_impls/rayon/helpers.rs +++ b/src/external_trait_impls/rayon/helpers.rs @@ -1,5 +1,5 @@ -use alloc::collections::LinkedList; -use alloc::vec::Vec; +use stdalloc::collections::LinkedList; +use stdalloc::vec::Vec; use rayon::iter::{IntoParallelIterator, ParallelIterator}; diff --git a/src/external_trait_impls/rayon/map.rs b/src/external_trait_impls/rayon/map.rs index 3897606ee..1a33c5ff3 100644 --- a/src/external_trait_impls/rayon/map.rs +++ b/src/external_trait_impls/rayon/map.rs @@ -1,8 +1,8 @@ //! Rayon extensions for `HashMap`. use super::raw::{RawIntoParIter, RawParDrain, RawParIter}; -use crate::hash_map::HashMap; -use crate::raw::{Allocator, Global}; +use crate::HashMap; +use crate::alloc::{Allocator, Global}; use core::fmt; use core::hash::{BuildHasher, Hash}; use core::marker::PhantomData; @@ -456,13 +456,13 @@ where #[cfg(test)] mod test_par_map { - use alloc::vec::Vec; use core::hash::{Hash, Hasher}; use core::sync::atomic::{AtomicUsize, Ordering}; + use stdalloc::vec::Vec; use rayon::prelude::*; - use crate::hash_map::HashMap; + use crate::HashMap; struct Droppable<'a> { k: usize, diff --git a/src/external_trait_impls/rayon/raw.rs b/src/external_trait_impls/rayon/raw.rs index 5a555ce07..b8fc069d0 100644 --- a/src/external_trait_impls/rayon/raw.rs +++ b/src/external_trait_impls/rayon/raw.rs @@ -1,5 +1,5 @@ -use crate::raw::Bucket; -use crate::raw::{Allocator, Global, RawIter, RawIterRange, RawTable}; +use crate::alloc::{Allocator, Global}; +use crate::raw::{Bucket, RawIter, RawIterRange, RawTable}; use crate::scopeguard::guard; use core::marker::PhantomData; use core::mem; diff --git a/src/external_trait_impls/rayon/set.rs b/src/external_trait_impls/rayon/set.rs index 4ef64d63d..205d2e0b1 100644 --- a/src/external_trait_impls/rayon/set.rs +++ b/src/external_trait_impls/rayon/set.rs @@ -1,8 +1,8 @@ //! Rayon extensions for `HashSet`. use super::map; -use crate::hash_set::HashSet; -use crate::raw::{Allocator, Global}; +use crate::HashSet; +use crate::alloc::{Allocator, Global}; use core::hash::{BuildHasher, Hash}; use rayon::iter::plumbing::UnindexedConsumer; use rayon::iter::{FromParallelIterator, IntoParallelIterator, ParallelExtend, ParallelIterator}; @@ -386,12 +386,12 @@ where #[cfg(test)] mod test_par_set { - use alloc::vec::Vec; use core::sync::atomic::{AtomicUsize, Ordering}; + use stdalloc::vec::Vec; use rayon::prelude::*; - use crate::hash_set::HashSet; + use crate::HashSet; #[test] fn test_disjoint() { diff --git a/src/external_trait_impls/rayon/table.rs b/src/external_trait_impls/rayon/table.rs index 9ace7c7da..20298f40e 100644 --- a/src/external_trait_impls/rayon/table.rs +++ b/src/external_trait_impls/rayon/table.rs @@ -1,8 +1,8 @@ //! Rayon extensions for `HashTable`. use super::raw::{RawIntoParIter, RawParDrain, RawParIter}; -use crate::hash_table::HashTable; -use crate::raw::{Allocator, Global}; +use crate::HashTable; +use crate::alloc::{Allocator, Global}; use core::fmt; use core::marker::PhantomData; use rayon::iter::plumbing::UnindexedConsumer; @@ -206,8 +206,8 @@ impl<'a, T: Send, A: Allocator> IntoParallelIterator for &'a mut HashTable #[cfg(test)] mod test_par_table { - use alloc::vec::Vec; use core::sync::atomic::{AtomicUsize, Ordering}; + use stdalloc::vec::Vec; use rayon::prelude::*; diff --git a/src/external_trait_impls/serde.rs b/src/external_trait_impls/serde.rs index 92614fe04..f55eee485 100644 --- a/src/external_trait_impls/serde.rs +++ b/src/external_trait_impls/serde.rs @@ -11,14 +11,14 @@ mod size_hint { } mod map { - use crate::raw::Allocator; + use crate::alloc::Allocator; use core::fmt; use core::hash::{BuildHasher, Hash}; use core::marker::PhantomData; use serde_core::de::{Deserialize, Deserializer, MapAccess, Visitor}; use serde_core::ser::{Serialize, Serializer}; - use crate::hash_map::HashMap; + use crate::HashMap; use super::size_hint; @@ -97,14 +97,14 @@ mod map { } mod set { - use crate::raw::Allocator; + use crate::alloc::Allocator; use core::fmt; use core::hash::{BuildHasher, Hash}; use core::marker::PhantomData; use serde_core::de::{Deserialize, Deserializer, SeqAccess, Visitor}; use serde_core::ser::{Serialize, Serializer}; - use crate::hash_set::HashSet; + use crate::HashSet; use super::size_hint; diff --git a/src/lib.rs b/src/lib.rs index 409204824..fbd366a00 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,7 +43,7 @@ extern crate std; #[cfg_attr(test, macro_use)] #[cfg_attr(feature = "rustc-dep-of-std", allow(unused_extern_crates))] -extern crate alloc; +extern crate alloc as stdalloc; #[doc = include_str!("../README.md")] #[cfg(doctest)] @@ -52,6 +52,7 @@ pub struct ReadmeDoctests; #[macro_use] mod macros; +mod alloc; mod control; mod hasher; mod raw; @@ -170,6 +171,6 @@ pub enum TryReserveError { /// The memory allocator returned an error AllocError { /// The layout of the allocation request that failed. - layout: alloc::alloc::Layout, + layout: stdalloc::alloc::Layout, }, } diff --git a/src/map.rs b/src/map.rs index 0f8db55d0..f009f4132 100644 --- a/src/map.rs +++ b/src/map.rs @@ -1,8 +1,6 @@ -use crate::raw::{ - Allocator, Bucket, Global, RawDrain, RawExtractIf, RawIntoIter, RawIter, RawTable, -}; +use crate::alloc::{Allocator, Global}; +use crate::raw::{Bucket, RawDrain, RawExtractIf, RawIntoIter, RawIter, RawTable}; use crate::{DefaultHashBuilder, Equivalent, TryReserveError}; -use ::alloc::borrow::ToOwned; use core::borrow::Borrow; use core::fmt::{self, Debug}; use core::hash::{BuildHasher, Hash}; @@ -10,6 +8,7 @@ use core::iter::FusedIterator; use core::marker::PhantomData; use core::mem; use core::ops::Index; +use stdalloc::borrow::ToOwned; #[cfg(feature = "raw-entry")] pub use crate::raw_entry::*; @@ -1055,7 +1054,7 @@ where /// in case of allocation error. Use [`try_reserve`](HashMap::try_reserve) instead /// if you want to handle memory allocation failure. /// - /// [`abort`]: alloc::alloc::handle_alloc_error + /// [`abort`]: stdalloc::alloc::handle_alloc_error /// /// # Examples /// @@ -4863,9 +4862,7 @@ mod test_map { use super::Entry::{Occupied, Vacant}; use super::EntryRef; use super::HashMap; - use crate::raw::{AllocError, Allocator, Global}; - use alloc::string::{String, ToString}; - use alloc::sync::Arc; + use crate::alloc::{AllocError, Allocator, Global}; use core::alloc::Layout; use core::ptr::NonNull; use core::sync::atomic::{AtomicI8, Ordering}; @@ -4873,6 +4870,8 @@ mod test_map { use std::borrow::ToOwned; use std::cell::RefCell; use std::vec::Vec; + use stdalloc::string::{String, ToString}; + use stdalloc::sync::Arc; #[test] fn test_zero_capacities() { @@ -6241,7 +6240,7 @@ mod test_map { #[test] #[should_panic = "panic in clone"] fn test_clone_from_memory_leaks() { - use alloc::vec::Vec; + use stdalloc::vec::Vec; struct CheckedClone { panic_in_clone: bool, diff --git a/src/raw/mod.rs b/src/raw.rs similarity index 99% rename from src/raw/mod.rs rename to src/raw.rs index c9870bf4c..4bc1f7439 100644 --- a/src/raw/mod.rs +++ b/src/raw.rs @@ -1,5 +1,4 @@ use crate::TryReserveError; -use crate::alloc::alloc::{Layout, handle_alloc_error}; use crate::control::{BitMaskIter, Group, Tag, TagSliceExt}; use crate::scopeguard::{ScopeGuard, guard}; use crate::util::{invalid_mut, likely, unlikely}; @@ -10,11 +9,11 @@ use core::mem; use core::ptr::NonNull; use core::slice; use core::{hint, ptr}; +use stdalloc::alloc::{Layout, handle_alloc_error}; -mod alloc; #[cfg(test)] -pub(crate) use self::alloc::AllocError; -pub(crate) use self::alloc::{Allocator, Global, do_alloc}; +use crate::alloc::AllocError; +use crate::alloc::{Allocator, Global, do_alloc}; #[inline] unsafe fn offset_from(to: *const T, from: *const T) -> usize { @@ -1571,7 +1570,7 @@ impl RawTableInner { /// /// See also [`Allocator`] API for other safety concerns. /// - /// [`Allocator`]: alloc::alloc::Allocator + /// [`Allocator`]: stdalloc::alloc::Allocator #[cfg_attr(feature = "inline-more", inline)] unsafe fn new_uninitialized( alloc: &A, @@ -1670,7 +1669,7 @@ impl RawTableInner { /// All the control bytes are initialized with the [`Tag::EMPTY`] bytes. /// /// [`fallible_with_capacity`]: RawTableInner::fallible_with_capacity - /// [`abort`]: alloc::abort::handle_alloc_error + /// [`abort`]: stdalloc::abort::handle_alloc_error fn with_capacity(alloc: &A, table_layout: TableLayout, capacity: usize) -> Self where A: Allocator, @@ -3118,8 +3117,8 @@ impl RawTableInner { /// See also [`GlobalAlloc::dealloc`] or [`Allocator::deallocate`] for more information. /// /// [`Undefined Behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html - /// [`GlobalAlloc::dealloc`]: alloc::alloc::GlobalAlloc::dealloc - /// [`Allocator::deallocate`]: alloc::alloc::Allocator::deallocate + /// [`GlobalAlloc::dealloc`]: stdalloc::alloc::GlobalAlloc::dealloc + /// [`Allocator::deallocate`]: stdalloc::alloc::Allocator::deallocate #[inline] unsafe fn free_buckets(&mut self, alloc: &A, table_layout: TableLayout) where @@ -3150,8 +3149,8 @@ impl RawTableInner { /// See also [`GlobalAlloc::dealloc`] or [`Allocator::deallocate`] for more information. /// /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html - /// [`GlobalAlloc::dealloc`]: alloc::GlobalAlloc::dealloc - /// [`Allocator::deallocate`]: alloc::Allocator::deallocate + /// [`GlobalAlloc::dealloc`]: stdalloc::GlobalAlloc::dealloc + /// [`Allocator::deallocate`]: stdalloc::Allocator::deallocate #[inline] unsafe fn allocation_info(&self, table_layout: TableLayout) -> (NonNull, Layout) { debug_assert!( @@ -4441,7 +4440,7 @@ mod test_map { /// AN UNINITIALIZED TABLE DURING THE DROP #[test] fn test_drop_uninitialized() { - use ::alloc::vec::Vec; + use stdalloc::vec::Vec; let table = unsafe { // SAFETY: The `buckets` is power of two and we're not @@ -4456,7 +4455,7 @@ mod test_map { /// ARE ZERO, EVEN IF WE HAVE `FULL` CONTROL BYTES. #[test] fn test_drop_zero_items() { - use ::alloc::vec::Vec; + use stdalloc::vec::Vec; unsafe { // SAFETY: The `buckets` is power of two and we're not // trying to actually use the returned RawTable. @@ -4502,10 +4501,10 @@ mod test_map { #[test] fn test_catch_panic_clone_from() { use super::{AllocError, Allocator, Global}; - use ::alloc::sync::Arc; - use ::alloc::vec::Vec; use core::sync::atomic::{AtomicI8, Ordering}; use std::thread; + use stdalloc::sync::Arc; + use stdalloc::vec::Vec; struct MyAllocInner { drop_count: Arc, diff --git a/src/raw_entry.rs b/src/raw_entry.rs index 0905e35ca..13b71bc3e 100644 --- a/src/raw_entry.rs +++ b/src/raw_entry.rs @@ -1,6 +1,7 @@ -use crate::hash_map::{equivalent, make_hash, make_hasher}; -use crate::raw::{Allocator, Bucket, Global, RawTable}; -use crate::{Equivalent, HashMap}; +use crate::Equivalent; +use crate::alloc::{Allocator, Global}; +use crate::map::{HashMap, equivalent, make_hash, make_hasher}; +use crate::raw::{Bucket, RawTable}; use core::fmt::{self, Debug}; use core::hash::{BuildHasher, Hash}; use core::mem; diff --git a/src/rustc_entry.rs b/src/rustc_entry.rs index 2fb7d51be..d442f7903 100644 --- a/src/rustc_entry.rs +++ b/src/rustc_entry.rs @@ -1,6 +1,7 @@ use self::RustcEntry::*; +use crate::alloc::{Allocator, Global}; use crate::map::{Drain, HashMap, IntoIter, Iter, IterMut, make_hash}; -use crate::raw::{Allocator, Bucket, Global, RawTable}; +use crate::raw::{Bucket, RawTable}; use core::fmt::{self, Debug}; use core::hash::{BuildHasher, Hash}; use core::mem; diff --git a/src/set.rs b/src/set.rs index 6a8683ece..81d61c893 100644 --- a/src/set.rs +++ b/src/set.rs @@ -7,7 +7,8 @@ use map::make_hash; use super::map::{self, HashMap, Keys}; use crate::DefaultHashBuilder; -use crate::raw::{Allocator, Global, RawExtractIf}; +use crate::alloc::{Allocator, Global}; +use crate::raw::RawExtractIf; // Future Optimization (FIXME!) // ============================= @@ -616,7 +617,7 @@ where /// in case of allocation error. Use [`try_reserve`](HashSet::try_reserve) instead /// if you want to handle memory allocation failure. /// - /// [`abort`]: alloc::alloc::handle_alloc_error + /// [`abort`]: stdalloc::alloc::handle_alloc_error /// /// # Examples /// diff --git a/src/table.rs b/src/table.rs index 8bb2275b4..094350442 100644 --- a/src/table.rs +++ b/src/table.rs @@ -2,10 +2,11 @@ use core::{fmt, iter::FusedIterator, marker::PhantomData, ptr::NonNull}; use crate::{ TryReserveError, + alloc::{Allocator, Global}, control::Tag, raw::{ - Allocator, Bucket, FullBucketsIndices, Global, RawDrain, RawExtractIf, RawIntoIter, - RawIter, RawIterHash, RawIterHashIndices, RawTable, + Bucket, FullBucketsIndices, RawDrain, RawExtractIf, RawIntoIter, RawIter, RawIterHash, + RawIterHashIndices, RawTable, }, }; @@ -816,7 +817,7 @@ where /// in case of allocation error. Use [`try_reserve`](HashTable::try_reserve) instead /// if you want to handle memory allocation failure. /// - /// [`abort`]: alloc::alloc::handle_alloc_error + /// [`abort`]: stdalloc::alloc::handle_alloc_error /// /// # Examples ///