make Allocator object-safe
add test to ensure object-safety This allows for runtime polymorphic allocators
This commit is contained in:
parent
120b2a704a
commit
d06384ac29
@ -342,7 +342,10 @@ pub unsafe trait Allocator {
|
||||
///
|
||||
/// The returned adaptor also implements `Allocator` and will simply borrow this.
|
||||
#[inline(always)]
|
||||
fn by_ref(&self) -> &Self {
|
||||
fn by_ref(&self) -> &Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
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…
x
Reference in New Issue
Block a user