Add #[must_use] to alloc constructors
This commit is contained in:
parent
6928fafe06
commit
58cc18c56b
12 changed files with 40 additions and 2 deletions
|
@ -452,6 +452,7 @@ impl<T> Rc<T> {
|
|||
/// ```
|
||||
#[cfg(not(no_global_oom_handling))]
|
||||
#[unstable(feature = "new_uninit", issue = "63291")]
|
||||
#[must_use]
|
||||
pub fn new_uninit() -> Rc<mem::MaybeUninit<T>> {
|
||||
unsafe {
|
||||
Rc::from_ptr(Rc::allocate_for_layout(
|
||||
|
@ -484,6 +485,7 @@ impl<T> Rc<T> {
|
|||
/// [zeroed]: mem::MaybeUninit::zeroed
|
||||
#[cfg(not(no_global_oom_handling))]
|
||||
#[unstable(feature = "new_uninit", issue = "63291")]
|
||||
#[must_use]
|
||||
pub fn new_zeroed() -> Rc<mem::MaybeUninit<T>> {
|
||||
unsafe {
|
||||
Rc::from_ptr(Rc::allocate_for_layout(
|
||||
|
@ -587,6 +589,7 @@ impl<T> Rc<T> {
|
|||
/// `value` will be pinned in memory and unable to be moved.
|
||||
#[cfg(not(no_global_oom_handling))]
|
||||
#[stable(feature = "pin", since = "1.33.0")]
|
||||
#[must_use]
|
||||
pub fn pin(value: T) -> Pin<Rc<T>> {
|
||||
unsafe { Pin::new_unchecked(Rc::new(value)) }
|
||||
}
|
||||
|
@ -658,6 +661,7 @@ impl<T> Rc<[T]> {
|
|||
/// ```
|
||||
#[cfg(not(no_global_oom_handling))]
|
||||
#[unstable(feature = "new_uninit", issue = "63291")]
|
||||
#[must_use]
|
||||
pub fn new_uninit_slice(len: usize) -> Rc<[mem::MaybeUninit<T>]> {
|
||||
unsafe { Rc::from_ptr(Rc::allocate_for_slice(len)) }
|
||||
}
|
||||
|
@ -684,6 +688,7 @@ impl<T> Rc<[T]> {
|
|||
/// [zeroed]: mem::MaybeUninit::zeroed
|
||||
#[cfg(not(no_global_oom_handling))]
|
||||
#[unstable(feature = "new_uninit", issue = "63291")]
|
||||
#[must_use]
|
||||
pub fn new_zeroed_slice(len: usize) -> Rc<[mem::MaybeUninit<T>]> {
|
||||
unsafe {
|
||||
Rc::from_ptr(Rc::allocate_for_layout(
|
||||
|
@ -2044,6 +2049,7 @@ impl<T> Weak<T> {
|
|||
/// assert!(empty.upgrade().is_none());
|
||||
/// ```
|
||||
#[stable(feature = "downgraded_weak", since = "1.10.0")]
|
||||
#[must_use]
|
||||
pub fn new() -> Weak<T> {
|
||||
Weak { ptr: NonNull::new(usize::MAX as *mut RcBox<T>).expect("MAX is not 0") }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue