Skip to content

Commit

Permalink
rust: alloc: disable several new()s, pin()s, default()s, etc.
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ojeda committed Jul 1, 2021
1 parent 38a10b4 commit b4a8689
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rust/alloc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,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))]
Expand Down Expand Up @@ -348,6 +349,7 @@ impl<T> Rc<T> {
///
/// let five = Rc::new(5);
/// ```
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new(value: T) -> Rc<T> {
// There is an implicit weak pointer owned by all the strong
Expand Down Expand Up @@ -383,6 +385,7 @@ impl<T> Rc<T> {
/// }
/// }
/// ```
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "arc_new_cyclic", issue = "75861")]
pub fn new_cyclic(data_fn: impl FnOnce(&Weak<T>) -> T) -> Rc<T> {
// Construct the inner in the "uninitialized" state with a single
Expand Down Expand Up @@ -579,6 +582,7 @@ impl<T> Rc<T> {
}
/// Constructs a new `Pin<Rc<T>>`. 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<Rc<T>> {
unsafe { Pin::new_unchecked(Rc::new(value)) }
Expand Down Expand Up @@ -1475,6 +1479,7 @@ impl<T: ?Sized> Clone for Rc<T> {
}
}

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

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "from_for_ptrs", since = "1.6.0")]
impl<T> From<T> for Rc<T> {
/// Converts a generic type `T` into a `Rc<T>`
Expand Down
6 changes: 6 additions & 0 deletions rust/alloc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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))]
Expand Down Expand Up @@ -334,6 +335,7 @@ impl<T> Arc<T> {
///
/// 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<T> {
Expand Down Expand Up @@ -367,6 +369,7 @@ impl<T> Arc<T> {
/// 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>) -> T) -> Arc<T> {
Expand Down Expand Up @@ -487,6 +490,7 @@ impl<T> Arc<T> {

/// Constructs a new `Pin<Arc<T>>`. 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<Arc<T>> {
unsafe { Pin::new_unchecked(Arc::new(data)) }
Expand Down Expand Up @@ -2276,6 +2280,7 @@ impl<T: ?Sized> fmt::Pointer for Arc<T> {
}
}

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

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

0 comments on commit b4a8689

Please sign in to comment.