-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
allocator: refactor for stabilisation #157428
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
base: main
Are you sure you want to change the base?
Changes from 14 commits
354678d
ecfda4e
565c994
d82182c
a3db8cd
0fca0d1
d4cb394
24f496f
4868441
ad88f59
5af9c06
c172f93
dffda9e
aa9abd6
59219ba
4805e24
ffdb858
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -206,10 +206,12 @@ use core::task::{Context, Poll}; | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| #[cfg(not(no_global_oom_handling))] | ||||||||||||||||||||||||
| use crate::alloc::handle_alloc_error; | ||||||||||||||||||||||||
| use crate::alloc::{AllocError, Allocator, Global, Layout}; | ||||||||||||||||||||||||
| use crate::alloc::{ | ||||||||||||||||||||||||
| AllocError, Allocator, AllocatorClone, AllocatorEq, Global, Layout, StaticAllocator, | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
| use crate::raw_vec::RawVec; | ||||||||||||||||||||||||
| #[cfg(not(no_global_oom_handling))] | ||||||||||||||||||||||||
| use crate::str::from_boxed_utf8_unchecked; | ||||||||||||||||||||||||
| use crate::str::from_boxed_utf8_unchecked_in; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /// Conversion related impls for `Box<_>` (`From`, `downcast`, etc) | ||||||||||||||||||||||||
| mod convert; | ||||||||||||||||||||||||
|
|
@@ -712,7 +714,7 @@ impl<T, A: Allocator> Box<T, A> { | |||||||||||||||||||||||
| #[inline(always)] | ||||||||||||||||||||||||
| pub fn pin_in(x: T, alloc: A) -> Pin<Self> | ||||||||||||||||||||||||
| where | ||||||||||||||||||||||||
| A: 'static + Allocator, | ||||||||||||||||||||||||
| A: StaticAllocator, | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| Self::into_pin(Self::new_in(x, alloc)) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
@@ -1979,7 +1981,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> { | |||||||||||||||||||||||
| #[stable(feature = "box_into_pin", since = "1.63.0")] | ||||||||||||||||||||||||
| pub fn into_pin(boxed: Self) -> Pin<Self> | ||||||||||||||||||||||||
| where | ||||||||||||||||||||||||
| A: 'static, | ||||||||||||||||||||||||
| A: StaticAllocator, | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| // It's not possible to move or replace the insides of a `Pin<Box<T>>` | ||||||||||||||||||||||||
| // when `T: !Unpin`, so it's safe to pin it directly without any | ||||||||||||||||||||||||
|
|
@@ -2153,11 +2155,10 @@ impl<T: Clone, A: Allocator + Clone> Clone for Box<[T], A> { | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| #[cfg(not(no_global_oom_handling))] | ||||||||||||||||||||||||
| #[stable(feature = "box_slice_clone", since = "1.3.0")] | ||||||||||||||||||||||||
| impl Clone for Box<str> { | ||||||||||||||||||||||||
| impl<A: Allocator + Clone> Clone for Box<str, A> { | ||||||||||||||||||||||||
| fn clone(&self) -> Self { | ||||||||||||||||||||||||
| // this makes a copy of the data | ||||||||||||||||||||||||
| let buf: Box<[u8]> = self.as_bytes().into(); | ||||||||||||||||||||||||
| unsafe { from_boxed_utf8_unchecked(buf) } | ||||||||||||||||||||||||
| let buf = Box::clone_from_ref_in(self.as_bytes(), self.1.clone()); | ||||||||||||||||||||||||
| unsafe { from_boxed_utf8_unchecked_in(buf) } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -2369,7 +2370,7 @@ impl<Args: Tuple, F: AsyncFn<Args> + ?Sized, A: Allocator> AsyncFn<Args> for Box | |||||||||||||||||||||||
| impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> for Box<T, A> {} | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| #[unstable(feature = "pin_coerce_unsized_trait", issue = "150112")] | ||||||||||||||||||||||||
| unsafe impl<T: ?Sized, A: Allocator> PinCoerceUnsized for Box<T, A> {} | ||||||||||||||||||||||||
| unsafe impl<T: ?Sized, A: StaticAllocator> PinCoerceUnsized for Box<T, A> {} | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // It is quite crucial that we only allow the `Global` allocator here. | ||||||||||||||||||||||||
| // Handling arbitrary custom allocators (which can affect the `Box` layout heavily!) | ||||||||||||||||||||||||
|
|
@@ -2529,3 +2530,21 @@ unsafe impl<T: ?Sized + Allocator, A: Allocator> Allocator for Box<T, A> { | |||||||||||||||||||||||
| unsafe { (**self).shrink(ptr, old_layout, new_layout) } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| #[unstable(feature = "allocator_api", issue = "32838")] | ||||||||||||||||||||||||
| unsafe impl<T, A> AllocatorClone for Box<T, A> | ||||||||||||||||||||||||
| where | ||||||||||||||||||||||||
| T: AllocatorClone, | ||||||||||||||||||||||||
| // Otherwise, the clone impl *here* may unwind. | ||||||||||||||||||||||||
| A: AllocatorClone, | ||||||||||||||||||||||||
| Box<T, A>: Clone, | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
The
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oop yeah ur right
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we could relax this a little more to |
||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| #[unstable(feature = "allocator_api", issue = "32838")] | ||||||||||||||||||||||||
| unsafe impl<T, A> AllocatorEq for Box<T, A> | ||||||||||||||||||||||||
| where | ||||||||||||||||||||||||
| T: AllocatorEq + ?Sized, | ||||||||||||||||||||||||
| A: Allocator, | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.