diff options
| author | CAD97 <cad97@cad97.com> | 2022-03-15 23:58:18 -0500 |
|---|---|---|
| committer | CAD97 <cad97@cad97.com> | 2022-03-18 17:47:36 -0500 |
| commit | a358ad2aff788bf21cf9c17662da7e962d75fc83 (patch) | |
| tree | 8ff404923dc2a9c3812038522ed036a705074b99 | |
| parent | af446e1d7086d4aeed495f6b03e70009e9424ce4 (diff) | |
| download | rust-a358ad2aff788bf21cf9c17662da7e962d75fc83.tar.gz rust-a358ad2aff788bf21cf9c17662da7e962d75fc83.zip | |
Make Weak::new const
| -rw-r--r-- | library/alloc/src/rc.rs | 5 | ||||
| -rw-r--r-- | library/alloc/src/sync.rs | 5 |
2 files changed, 6 insertions, 4 deletions
diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 3065169e5e2..ea651c075d9 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -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>) } } } } diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 2140c3f168d..ba3187294e6 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -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>) } } } } |
