Make {Mutex, Condvar, RwLock}::new() const. · rust-lang/rust@edae495 (original) (raw)

5 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -122,6 +122,7 @@ impl Condvar {
122 122 /// let condvar = Condvar::new();
123 123 /// ```
124 124 #[stable(feature = "rust1", since = "1.0.0")]
125 +#[rustc_const_stable(feature = "const_locks", since = "1.63.0")]
125 126 #[must_use]
126 127 #[inline]
127 128 pub const fn new() -> Condvar {
Original file line number Diff line number Diff line change
@@ -214,6 +214,7 @@ impl Mutex {
214 214 /// let mutex = Mutex::new(0);
215 215 /// ```
216 216 #[stable(feature = "rust1", since = "1.0.0")]
217 +#[rustc_const_stable(feature = "const_locks", since = "1.63.0")]
217 218 #[inline]
218 219 pub const fn new(t: T) -> Mutex<T> {
219 220 Mutex {
Original file line number Diff line number Diff line change
@@ -146,6 +146,7 @@ impl RwLock {
146 146 /// let lock = RwLock::new(5);
147 147 /// ```
148 148 #[stable(feature = "rust1", since = "1.0.0")]
149 +#[rustc_const_stable(feature = "const_locks", since = "1.63.0")]
149 150 #[inline]
150 151 pub const fn new(t: T) -> RwLock<T> {
151 152 RwLock {
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ unsafe impl Sync for MovableMutex {}
62 62 impl MovableMutex {
63 63 /// Creates a new mutex.
64 64 #[inline]
65 -pub fn new() -> Self {
65 +pub const fn new() -> Self {
66 66 Self(imp::MovableMutex::new())
67 67 }
68 68
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ pub struct MovableRwLock(imp::MovableRwLock);
75 75 impl MovableRwLock {
76 76 /// Creates a new reader-writer lock for use.
77 77 #[inline]
78 -pub fn new() -> Self {
78 +pub const fn new() -> Self {
79 79 Self(imp::MovableRwLock::new())
80 80 }
81 81