Skip to content

Commit 8649737

Browse files
committed
Auto merge of #86810 - ojeda:alloc-gate, r=dtolnay
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: Rust-for-Linux/linux#402 Suggested-by: Gary Guo <gary@garyguo.net> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2 parents a8b8558 + 7775dff commit 8649737

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

library/alloc/src/rc.rs

+6
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ use core::marker::{self, PhantomData, Unpin, Unsize};
262262
use core::mem::size_of_val;
263263
use core::mem::{self, align_of_val_raw, forget};
264264
use core::ops::{CoerceUnsized, Deref, DispatchFromDyn, Receiver};
265+
#[cfg(not(no_global_oom_handling))]
265266
use core::pin::Pin;
266267
use core::ptr::{self, NonNull};
267268
#[cfg(not(no_global_oom_handling))]
@@ -346,6 +347,7 @@ impl<T> Rc<T> {
346347
///
347348
/// let five = Rc::new(5);
348349
/// ```
350+
#[cfg(not(no_global_oom_handling))]
349351
#[stable(feature = "rust1", since = "1.0.0")]
350352
pub fn new(value: T) -> Rc<T> {
351353
// There is an implicit weak pointer owned by all the strong
@@ -381,6 +383,7 @@ impl<T> Rc<T> {
381383
/// }
382384
/// }
383385
/// ```
386+
#[cfg(not(no_global_oom_handling))]
384387
#[unstable(feature = "arc_new_cyclic", issue = "75861")]
385388
pub fn new_cyclic(data_fn: impl FnOnce(&Weak<T>) -> T) -> Rc<T> {
386389
// Construct the inner in the "uninitialized" state with a single
@@ -577,6 +580,7 @@ impl<T> Rc<T> {
577580
}
578581
/// Constructs a new `Pin<Rc<T>>`. If `T` does not implement `Unpin`, then
579582
/// `value` will be pinned in memory and unable to be moved.
583+
#[cfg(not(no_global_oom_handling))]
580584
#[stable(feature = "pin", since = "1.33.0")]
581585
pub fn pin(value: T) -> Pin<Rc<T>> {
582586
unsafe { Pin::new_unchecked(Rc::new(value)) }
@@ -1473,6 +1477,7 @@ impl<T: ?Sized> Clone for Rc<T> {
14731477
}
14741478
}
14751479

1480+
#[cfg(not(no_global_oom_handling))]
14761481
#[stable(feature = "rust1", since = "1.0.0")]
14771482
impl<T: Default> Default for Rc<T> {
14781483
/// Creates a new `Rc<T>`, with the `Default` value for `T`.
@@ -1731,6 +1736,7 @@ impl<T: ?Sized> fmt::Pointer for Rc<T> {
17311736
}
17321737
}
17331738

1739+
#[cfg(not(no_global_oom_handling))]
17341740
#[stable(feature = "from_for_ptrs", since = "1.6.0")]
17351741
impl<T> From<T> for Rc<T> {
17361742
/// Converts a generic type `T` into a `Rc<T>`

library/alloc/src/sync.rs

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use core::marker::{PhantomData, Unpin, Unsize};
1919
use core::mem::size_of_val;
2020
use core::mem::{self, align_of_val_raw};
2121
use core::ops::{CoerceUnsized, Deref, DispatchFromDyn, Receiver};
22+
#[cfg(not(no_global_oom_handling))]
2223
use core::pin::Pin;
2324
use core::ptr::{self, NonNull};
2425
#[cfg(not(no_global_oom_handling))]
@@ -332,6 +333,7 @@ impl<T> Arc<T> {
332333
///
333334
/// let five = Arc::new(5);
334335
/// ```
336+
#[cfg(not(no_global_oom_handling))]
335337
#[inline]
336338
#[stable(feature = "rust1", since = "1.0.0")]
337339
pub fn new(data: T) -> Arc<T> {
@@ -365,6 +367,7 @@ impl<T> Arc<T> {
365367
/// me: me.clone(),
366368
/// });
367369
/// ```
370+
#[cfg(not(no_global_oom_handling))]
368371
#[inline]
369372
#[unstable(feature = "arc_new_cyclic", issue = "75861")]
370373
pub fn new_cyclic(data_fn: impl FnOnce(&Weak<T>) -> T) -> Arc<T> {
@@ -485,6 +488,7 @@ impl<T> Arc<T> {
485488

486489
/// Constructs a new `Pin<Arc<T>>`. If `T` does not implement `Unpin`, then
487490
/// `data` will be pinned in memory and unable to be moved.
491+
#[cfg(not(no_global_oom_handling))]
488492
#[stable(feature = "pin", since = "1.33.0")]
489493
pub fn pin(data: T) -> Pin<Arc<T>> {
490494
unsafe { Pin::new_unchecked(Arc::new(data)) }
@@ -2274,6 +2278,7 @@ impl<T: ?Sized> fmt::Pointer for Arc<T> {
22742278
}
22752279
}
22762280

2281+
#[cfg(not(no_global_oom_handling))]
22772282
#[stable(feature = "rust1", since = "1.0.0")]
22782283
impl<T: Default> Default for Arc<T> {
22792284
/// Creates a new `Arc<T>`, with the `Default` value for `T`.
@@ -2298,6 +2303,7 @@ impl<T: ?Sized + Hash> Hash for Arc<T> {
22982303
}
22992304
}
23002305

2306+
#[cfg(not(no_global_oom_handling))]
23012307
#[stable(feature = "from_for_ptrs", since = "1.6.0")]
23022308
impl<T> From<T> for Arc<T> {
23032309
/// Converts a `T` into an `Arc<T>`

0 commit comments

Comments
 (0)