Skip to content

Commit 9031ac4

Browse files
authored
Rollup merge of rust-lang#91806 - woppopo:const_unique, r=dtolnay
Make `Unique`s methods `const` Tracking issue: None
2 parents 9aade50 + 34eaf52 commit 9031ac4

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
#![feature(const_option)]
125125
#![feature(const_pin)]
126126
#![feature(const_replace)]
127+
#![feature(const_ptr_is_null)]
127128
#![feature(const_ptr_offset)]
128129
#![feature(const_ptr_offset_from)]
129130
#![feature(const_ptr_read)]

library/core/src/ptr/unique.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<T: ?Sized> Unique<T> {
9292

9393
/// Creates a new `Unique` if `ptr` is non-null.
9494
#[inline]
95-
pub fn new(ptr: *mut T) -> Option<Self> {
95+
pub const fn new(ptr: *mut T) -> Option<Self> {
9696
if !ptr.is_null() {
9797
// SAFETY: The pointer has already been checked and is not null.
9898
Some(unsafe { Unique { pointer: ptr as _, _marker: PhantomData } })
@@ -115,7 +115,7 @@ impl<T: ?Sized> Unique<T> {
115115
/// (unbound) lifetime is needed, use `&*my_ptr.as_ptr()`.
116116
#[must_use]
117117
#[inline]
118-
pub unsafe fn as_ref(&self) -> &T {
118+
pub const unsafe fn as_ref(&self) -> &T {
119119
// SAFETY: the caller must guarantee that `self` meets all the
120120
// requirements for a reference.
121121
unsafe { &*self.as_ptr() }
@@ -128,7 +128,7 @@ impl<T: ?Sized> Unique<T> {
128128
/// (unbound) lifetime is needed, use `&mut *my_ptr.as_ptr()`.
129129
#[must_use]
130130
#[inline]
131-
pub unsafe fn as_mut(&mut self) -> &mut T {
131+
pub const unsafe fn as_mut(&mut self) -> &mut T {
132132
// SAFETY: the caller must guarantee that `self` meets all the
133133
// requirements for a mutable reference.
134134
unsafe { &mut *self.as_ptr() }

0 commit comments

Comments
 (0)