Skip to content

Commit

Permalink
Make {Mutex, Condvar, RwLock}::new() const.
Browse files Browse the repository at this point in the history
  • Loading branch information
m-ou-se committed Jun 6, 2022
1 parent acc3ab4 commit edae495
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions library/std/src/sync/condvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ impl<T> Mutex<T> {
/// 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<T> {
Mutex {
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sync/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ impl<T> RwLock<T> {
/// 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<T> {
RwLock {
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys_common/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys_common/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down

0 comments on commit edae495

Please sign in to comment.