Skip to content

Commit ff3c85f

Browse files
authored
Rollup merge of #81730 - RustyYato:object-safe-allocator, r=Amanieu
Make `Allocator` object-safe This allows rust-lang/wg-allocators#83: polymorphic allocators
2 parents 21c276f + d06384a commit ff3c85f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

library/core/src/alloc/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,10 @@ pub unsafe trait Allocator {
342342
///
343343
/// The returned adaptor also implements `Allocator` and will simply borrow this.
344344
#[inline(always)]
345-
fn by_ref(&self) -> &Self {
345+
fn by_ref(&self) -> &Self
346+
where
347+
Self: Sized,
348+
{
346349
self
347350
}
348351
}

src/test/ui/allocator/object-safe.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// run-pass
2+
3+
// Check that `Allocator` is object safe, this allows for polymorphic allocators
4+
5+
#![feature(allocator_api)]
6+
7+
use std::alloc::{Allocator, System};
8+
9+
fn ensure_object_safe(_: &dyn Allocator) {}
10+
11+
fn main() {
12+
ensure_object_safe(&System);
13+
}

0 commit comments

Comments
 (0)