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

Move Layout and LayoutErr to core::mem #71856

Closed
wants to merge 3 commits into from
Closed
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
26 changes: 24 additions & 2 deletions src/liballoc/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ use core::ptr::{NonNull, Unique};
#[doc(inline)]
pub use core::alloc::*;

/// **This alias is soft-deprecated.**
///
/// Although using it won’t cause compilation warning, new code should use [`mem::Layout`] directly
/// instead.
///
/// [`mem::Layout`]: core::mem::Layout
#[stable(feature = "alloc_layout", since = "1.28.0")]
#[doc(no_inline)]
pub use core::mem::Layout;

/// **This alias is soft-deprecated.**
///
/// Although using it won’t cause compilation warning, new code should use [`mem::LayoutError`]
/// directly instead.
///
/// [`mem::LayoutError`]: core::mem::LayoutError
#[stable(feature = "alloc_layout", since = "1.28.0")]
#[doc(no_inline)]
pub use core::mem::LayoutError as LayoutErr;

#[cfg(test)]
mod tests;

Expand Down Expand Up @@ -62,7 +82,8 @@ pub struct Global;
/// # Examples
///
/// ```
/// use std::alloc::{alloc, dealloc, Layout};
/// use std::alloc::{alloc, dealloc};
/// use std::mem::Layout;
///
/// unsafe {
/// let layout = Layout::new::<u16>();
Expand Down Expand Up @@ -144,7 +165,8 @@ pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
/// # Examples
///
/// ```
/// use std::alloc::{alloc_zeroed, dealloc, Layout};
/// use std::alloc::{alloc_zeroed, dealloc};
/// use std::mem::Layout;
///
/// unsafe {
/// let layout = Layout::new::<u16>();
Expand Down
18 changes: 10 additions & 8 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@
//! [`Box::<T>::from_raw(value)`]: struct.Box.html#method.from_raw
//! [`Box::<T>::into_raw`]: struct.Box.html#method.into_raw
//! [`Global`]: ../alloc/struct.Global.html
//! [`Layout`]: ../alloc/struct.Layout.html
//! [`Layout::for_value(&*value)`]: ../alloc/struct.Layout.html#method.for_value
//! [`Layout`]: ../../core/mem/struct.Layout.html
//! [`Layout::for_value(&*value)`]: ../../core/mem/struct.Layout.html#method.for_value

#![stable(feature = "rust1", since = "1.0.0")]

Expand All @@ -137,7 +137,7 @@ use core::future::Future;
use core::hash::{Hash, Hasher};
use core::iter::{FromIterator, FusedIterator, Iterator};
use core::marker::{Unpin, Unsize};
use core::mem;
use core::mem::{self, Layout};
use core::ops::{
CoerceUnsized, Deref, DerefMut, DispatchFromDyn, Generator, GeneratorState, Receiver,
};
Expand Down Expand Up @@ -194,7 +194,7 @@ impl<T> Box<T> {
/// ```
#[unstable(feature = "new_uninit", issue = "63291")]
pub fn new_uninit() -> Box<mem::MaybeUninit<T>> {
let layout = alloc::Layout::new::<mem::MaybeUninit<T>>();
let layout = Layout::new::<mem::MaybeUninit<T>>();
let ptr = Global
.alloc(layout, AllocInit::Uninitialized)
.unwrap_or_else(|_| alloc::handle_alloc_error(layout))
Expand Down Expand Up @@ -223,7 +223,7 @@ impl<T> Box<T> {
/// [zeroed]: ../../std/mem/union.MaybeUninit.html#method.zeroed
#[unstable(feature = "new_uninit", issue = "63291")]
pub fn new_zeroed() -> Box<mem::MaybeUninit<T>> {
let layout = alloc::Layout::new::<mem::MaybeUninit<T>>();
let layout = Layout::new::<mem::MaybeUninit<T>>();
let ptr = Global
.alloc(layout, AllocInit::Zeroed)
.unwrap_or_else(|_| alloc::handle_alloc_error(layout))
Expand Down Expand Up @@ -377,7 +377,8 @@ impl<T: ?Sized> Box<T> {
/// ```
/// Manually create a `Box` from scratch by using the global allocator:
/// ```
/// use std::alloc::{alloc, Layout};
/// use std::alloc::alloc;
/// use std::mem::Layout;
///
/// unsafe {
/// let ptr = alloc(Layout::new::<i32>()) as *mut i32;
Expand All @@ -387,7 +388,7 @@ impl<T: ?Sized> Box<T> {
/// ```
///
/// [memory layout]: index.html#memory-layout
/// [`Layout`]: ../alloc/struct.Layout.html
/// [`Layout`]: core::mem::Layout
/// [`Box::into_raw`]: struct.Box.html#method.into_raw
#[stable(feature = "box_raw", since = "1.4.0")]
#[inline]
Expand Down Expand Up @@ -422,7 +423,8 @@ impl<T: ?Sized> Box<T> {
/// Manual cleanup by explicitly running the destructor and deallocating
/// the memory:
/// ```
/// use std::alloc::{dealloc, Layout};
/// use std::alloc::dealloc;
/// use std::mem::Layout;
/// use std::ptr;
///
/// let x = Box::new(String::from("Hello"));
Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/collections/btree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@

use core::cmp::Ordering;
use core::marker::PhantomData;
use core::mem::{self, MaybeUninit};
use core::mem::{self, Layout, MaybeUninit};
use core::ptr::{self, NonNull, Unique};
use core::slice;

use crate::alloc::{AllocRef, Global, Layout};
use crate::alloc::{AllocRef, Global};
use crate::boxed::Box;

const B: usize = 6;
Expand Down
6 changes: 3 additions & 3 deletions src/liballoc/collections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ pub use linked_list::LinkedList;
#[doc(no_inline)]
pub use vec_deque::VecDeque;

use crate::alloc::{Layout, LayoutErr};
use core::fmt::Display;
use core::mem::{Layout, LayoutError};

/// The error type for `try_reserve` methods.
#[derive(Clone, PartialEq, Eq, Debug)]
Expand Down Expand Up @@ -71,9 +71,9 @@ pub enum TryReserveError {
}

#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
impl From<LayoutErr> for TryReserveError {
impl From<LayoutError> for TryReserveError {
#[inline]
fn from(_: LayoutErr) -> Self {
fn from(_: LayoutError) -> Self {
TryReserveError::CapacityOverflow
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

use core::alloc::MemoryBlock;
use core::cmp;
use core::mem::{self, ManuallyDrop, MaybeUninit};
use core::mem::{self, Layout, ManuallyDrop, MaybeUninit};
use core::ops::Drop;
use core::ptr::{NonNull, Unique};
use core::slice;

use crate::alloc::{
handle_alloc_error, AllocErr,
AllocInit::{self, *},
AllocRef, Global, Layout,
AllocRef, Global,
ReallocPlacement::{self, *},
};
use crate::boxed::Box;
Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,13 @@ use core::hash::{Hash, Hasher};
use core::intrinsics::abort;
use core::iter;
use core::marker::{self, PhantomData, Unpin, Unsize};
use core::mem::{self, align_of, align_of_val, forget, size_of_val};
use core::mem::{self, align_of, align_of_val, forget, size_of_val, Layout};
use core::ops::{CoerceUnsized, Deref, DispatchFromDyn, Receiver};
use core::pin::Pin;
use core::ptr::{self, NonNull};
use core::slice::{self, from_raw_parts_mut};

use crate::alloc::{box_free, handle_alloc_error, AllocInit, AllocRef, Global, Layout};
use crate::alloc::{box_free, handle_alloc_error, AllocInit, AllocRef, Global};
use crate::string::String;
use crate::vec::Vec;

Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ use core::hash::{Hash, Hasher};
use core::intrinsics::abort;
use core::iter;
use core::marker::{PhantomData, Unpin, Unsize};
use core::mem::{self, align_of, align_of_val, size_of_val};
use core::mem::{self, align_of, align_of_val, size_of_val, Layout};
use core::ops::{CoerceUnsized, Deref, DispatchFromDyn, Receiver};
use core::pin::Pin;
use core::ptr::{self, NonNull};
use core::slice::{self, from_raw_parts_mut};
use core::sync::atomic;
use core::sync::atomic::Ordering::{Acquire, Relaxed, Release, SeqCst};

use crate::alloc::{box_free, handle_alloc_error, AllocInit, AllocRef, Global, Layout};
use crate::alloc::{box_free, handle_alloc_error, AllocInit, AllocRef, Global};
use crate::boxed::Box;
use crate::rc::is_dangling;
use crate::string::String;
Expand Down
3 changes: 2 additions & 1 deletion src/liballoc/tests/heap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::alloc::{AllocInit, AllocRef, Global, Layout, System};
use std::alloc::{AllocInit, AllocRef, Global, System};
use std::mem::Layout;

/// Issue #45955 and #62251.
#[test]
Expand Down
5 changes: 3 additions & 2 deletions src/libcore/alloc/global.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::alloc::Layout;
use crate::cmp;
use crate::mem::Layout;
use crate::ptr;

/// A memory allocator that can be registered as the standard library’s default
Expand All @@ -21,7 +21,8 @@ use crate::ptr;
/// # Example
///
/// ```no_run
/// use std::alloc::{GlobalAlloc, Layout, alloc};
/// use std::alloc::{GlobalAlloc, alloc};
/// use std::mem::Layout;
/// use std::ptr::null_mut;
///
/// struct MyAllocator;
Expand Down
21 changes: 19 additions & 2 deletions src/libcore/alloc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,29 @@
#![stable(feature = "alloc_module", since = "1.28.0")]

mod global;
mod layout;

#[stable(feature = "global_alloc", since = "1.28.0")]
pub use self::global::GlobalAlloc;

#[stable(feature = "alloc_layout", since = "1.28.0")]
pub use self::layout::{Layout, LayoutErr};
#[doc(no_inline)]
/// **This alias is soft-deprecated.**
///
/// Although using it won’t cause compilation warning, new code should use [`mem::Layout`] directly
/// instead.
///
/// [`mem::Layout`]: crate::mem::Layout
pub use crate::mem::Layout;

#[stable(feature = "alloc_layout", since = "1.28.0")]
#[doc(no_inline)]
/// **This alias is soft-deprecated.**
///
/// Although using it won’t cause compilation warning, new code should use [`mem::LayoutError`]
/// directly instead.
///
/// [`mem::LayoutError`]: crate::mem::LayoutError
pub use crate::mem::LayoutError as LayoutErr;

use crate::fmt;
use crate::ptr::{self, NonNull};
Expand Down
Loading