Skip to content

Commit a358ad2

Browse files
committedMar 18, 2022
Make Weak::new const
1 parent af446e1 commit a358ad2

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed
 

‎library/alloc/src/rc.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2112,9 +2112,10 @@ impl<T> Weak<T> {
21122112
/// assert!(empty.upgrade().is_none());
21132113
/// ```
21142114
#[stable(feature = "downgraded_weak", since = "1.10.0")]
2115+
#[rustc_const_unstable(feature = "const_weak_new", issue = "95091", reason = "recently added")]
21152116
#[must_use]
2116-
pub fn new() -> Weak<T> {
2117-
Weak { ptr: NonNull::new(usize::MAX as *mut RcBox<T>).expect("MAX is not 0") }
2117+
pub const fn new() -> Weak<T> {
2118+
Weak { ptr: unsafe { NonNull::new_unchecked(usize::MAX as *mut RcBox<T>) } }
21182119
}
21192120
}
21202121

‎library/alloc/src/sync.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1742,9 +1742,10 @@ impl<T> Weak<T> {
17421742
/// assert!(empty.upgrade().is_none());
17431743
/// ```
17441744
#[stable(feature = "downgraded_weak", since = "1.10.0")]
1745+
#[rustc_const_unstable(feature = "const_weak_new", issue = "95091", reason = "recently added")]
17451746
#[must_use]
1746-
pub fn new() -> Weak<T> {
1747-
Weak { ptr: NonNull::new(usize::MAX as *mut ArcInner<T>).expect("MAX is not 0") }
1747+
pub const fn new() -> Weak<T> {
1748+
Weak { ptr: unsafe { NonNull::new_unchecked(usize::MAX as *mut ArcInner<T>) } }
17481749
}
17491750
}
17501751

0 commit comments

Comments
 (0)
Please sign in to comment.