Skip to content

Commit 5ff0f08

Browse files
committed
Make {Mutex, Notify, OnceCell, RwLock, Semaphore}::const_new always available
Since MSRV is bumped to 1.63, `Mutex::new` is now usable in const context. Signed-off-by: Jiahao XU <[email protected]>
1 parent c445e46 commit 5ff0f08

File tree

7 files changed

+6
-13
lines changed

7 files changed

+6
-13
lines changed

tokio/src/loom/std/mutex.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ impl<T> Mutex<T> {
1313
}
1414

1515
#[inline]
16-
#[cfg(not(tokio_no_const_mutex_new))]
1716
pub(crate) const fn const_new(t: T) -> Mutex<T> {
1817
Mutex(sync::Mutex::new(t))
1918
}

tokio/src/sync/batch_semaphore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl Semaphore {
181181
///
182182
/// If the specified number of permits exceeds the maximum permit amount
183183
/// Then the value will get clamped to the maximum number of permits.
184-
#[cfg(all(feature = "parking_lot", not(all(loom, test))))]
184+
#[cfg(not(all(loom, test)))]
185185
pub(crate) const fn const_new(mut permits: usize) -> Self {
186186
// NOTE: assertions and by extension panics are still being worked on: https://github.com/rust-lang/rust/issues/74925
187187
// currently we just clamp the permit count when it exceeds the max

tokio/src/sync/mutex.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,7 @@ impl<T: ?Sized> Mutex<T> {
378378
///
379379
/// static LOCK: Mutex<i32> = Mutex::const_new(5);
380380
/// ```
381-
#[cfg(all(feature = "parking_lot", not(all(loom, test)),))]
382-
#[cfg_attr(docsrs, doc(cfg(feature = "parking_lot")))]
381+
#[cfg(not(all(loom, test)))]
383382
pub const fn const_new(t: T) -> Self
384383
where
385384
T: Sized,

tokio/src/sync/notify.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,7 @@ impl Notify {
443443
///
444444
/// static NOTIFY: Notify = Notify::const_new();
445445
/// ```
446-
#[cfg(all(feature = "parking_lot", not(all(loom, test))))]
447-
#[cfg_attr(docsrs, doc(cfg(feature = "parking_lot")))]
446+
#[cfg(not(all(loom, test)))]
448447
pub const fn const_new() -> Notify {
449448
Notify {
450449
state: AtomicUsize::new(0),

tokio/src/sync/once_cell.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ impl<T> OnceCell<T> {
171171
/// assert_eq!(*result, 2);
172172
/// }
173173
/// ```
174-
#[cfg(all(feature = "parking_lot", not(all(loom, test))))]
175-
#[cfg_attr(docsrs, doc(cfg(feature = "parking_lot")))]
174+
#[cfg(not(all(loom, test)))]
176175
pub const fn const_new() -> Self {
177176
OnceCell {
178177
value_set: AtomicBool::new(false),

tokio/src/sync/rwlock.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,7 @@ impl<T: ?Sized> RwLock<T> {
334334
///
335335
/// static LOCK: RwLock<i32> = RwLock::const_new(5);
336336
/// ```
337-
#[cfg(all(feature = "parking_lot", not(all(loom, test))))]
338-
#[cfg_attr(docsrs, doc(cfg(feature = "parking_lot")))]
337+
#[cfg(not(all(loom, test)))]
339338
pub const fn const_new(value: T) -> RwLock<T>
340339
where
341340
T: Sized,

tokio/src/sync/semaphore.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@ impl Semaphore {
172172
///
173173
/// static SEM: Semaphore = Semaphore::const_new(10);
174174
/// ```
175-
///
176-
#[cfg(all(feature = "parking_lot", not(all(loom, test))))]
177-
#[cfg_attr(docsrs, doc(cfg(feature = "parking_lot")))]
175+
#[cfg(not(all(loom, test)))]
178176
pub const fn const_new(permits: usize) -> Self {
179177
#[cfg(all(tokio_unstable, feature = "tracing"))]
180178
return Self {

0 commit comments

Comments
 (0)