diff --git a/std/src/sync/condvar.rs b/std/src/sync/condvar.rs index 7ff2f330f..eb1e7135a 100644 --- a/std/src/sync/condvar.rs +++ b/std/src/sync/condvar.rs @@ -122,8 +122,10 @@ 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] - pub fn new() -> Condvar { + #[inline] + pub const fn new() -> Condvar { Condvar { inner: sys::Condvar::new() } } diff --git a/std/src/sync/mutex.rs b/std/src/sync/mutex.rs index 31342a890..e0d13cd64 100644 --- a/std/src/sync/mutex.rs +++ b/std/src/sync/mutex.rs @@ -213,7 +213,9 @@ impl Mutex { /// let mutex = Mutex::new(0); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn new(t: T) -> Mutex { + #[rustc_const_stable(feature = "const_locks", since = "1.63.0")] + #[inline] + pub const fn new(t: T) -> Mutex { Mutex { inner: sys::MovableMutex::new(), poison: poison::Flag::new(), diff --git a/std/src/sync/poison.rs b/std/src/sync/poison.rs index 9c918be33..741312d55 100644 --- a/std/src/sync/poison.rs +++ b/std/src/sync/poison.rs @@ -19,6 +19,7 @@ pub struct Flag { // all cases. impl Flag { + #[inline] pub const fn new() -> Flag { Flag { failed: AtomicBool::new(false) } } diff --git a/std/src/sync/rwlock.rs b/std/src/sync/rwlock.rs index 9517e7e1f..1192c08cb 100644 --- a/std/src/sync/rwlock.rs +++ b/std/src/sync/rwlock.rs @@ -146,7 +146,9 @@ impl RwLock { /// let lock = RwLock::new(5); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn new(t: T) -> RwLock { + #[rustc_const_stable(feature = "const_locks", since = "1.63.0")] + #[inline] + pub const fn new(t: T) -> RwLock { RwLock { inner: sys::MovableRwLock::new(), poison: poison::Flag::new(), diff --git a/std/src/sys/itron/mutex.rs b/std/src/sys/itron/mutex.rs index 2ba8454ff..715e94c3b 100644 --- a/std/src/sys/itron/mutex.rs +++ b/std/src/sys/itron/mutex.rs @@ -26,6 +26,7 @@ fn new_mtx() -> Result { } impl Mutex { + #[inline] pub const fn new() -> Mutex { Mutex { mtx: SpinIdOnceCell::new() } } diff --git a/std/src/sys/solid/rwlock.rs b/std/src/sys/solid/rwlock.rs index 433abc895..0a770cf03 100644 --- a/std/src/sys/solid/rwlock.rs +++ b/std/src/sys/solid/rwlock.rs @@ -23,6 +23,7 @@ fn new_rwl() -> Result { } impl RwLock { + #[inline] pub const fn new() -> RwLock { RwLock { rwl: SpinIdOnceCell::new() } } diff --git a/std/src/sys/unsupported/locks/condvar.rs b/std/src/sys/unsupported/locks/condvar.rs index f27bf2b26..e703fd0d2 100644 --- a/std/src/sys/unsupported/locks/condvar.rs +++ b/std/src/sys/unsupported/locks/condvar.rs @@ -6,6 +6,7 @@ pub struct Condvar {} pub type MovableCondvar = Condvar; impl Condvar { + #[inline] pub const fn new() -> Condvar { Condvar {} } diff --git a/std/src/sys/unsupported/locks/mutex.rs b/std/src/sys/unsupported/locks/mutex.rs index 56bad71b1..d7cb12e0c 100644 --- a/std/src/sys/unsupported/locks/mutex.rs +++ b/std/src/sys/unsupported/locks/mutex.rs @@ -11,6 +11,7 @@ unsafe impl Send for Mutex {} unsafe impl Sync for Mutex {} // no threads on this platform impl Mutex { + #[inline] pub const fn new() -> Mutex { Mutex { locked: Cell::new(false) } } diff --git a/std/src/sys/unsupported/locks/rwlock.rs b/std/src/sys/unsupported/locks/rwlock.rs index bf6e2d3d0..aca5fb715 100644 --- a/std/src/sys/unsupported/locks/rwlock.rs +++ b/std/src/sys/unsupported/locks/rwlock.rs @@ -11,6 +11,7 @@ unsafe impl Send for RwLock {} unsafe impl Sync for RwLock {} // no threads on this platform impl RwLock { + #[inline] pub const fn new() -> RwLock { RwLock { mode: Cell::new(0) } } diff --git a/std/src/sys/windows/locks/condvar.rs b/std/src/sys/windows/locks/condvar.rs index 59e2c1be0..be9a2abbe 100644 --- a/std/src/sys/windows/locks/condvar.rs +++ b/std/src/sys/windows/locks/condvar.rs @@ -14,6 +14,7 @@ unsafe impl Send for Condvar {} unsafe impl Sync for Condvar {} impl Condvar { + #[inline] pub const fn new() -> Condvar { Condvar { inner: UnsafeCell::new(c::CONDITION_VARIABLE_INIT) } } diff --git a/std/src/sys/windows/locks/mutex.rs b/std/src/sys/windows/locks/mutex.rs index 08f55844a..f91e8f9f5 100644 --- a/std/src/sys/windows/locks/mutex.rs +++ b/std/src/sys/windows/locks/mutex.rs @@ -33,6 +33,7 @@ pub unsafe fn raw(m: &Mutex) -> c::PSRWLOCK { } impl Mutex { + #[inline] pub const fn new() -> Mutex { Mutex { srwlock: UnsafeCell::new(c::SRWLOCK_INIT) } } diff --git a/std/src/sys/windows/locks/rwlock.rs b/std/src/sys/windows/locks/rwlock.rs index a32df85e2..fa5ffe574 100644 --- a/std/src/sys/windows/locks/rwlock.rs +++ b/std/src/sys/windows/locks/rwlock.rs @@ -11,6 +11,7 @@ unsafe impl Send for RwLock {} unsafe impl Sync for RwLock {} impl RwLock { + #[inline] pub const fn new() -> RwLock { RwLock { inner: UnsafeCell::new(c::SRWLOCK_INIT) } } diff --git a/std/src/sys_common/condvar.rs b/std/src/sys_common/condvar.rs index 1def0518e..f3ac1061b 100644 --- a/std/src/sys_common/condvar.rs +++ b/std/src/sys_common/condvar.rs @@ -14,7 +14,8 @@ pub struct Condvar { impl Condvar { /// Creates a new condition variable for use. - pub fn new() -> Self { + #[inline] + pub const fn new() -> Self { Self { inner: imp::MovableCondvar::new(), check: CondvarCheck::new() } } diff --git a/std/src/sys_common/mutex.rs b/std/src/sys_common/mutex.rs index 36ea888d8..81eefa113 100644 --- a/std/src/sys_common/mutex.rs +++ b/std/src/sys_common/mutex.rs @@ -15,6 +15,7 @@ unsafe impl Sync for StaticMutex {} impl StaticMutex { /// Creates a new mutex for use. + #[inline] pub const fn new() -> Self { Self(imp::Mutex::new()) } @@ -60,7 +61,8 @@ unsafe impl Sync for MovableMutex {} impl MovableMutex { /// Creates a new mutex. - pub fn new() -> Self { + #[inline] + pub const fn new() -> Self { Self(imp::MovableMutex::new()) } diff --git a/std/src/sys_common/rwlock.rs b/std/src/sys_common/rwlock.rs index abc9fd561..265cebfdc 100644 --- a/std/src/sys_common/rwlock.rs +++ b/std/src/sys_common/rwlock.rs @@ -10,6 +10,7 @@ pub struct StaticRwLock(imp::RwLock); impl StaticRwLock { /// Creates a new rwlock for use. + #[inline] pub const fn new() -> Self { Self(imp::RwLock::new()) } @@ -73,7 +74,8 @@ pub struct MovableRwLock(imp::MovableRwLock); impl MovableRwLock { /// Creates a new reader-writer lock for use. - pub fn new() -> Self { + #[inline] + pub const fn new() -> Self { Self(imp::MovableRwLock::new()) }