Skip to content

Commit

Permalink
Rollup merge of rust-lang#81730 - RustyYato:object-safe-allocator, r=…
Browse files Browse the repository at this point in the history
…Amanieu

Make `Allocator` object-safe

This allows rust-lang/wg-allocators#83: polymorphic allocators
  • Loading branch information
m-ou-se committed Feb 5, 2021
2 parents 21c276f + d06384a commit ff3c85f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion library/core/src/alloc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/allocator/object-safe.rs
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit ff3c85f

Please sign in to comment.