From f6ac24339520a6b5536d56724f4a2adbf82f69e5 Mon Sep 17 00:00:00 2001 From: liyixin Date: Thu, 7 May 2026 17:53:30 +0800 Subject: [PATCH 1/4] nightly alloc trait support --- crates/iddqd/Cargo.toml | 1 + crates/iddqd/src/lib.rs | 5 +++++ crates/iddqd/src/support/alloc.rs | 29 +++++++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/crates/iddqd/Cargo.toml b/crates/iddqd/Cargo.toml index eb4c6d78..6ffad12d 100644 --- a/crates/iddqd/Cargo.toml +++ b/crates/iddqd/Cargo.toml @@ -46,6 +46,7 @@ allocator-api2 = ["iddqd-test-utils/allocator-api2"] daft = ["dep:daft", "dep:ref-cast"] default = ["allocator-api2", "std", "default-hasher"] default-hasher = ["dep:foldhash", "iddqd-test-utils/default-hasher"] +nightly = [] proptest = ["dep:proptest"] schemars08 = ["dep:schemars", "dep:serde_json", "serde"] serde = ["dep:serde_core", "iddqd-test-utils/serde"] diff --git a/crates/iddqd/src/lib.rs b/crates/iddqd/src/lib.rs index 1996a749..e6e6b44e 100644 --- a/crates/iddqd/src/lib.rs +++ b/crates/iddqd/src/lib.rs @@ -317,6 +317,10 @@ //! - `default-hasher`: Enables the `DefaultHashBuilder` type. Disable this //! feature to require a hash builder type parameter to be passed into //! [`IdHashMap`], [`BiHashMap`], and [`TriHashMap`]. *Enabled by default.* +//! - `nightly`: Enables support for the nightly `core::alloc::Allocator` trait. +//! Requires a nightly Rust compiler. When enabled, map types accept any type +//! implementing `core::alloc::Allocator` as a custom allocator. *Not enabled +//! by default.* //! - `proptest`: Enables [`proptest`] support for all ID map types, providing //! [`Arbitrary`] implementations and strategies for property-based testing. //! *Not enabled by default.* @@ -367,6 +371,7 @@ #![no_std] #![cfg_attr(doc_cfg, feature(doc_cfg))] +#![cfg_attr(feature = "nightly", feature(allocator_api))] #![warn(missing_docs)] #[cfg_attr(not(feature = "std"), macro_use)] // for `format!` diff --git a/crates/iddqd/src/support/alloc.rs b/crates/iddqd/src/support/alloc.rs index 02360bbc..aae39ea0 100644 --- a/crates/iddqd/src/support/alloc.rs +++ b/crates/iddqd/src/support/alloc.rs @@ -5,8 +5,6 @@ pub use self::inner::Global; pub(crate) use self::inner::{AllocWrapper, Allocator, global_alloc}; -// TODO: support nightly. - // Basic non-nightly case. #[cfg(feature = "allocator-api2")] mod inner { @@ -103,3 +101,30 @@ mod inner { } } } + +// Nightly support: implement `core::alloc::Allocator` for `AllocWrapper`. +// This bridges `allocator_api2::alloc::Allocator` types to the nightly +// `core::alloc::Allocator` trait, allowing `AllocWrapper` to be used where +// the standard library allocator trait is expected. +#[cfg(feature = "nightly")] +// SAFETY: These functions just forward to the wrapped allocator. +unsafe impl alloc::alloc::Allocator for AllocWrapper { + #[inline] + fn allocate( + &self, + layout: alloc::alloc::Layout, + ) -> Result, alloc::alloc::AllocError> { + Allocator::allocate(&self.0, layout) + .map_err(|_| alloc::alloc::AllocError) + } + + #[inline] + unsafe fn deallocate( + &self, + ptr: core::ptr::NonNull, + layout: alloc::alloc::Layout, + ) { + // SAFETY: caller upholds safety contract. + unsafe { Allocator::deallocate(&self.0, ptr, layout) } + } +} From a0245ab836cc5d476a82a1e27511995f3444842d Mon Sep 17 00:00:00 2001 From: liyixin Date: Thu, 7 May 2026 18:02:57 +0800 Subject: [PATCH 2/4] exclude nightly in ci --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 87d2ef89..3739de8c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: with: tool: just,cargo-hack,cargo-sync-rdme - name: Lint (clippy) - run: just powerset --partition ${{ matrix.partition }}/10 clippy --all-targets + run: just powerset --exclude-features nightly --partition ${{ matrix.partition }}/10 clippy --all-targets - name: Lint (rustfmt) run: cargo xfmt --check - name: Run rustdoc From fbc9e4a91706879ea0d3b1000d1d491359ee5b3e Mon Sep 17 00:00:00 2001 From: liyixin Date: Thu, 7 May 2026 18:11:06 +0800 Subject: [PATCH 3/4] exclude nightly in ci --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3739de8c..dede44cb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,11 +67,11 @@ jobs: - uses: taiki-e/install-action@just - uses: taiki-e/install-action@nextest - name: Build - run: just powerset --partition ${{ matrix.partition }}/10 build + run: just powerset --exclude-features nightly --partition ${{ matrix.partition }}/10 build - name: Run tests - run: just powerset --partition ${{ matrix.partition }}/10 nextest run + run: just powerset --exclude-features nightly --partition ${{ matrix.partition }}/10 nextest run - name: Doctests - run: just powerset --partition ${{ matrix.partition }}/10 test --doc + run: just powerset --exclude-features nightly --partition ${{ matrix.partition }}/10 test --doc build-no-std: name: Build on no-std From 4a041d8b324b89b14d7f502c55e2911db46e6f16 Mon Sep 17 00:00:00 2001 From: liyixin Date: Thu, 7 May 2026 18:34:02 +0800 Subject: [PATCH 4/4] regenerate readmes --- crates/iddqd/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/iddqd/README.md b/crates/iddqd/README.md index b292f920..41eb5880 100644 --- a/crates/iddqd/README.md +++ b/crates/iddqd/README.md @@ -289,6 +289,10 @@ platform-specific notion of thread locals, would suffice to make * `default-hasher`: Enables the `DefaultHashBuilder` type. Disable this feature to require a hash builder type parameter to be passed into [`IdHashMap`](https://docs.rs/iddqd/0.4.0/iddqd/id_hash_map/imp/struct.IdHashMap.html), [`BiHashMap`](https://docs.rs/iddqd/0.4.0/iddqd/bi_hash_map/imp/struct.BiHashMap.html), and [`TriHashMap`](https://docs.rs/iddqd/0.4.0/iddqd/tri_hash_map/imp/struct.TriHashMap.html). *Enabled by default.* +* `nightly`: Enables support for the nightly `core::alloc::Allocator` trait. + Requires a nightly Rust compiler. When enabled, map types accept any type + implementing `core::alloc::Allocator` as a custom allocator. *Not enabled + by default.* * `proptest`: Enables [`proptest`](https://docs.rs/proptest/1.7.0/proptest/index.html) support for all ID map types, providing [`Arbitrary`] implementations and strategies for property-based testing. *Not enabled by default.*