Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to nightly-2020-12-07 #2

Merged
merged 1 commit into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2020-11-24"
channel = "nightly-2020-12-07"
components = [ "rustfmt", "miri", "clippy" ]
26 changes: 13 additions & 13 deletions src/buffer/alloc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{Buffer, UnmanagedBuffer};
use alloc::alloc::Global;
use core::{
alloc::{AllocError, AllocRef, Layout},
alloc::{AllocError, Allocator, Layout},
marker::{PhantomData, Unsize},
mem,
ops::CoerceUnsized,
Expand Down Expand Up @@ -41,12 +41,12 @@ impl<T> AllocatedBuffer<T> {
}
}

impl<T, A: ?Sized + AllocRef> AllocatedBuffer<T, A> {
impl<T, A: ?Sized + Allocator> AllocatedBuffer<T, A> {
fn allocate_in(allocator: &A, init: Init) -> Result<Self, AllocError> {
let layout = Layout::new::<T>();
let ptr = match init {
Init::Unspecified => allocator.alloc(layout)?,
Init::Zeroed => allocator.alloc_zeroed(layout)?,
Init::Unspecified => allocator.allocate(layout)?,
Init::Zeroed => allocator.allocate_zeroed(layout)?,
};
unsafe { Ok(Self::from_raw(ptr.as_non_null_ptr().cast())) }
}
Expand All @@ -60,7 +60,7 @@ impl<T, A: ?Sized + AllocRef> AllocatedBuffer<T, A> {
}
}

impl<T, A: ?Sized + AllocRef> AllocatedBuffer<[T], A> {
impl<T, A: ?Sized + Allocator> AllocatedBuffer<[T], A> {
fn capacity_from_bytes(bytes: usize) -> usize {
debug_assert_ne!(mem::size_of::<T>(), 0);
bytes / mem::size_of::<T>()
Expand All @@ -73,8 +73,8 @@ impl<T, A: ?Sized + AllocRef> AllocatedBuffer<[T], A> {
let layout = Layout::array::<T>(len).map_err(|_| AllocError)?;
alloc_guard(layout.size()).map_err(|_| AllocError)?;
let ptr = match init {
Init::Unspecified => allocator.alloc(layout)?,
Init::Zeroed => allocator.alloc_zeroed(layout)?,
Init::Unspecified => allocator.allocate(layout)?,
Init::Zeroed => allocator.allocate_zeroed(layout)?,
};

NonNull::slice_from_raw_parts(
Expand All @@ -94,7 +94,7 @@ impl<T, A: ?Sized + AllocRef> AllocatedBuffer<[T], A> {
}
}

impl<T: ?Sized, A: ?Sized + AllocRef> Buffer<T> for AllocatedBuffer<T, A> {
impl<T: ?Sized, A: ?Sized + Allocator> Buffer<T> for AllocatedBuffer<T, A> {
type ExternalData = A;

fn as_ptr(&self, _data: &Self::ExternalData) -> *const T {
Expand All @@ -106,7 +106,7 @@ impl<T: ?Sized, A: ?Sized + AllocRef> Buffer<T> for AllocatedBuffer<T, A> {
}
}

impl<T, A: ?Sized + AllocRef> Buffer<mem::MaybeUninit<T>> for AllocatedBuffer<T, A> {
impl<T, A: ?Sized + Allocator> Buffer<mem::MaybeUninit<T>> for AllocatedBuffer<T, A> {
type ExternalData = A;

fn as_ptr(&self, _data: &Self::ExternalData) -> *const mem::MaybeUninit<T> {
Expand All @@ -118,7 +118,7 @@ impl<T, A: ?Sized + AllocRef> Buffer<mem::MaybeUninit<T>> for AllocatedBuffer<T,
}
}

impl<T, A: ?Sized + AllocRef> Buffer<[mem::MaybeUninit<T>]> for AllocatedBuffer<[T], A> {
impl<T, A: ?Sized + Allocator> Buffer<[mem::MaybeUninit<T>]> for AllocatedBuffer<[T], A> {
type ExternalData = A;

fn as_ptr(&self, _data: &Self::ExternalData) -> *const [mem::MaybeUninit<T>] {
Expand All @@ -130,12 +130,12 @@ impl<T, A: ?Sized + AllocRef> Buffer<[mem::MaybeUninit<T>]> for AllocatedBuffer<
}
}

impl<T: ?Sized, A: AllocRef> UnmanagedBuffer<T> for AllocatedBuffer<T, A> {
impl<T: ?Sized, A: Allocator> UnmanagedBuffer<T> for AllocatedBuffer<T, A> {
unsafe fn free_unchecked(&mut self, allocator: &Self::ExternalData) {
let size = mem::size_of_val(self.ptr.as_ref());
let align = mem::align_of_val(self.ptr.as_ref());
let layout = Layout::from_size_align_unchecked(size, align);
allocator.dealloc(self.ptr.cast(), layout);
allocator.deallocate(self.ptr.cast(), layout);
}
}

Expand All @@ -148,7 +148,7 @@ const fn alloc_guard(alloc_size: usize) -> Result<(), AllocError> {
}
}

impl<T: ?Sized + Unsize<U>, U: ?Sized, A: AllocRef> CoerceUnsized<AllocatedBuffer<U, A>>
impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<AllocatedBuffer<U, A>>
for AllocatedBuffer<T, A>
{
}