From 7775dffbc052f66ef80cad3c5ddc4f7e71585959 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Fri, 2 Jul 2021 14:55:20 +0200 Subject: [PATCH] alloc: `no_global_oom_handling`: disable `new()`s, `pin()`s, etc. They are infallible, and could not be actually used because they will trigger an error when monomorphized, but it is better to just remove them. Link: https://github.com/Rust-for-Linux/linux/pull/402 Suggested-by: Gary Guo Signed-off-by: Miguel Ojeda --- library/alloc/src/rc.rs | 6 ++++++ library/alloc/src/sync.rs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index f131182a89633..e116ab6483c9b 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -262,6 +262,7 @@ use core::marker::{self, PhantomData, Unpin, Unsize}; use core::mem::size_of_val; use core::mem::{self, align_of_val_raw, forget}; use core::ops::{CoerceUnsized, Deref, DispatchFromDyn, Receiver}; +#[cfg(not(no_global_oom_handling))] use core::pin::Pin; use core::ptr::{self, NonNull}; #[cfg(not(no_global_oom_handling))] @@ -346,6 +347,7 @@ impl Rc { /// /// let five = Rc::new(5); /// ``` + #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] pub fn new(value: T) -> Rc { // There is an implicit weak pointer owned by all the strong @@ -381,6 +383,7 @@ impl Rc { /// } /// } /// ``` + #[cfg(not(no_global_oom_handling))] #[unstable(feature = "arc_new_cyclic", issue = "75861")] pub fn new_cyclic(data_fn: impl FnOnce(&Weak) -> T) -> Rc { // Construct the inner in the "uninitialized" state with a single @@ -577,6 +580,7 @@ impl Rc { } /// Constructs a new `Pin>`. If `T` does not implement `Unpin`, then /// `value` will be pinned in memory and unable to be moved. + #[cfg(not(no_global_oom_handling))] #[stable(feature = "pin", since = "1.33.0")] pub fn pin(value: T) -> Pin> { unsafe { Pin::new_unchecked(Rc::new(value)) } @@ -1473,6 +1477,7 @@ impl Clone for Rc { } } +#[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] impl Default for Rc { /// Creates a new `Rc`, with the `Default` value for `T`. @@ -1731,6 +1736,7 @@ impl fmt::Pointer for Rc { } } +#[cfg(not(no_global_oom_handling))] #[stable(feature = "from_for_ptrs", since = "1.6.0")] impl From for Rc { /// Converts a generic type `T` into a `Rc` diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 742a9d7ba0187..4b34a7dc894ae 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -19,6 +19,7 @@ use core::marker::{PhantomData, Unpin, Unsize}; use core::mem::size_of_val; use core::mem::{self, align_of_val_raw}; use core::ops::{CoerceUnsized, Deref, DispatchFromDyn, Receiver}; +#[cfg(not(no_global_oom_handling))] use core::pin::Pin; use core::ptr::{self, NonNull}; #[cfg(not(no_global_oom_handling))] @@ -332,6 +333,7 @@ impl Arc { /// /// let five = Arc::new(5); /// ``` + #[cfg(not(no_global_oom_handling))] #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn new(data: T) -> Arc { @@ -365,6 +367,7 @@ impl Arc { /// me: me.clone(), /// }); /// ``` + #[cfg(not(no_global_oom_handling))] #[inline] #[unstable(feature = "arc_new_cyclic", issue = "75861")] pub fn new_cyclic(data_fn: impl FnOnce(&Weak) -> T) -> Arc { @@ -485,6 +488,7 @@ impl Arc { /// Constructs a new `Pin>`. If `T` does not implement `Unpin`, then /// `data` will be pinned in memory and unable to be moved. + #[cfg(not(no_global_oom_handling))] #[stable(feature = "pin", since = "1.33.0")] pub fn pin(data: T) -> Pin> { unsafe { Pin::new_unchecked(Arc::new(data)) } @@ -2274,6 +2278,7 @@ impl fmt::Pointer for Arc { } } +#[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] impl Default for Arc { /// Creates a new `Arc`, with the `Default` value for `T`. @@ -2298,6 +2303,7 @@ impl Hash for Arc { } } +#[cfg(not(no_global_oom_handling))] #[stable(feature = "from_for_ptrs", since = "1.6.0")] impl From for Arc { /// Converts a `T` into an `Arc`