Rollup merge of #81730 - RustyYato:object-safe-allocator, r=Amanieu
Make `Allocator` object-safe This allows rust-lang/wg-allocators#83: polymorphic allocators
This commit is contained in:
commit
ff3c85fd65
2 changed files with 17 additions and 1 deletions
|
@ -342,7 +342,10 @@ pub unsafe trait Allocator {
|
||||||
///
|
///
|
||||||
/// The returned adaptor also implements `Allocator` and will simply borrow this.
|
/// The returned adaptor also implements `Allocator` and will simply borrow this.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn by_ref(&self) -> &Self {
|
fn by_ref(&self) -> &Self
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
13
src/test/ui/allocator/object-safe.rs
Normal file
13
src/test/ui/allocator/object-safe.rs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
// run-pass
|
||||||
|
|
||||||
|
// Check that `Allocator` is object safe, this allows for polymorphic allocators
|
||||||
|
|
||||||
|
#![feature(allocator_api)]
|
||||||
|
|
||||||
|
use std::alloc::{Allocator, System};
|
||||||
|
|
||||||
|
fn ensure_object_safe(_: &dyn Allocator) {}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
ensure_object_safe(&System);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue