Rollup merge of #94991 - CAD97:const-weak-new, r=dtolnay
Make Weak::new const Simple enough. This is const creation of an allocating container, but no actual allocation is done, because it's defined to.
This commit is contained in:
commit
6a73024661
@ -2112,9 +2112,10 @@ impl<T> Weak<T> {
|
||||
/// assert!(empty.upgrade().is_none());
|
||||
/// ```
|
||||
#[stable(feature = "downgraded_weak", since = "1.10.0")]
|
||||
#[rustc_const_unstable(feature = "const_weak_new", issue = "95091", reason = "recently added")]
|
||||
#[must_use]
|
||||
pub fn new() -> Weak<T> {
|
||||
Weak { ptr: NonNull::new(usize::MAX as *mut RcBox<T>).expect("MAX is not 0") }
|
||||
pub const fn new() -> Weak<T> {
|
||||
Weak { ptr: unsafe { NonNull::new_unchecked(usize::MAX as *mut RcBox<T>) } }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1742,9 +1742,10 @@ impl<T> Weak<T> {
|
||||
/// assert!(empty.upgrade().is_none());
|
||||
/// ```
|
||||
#[stable(feature = "downgraded_weak", since = "1.10.0")]
|
||||
#[rustc_const_unstable(feature = "const_weak_new", issue = "95091", reason = "recently added")]
|
||||
#[must_use]
|
||||
pub fn new() -> Weak<T> {
|
||||
Weak { ptr: NonNull::new(usize::MAX as *mut ArcInner<T>).expect("MAX is not 0") }
|
||||
pub const fn new() -> Weak<T> {
|
||||
Weak { ptr: unsafe { NonNull::new_unchecked(usize::MAX as *mut ArcInner<T>) } }
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user