Skip to content

Commit b4a8689

Browse files
committed
rust: alloc: disable several new()s, pin()s, default()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. Suggested-by: Gary Guo <[email protected]> Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 38a10b4 commit b4a8689

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

rust/alloc/rc.rs

+6
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ use core::marker::{self, PhantomData, Unpin, Unsize};
264264
use core::mem::size_of_val;
265265
use core::mem::{self, align_of_val_raw, forget};
266266
use core::ops::{CoerceUnsized, Deref, DispatchFromDyn, Receiver};
267+
#[cfg(not(no_global_oom_handling))]
267268
use core::pin::Pin;
268269
use core::ptr::{self, NonNull};
269270
#[cfg(not(no_global_oom_handling))]
@@ -348,6 +349,7 @@ impl<T> Rc<T> {
348349
///
349350
/// let five = Rc::new(5);
350351
/// ```
352+
#[cfg(not(no_global_oom_handling))]
351353
#[stable(feature = "rust1", since = "1.0.0")]
352354
pub fn new(value: T) -> Rc<T> {
353355
// There is an implicit weak pointer owned by all the strong
@@ -383,6 +385,7 @@ impl<T> Rc<T> {
383385
/// }
384386
/// }
385387
/// ```
388+
#[cfg(not(no_global_oom_handling))]
386389
#[unstable(feature = "arc_new_cyclic", issue = "75861")]
387390
pub fn new_cyclic(data_fn: impl FnOnce(&Weak<T>) -> T) -> Rc<T> {
388391
// Construct the inner in the "uninitialized" state with a single
@@ -579,6 +582,7 @@ impl<T> Rc<T> {
579582
}
580583
/// Constructs a new `Pin<Rc<T>>`. If `T` does not implement `Unpin`, then
581584
/// `value` will be pinned in memory and unable to be moved.
585+
#[cfg(not(no_global_oom_handling))]
582586
#[stable(feature = "pin", since = "1.33.0")]
583587
pub fn pin(value: T) -> Pin<Rc<T>> {
584588
unsafe { Pin::new_unchecked(Rc::new(value)) }
@@ -1475,6 +1479,7 @@ impl<T: ?Sized> Clone for Rc<T> {
14751479
}
14761480
}
14771481

1482+
#[cfg(not(no_global_oom_handling))]
14781483
#[stable(feature = "rust1", since = "1.0.0")]
14791484
impl<T: Default> Default for Rc<T> {
14801485
/// Creates a new `Rc<T>`, with the `Default` value for `T`.
@@ -1733,6 +1738,7 @@ impl<T: ?Sized> fmt::Pointer for Rc<T> {
17331738
}
17341739
}
17351740

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

rust/alloc/sync.rs

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use core::marker::{PhantomData, Unpin, Unsize};
2121
use core::mem::size_of_val;
2222
use core::mem::{self, align_of_val_raw};
2323
use core::ops::{CoerceUnsized, Deref, DispatchFromDyn, Receiver};
24+
#[cfg(not(no_global_oom_handling))]
2425
use core::pin::Pin;
2526
use core::ptr::{self, NonNull};
2627
#[cfg(not(no_global_oom_handling))]
@@ -334,6 +335,7 @@ impl<T> Arc<T> {
334335
///
335336
/// let five = Arc::new(5);
336337
/// ```
338+
#[cfg(not(no_global_oom_handling))]
337339
#[inline]
338340
#[stable(feature = "rust1", since = "1.0.0")]
339341
pub fn new(data: T) -> Arc<T> {
@@ -367,6 +369,7 @@ impl<T> Arc<T> {
367369
/// me: me.clone(),
368370
/// });
369371
/// ```
372+
#[cfg(not(no_global_oom_handling))]
370373
#[inline]
371374
#[unstable(feature = "arc_new_cyclic", issue = "75861")]
372375
pub fn new_cyclic(data_fn: impl FnOnce(&Weak<T>) -> T) -> Arc<T> {
@@ -487,6 +490,7 @@ impl<T> Arc<T> {
487490

488491
/// Constructs a new `Pin<Arc<T>>`. If `T` does not implement `Unpin`, then
489492
/// `data` will be pinned in memory and unable to be moved.
493+
#[cfg(not(no_global_oom_handling))]
490494
#[stable(feature = "pin", since = "1.33.0")]
491495
pub fn pin(data: T) -> Pin<Arc<T>> {
492496
unsafe { Pin::new_unchecked(Arc::new(data)) }
@@ -2276,6 +2280,7 @@ impl<T: ?Sized> fmt::Pointer for Arc<T> {
22762280
}
22772281
}
22782282

2283+
#[cfg(not(no_global_oom_handling))]
22792284
#[stable(feature = "rust1", since = "1.0.0")]
22802285
impl<T: Default> Default for Arc<T> {
22812286
/// Creates a new `Arc<T>`, with the `Default` value for `T`.
@@ -2300,6 +2305,7 @@ impl<T: ?Sized + Hash> Hash for Arc<T> {
23002305
}
23012306
}
23022307

2308+
#[cfg(not(no_global_oom_handling))]
23032309
#[stable(feature = "from_for_ptrs", since = "1.6.0")]
23042310
impl<T> From<T> for Arc<T> {
23052311
fn from(t: T) -> Self {

0 commit comments

Comments
 (0)