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:
Mara Bos 2021-02-05 12:26:05 +01:00 committed by GitHub
commit ff3c85fd65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -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
}
}

View 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);
}