@@ -395,17 +395,22 @@ pub const unsafe trait Allocator {
395395 }
396396}
397397
398- /// Internal trait for enabling dyn-compatible allocators. Do not manually call
399- /// these methods; use their equivalents on `Allocator` instead.
398+ /// Marker trait for enabling dyn-compatible allocators.
399+ ///
400+ /// # Usage
401+ ///
402+ /// `dyn DynAllocator` objects implement [`Allocator`], thus enabling these to be
403+ /// used as dynamically-dispatched allocators. This also applies to `dyn` objects
404+ /// with autotrait bounds alongside `DynAllocator`, e.g. `dyn DynAllocator + Send`.
400405///
401406/// # Safety
402407///
403408/// Same as [`Allocator`].
404409#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
405- #[ rust_analyzer :: skip ]
406- # [ expect ( missing_docs ) ]
407- # [ expect ( clippy :: missing_safety_doc ) ]
408- pub impl ( self ) unsafe trait DynAllocator {
410+ #[ expect ( private_bounds ) ]
411+ pub impl ( self ) unsafe trait DynAllocator : DynAllocatorInternal { }
412+
413+ unsafe trait DynAllocatorInternal {
409414 fn __dyn_allocate ( & self , layout : Layout ) -> Result < NonNull < [ u8 ] > , AllocError > ;
410415 fn __dyn_allocate_zeroed ( & self , layout : Layout ) -> Result < NonNull < [ u8 ] > , AllocError > ;
411416 unsafe fn __dyn_deallocate ( & self , ptr : NonNull < u8 > , layout : Layout ) ;
@@ -595,8 +600,7 @@ where
595600 }
596601}
597602
598- #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
599- unsafe impl < A : Allocator + ?Sized > DynAllocator for A {
603+ unsafe impl < A : Allocator + ?Sized > DynAllocatorInternal for A {
600604 fn __dyn_allocate ( & self , layout : Layout ) -> Result < NonNull < [ u8 ] > , AllocError > {
601605 self . allocate ( layout)
602606 }
@@ -636,9 +640,13 @@ unsafe impl<A: Allocator + ?Sized> DynAllocator for A {
636640 }
637641}
638642
643+ #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
644+ unsafe impl < A : DynAllocatorInternal + ?Sized > DynAllocator for A { }
645+
639646// FIXME(nia-e): See if it's possible to make this built-in to the typesystem,
640647// e.g. by making the impl work on arbitrary `dyn DynAlloc + Foo + Bar`. Otherwise,
641- // just expand this macro with other trait combinations for now.
648+ // just expand this macro with other trait combinations for now. Also needs to be
649+ // extendd for arbitrary `dyn DynAllocator + 'a`.
642650// https://rust.tf/157506
643651
644652macro_rules! impl_dyn_allocator {
0 commit comments