From edae4958556a6150841b9964b322d1e96e7a4586 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 6 Jun 2022 13:55:43 +0200 Subject: [PATCH] Make {Mutex, Condvar, RwLock}::new() const. --- library/std/src/sync/condvar.rs | 1 + library/std/src/sync/mutex.rs | 1 + library/std/src/sync/rwlock.rs | 1 + library/std/src/sys_common/mutex.rs | 2 +- library/std/src/sys_common/rwlock.rs | 2 +- 5 files changed, 5 insertions(+), 2 deletions(-) diff --git a/library/std/src/sync/condvar.rs b/library/std/src/sync/condvar.rs index a1d7b6ff06174..eb1e7135a6e41 100644 --- a/library/std/src/sync/condvar.rs +++ b/library/std/src/sync/condvar.rs @@ -122,6 +122,7 @@ impl Condvar { /// let condvar = Condvar::new(); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_locks", since = "1.63.0")] #[must_use] #[inline] pub const fn new() -> Condvar { diff --git a/library/std/src/sync/mutex.rs b/library/std/src/sync/mutex.rs index d63f81e68c815..37d4454534d17 100644 --- a/library/std/src/sync/mutex.rs +++ b/library/std/src/sync/mutex.rs @@ -214,6 +214,7 @@ impl Mutex { /// let mutex = Mutex::new(0); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_locks", since = "1.63.0")] #[inline] pub const fn new(t: T) -> Mutex { Mutex { diff --git a/library/std/src/sync/rwlock.rs b/library/std/src/sync/rwlock.rs index ce62c022ae08b..9fee42e236215 100644 --- a/library/std/src/sync/rwlock.rs +++ b/library/std/src/sync/rwlock.rs @@ -146,6 +146,7 @@ impl RwLock { /// let lock = RwLock::new(5); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_locks", since = "1.63.0")] #[inline] pub const fn new(t: T) -> RwLock { RwLock { diff --git a/library/std/src/sys_common/mutex.rs b/library/std/src/sys_common/mutex.rs index daba9c3f2b69c..81eefa1133fa5 100644 --- a/library/std/src/sys_common/mutex.rs +++ b/library/std/src/sys_common/mutex.rs @@ -62,7 +62,7 @@ unsafe impl Sync for MovableMutex {} impl MovableMutex { /// Creates a new mutex. #[inline] - pub fn new() -> Self { + pub const fn new() -> Self { Self(imp::MovableMutex::new()) } diff --git a/library/std/src/sys_common/rwlock.rs b/library/std/src/sys_common/rwlock.rs index b455074709288..265cebfdc3e0a 100644 --- a/library/std/src/sys_common/rwlock.rs +++ b/library/std/src/sys_common/rwlock.rs @@ -75,7 +75,7 @@ pub struct MovableRwLock(imp::MovableRwLock); impl MovableRwLock { /// Creates a new reader-writer lock for use. #[inline] - pub fn new() -> Self { + pub const fn new() -> Self { Self(imp::MovableRwLock::new()) }