Update to stabilized const_fn_trait_bound

This commit is contained in:
Taiki Endo
2022-03-16 22:53:18 +09:00
parent 9f49f67edf
commit 72a16ad077
11 changed files with 21 additions and 17 deletions
-3
View File
@@ -91,9 +91,6 @@ lock.
There are a few restrictions when using this library on stable Rust:
- You will have to use the `const_*` functions (e.g. `const_mutex(val)`) to
statically initialize the locking primitives. Using e.g. `Mutex::new(val)`
does not work on stable Rust yet.
- The `wasm32-unknown-unknown` target is only fully supported on nightly with
`-C target-feature=+atomics` in `RUSTFLAGS` and `-Z build-std` passed to cargo.
parking_lot will work mostly fine on stable, the only difference is it will
+3
View File
@@ -18,6 +18,9 @@ owning_ref = { version = "0.4.1", optional = true }
# support, just pass "--features serde" when building this crate.
serde = { version = "1.0.126", default-features = false, optional = true }
[build-dependencies]
autocfg = "1.1.0"
[features]
nightly = []
arc_lock = []
+7
View File
@@ -0,0 +1,7 @@
fn main() {
let cfg = autocfg::new();
if cfg.probe_rustc_version(1, 61) {
println!("cargo:rustc-cfg=has_const_fn_trait_bound");
}
}
-3
View File
@@ -84,13 +84,10 @@
//! - `owning_ref`: Allows your lock types to be used with the `owning_ref` crate.
//! - `arc_lock`: Enables locking from an `Arc`. This enables types such as `ArcMutexGuard`. Note that this
//! requires the `alloc` crate to be present.
//! - `nightly`: Enables nightly-only features. At the moment the only such
//! feature is `const fn` constructors for lock types.
#![no_std]
#![warn(missing_docs)]
#![warn(rust_2018_idioms)]
#![cfg_attr(feature = "nightly", feature(const_fn_trait_bound))]
#[macro_use]
extern crate scopeguard;
+2 -2
View File
@@ -149,7 +149,7 @@ unsafe impl<R: RawMutex + Sync, T: ?Sized + Send> Sync for Mutex<R, T> {}
impl<R: RawMutex, T> Mutex<R, T> {
/// Creates a new mutex in an unlocked state ready for use.
#[cfg(feature = "nightly")]
#[cfg(has_const_fn_trait_bound)]
#[inline]
pub const fn new(val: T) -> Mutex<R, T> {
Mutex {
@@ -159,7 +159,7 @@ impl<R: RawMutex, T> Mutex<R, T> {
}
/// Creates a new mutex in an unlocked state ready for use.
#[cfg(not(feature = "nightly"))]
#[cfg(not(has_const_fn_trait_bound))]
#[inline]
pub fn new(val: T) -> Mutex<R, T> {
Mutex {
+2 -2
View File
@@ -230,7 +230,7 @@ unsafe impl<R: RawMutex + Sync, G: GetThreadId + Sync, T: ?Sized + Send> Sync
impl<R: RawMutex, G: GetThreadId, T> ReentrantMutex<R, G, T> {
/// Creates a new reentrant mutex in an unlocked state ready for use.
#[cfg(feature = "nightly")]
#[cfg(has_const_fn_trait_bound)]
#[inline]
pub const fn new(val: T) -> ReentrantMutex<R, G, T> {
ReentrantMutex {
@@ -245,7 +245,7 @@ impl<R: RawMutex, G: GetThreadId, T> ReentrantMutex<R, G, T> {
}
/// Creates a new reentrant mutex in an unlocked state ready for use.
#[cfg(not(feature = "nightly"))]
#[cfg(not(has_const_fn_trait_bound))]
#[inline]
pub fn new(val: T) -> ReentrantMutex<R, G, T> {
ReentrantMutex {
+3 -3
View File
@@ -366,7 +366,7 @@ unsafe impl<R: RawRwLock + Sync, T: ?Sized + Send + Sync> Sync for RwLock<R, T>
impl<R: RawRwLock, T> RwLock<R, T> {
/// Creates a new instance of an `RwLock<T>` which is unlocked.
#[cfg(feature = "nightly")]
#[cfg(has_const_fn_trait_bound)]
#[inline]
pub const fn new(val: T) -> RwLock<R, T> {
RwLock {
@@ -376,7 +376,7 @@ impl<R: RawRwLock, T> RwLock<R, T> {
}
/// Creates a new instance of an `RwLock<T>` which is unlocked.
#[cfg(not(feature = "nightly"))]
#[cfg(not(has_const_fn_trait_bound))]
#[inline]
pub fn new(val: T) -> RwLock<R, T> {
RwLock {
@@ -892,7 +892,7 @@ impl<R: RawRwLockRecursive, T: ?Sized> RwLock<R, T> {
/// Attempts to lock this `RwLock` with shared read access, through an `Arc`.
///
/// This method is similar to the `try_read_recursive` method; however, it requires the `RwLock` to be inside
/// of an `Arc` and the resulting read guard has no lifetime requirements.
/// of an `Arc` and the resulting read guard has no lifetime requirements.
#[cfg(feature = "arc_lock")]
#[inline]
pub fn try_read_recursive_arc(self: &Arc<Self>) -> Option<ArcRwLockReadGuard<R, T>> {
+1 -1
View File
@@ -53,7 +53,7 @@ impl WaitTimeoutResult {
/// woken up.
/// - Only requires 1 word of space, whereas the standard library boxes the
/// `Condvar` due to platform limitations.
/// - Can be statically constructed (requires the `const_fn` nightly feature).
/// - Can be statically constructed.
/// - Does not require any drop glue when dropped.
/// - Inline fast path for the uncontended case.
///
+1 -1
View File
@@ -35,7 +35,7 @@ use lock_api;
/// - No poisoning, the lock is released normally on panic.
/// - Only requires 1 byte of space, whereas the standard library boxes the
/// `FairMutex` due to platform limitations.
/// - Can be statically constructed (requires the `const_fn` nightly feature).
/// - Can be statically constructed.
/// - Does not require any drop glue when dropped.
/// - Inline fast path for the uncontended case.
/// - Efficient handling of micro-contention using adaptive spinning.
+1 -1
View File
@@ -42,7 +42,7 @@ use lock_api;
/// - No poisoning, the lock is released normally on panic.
/// - Only requires 1 byte of space, whereas the standard library boxes the
/// `Mutex` due to platform limitations.
/// - Can be statically constructed (requires the `const_fn` nightly feature).
/// - Can be statically constructed.
/// - Does not require any drop glue when dropped.
/// - Inline fast path for the uncontended case.
/// - Efficient handling of micro-contention using adaptive spinning.
+1 -1
View File
@@ -55,7 +55,7 @@ use lock_api;
/// - No poisoning, the lock is released normally on panic.
/// - Only requires 1 word of space, whereas the standard library boxes the
/// `RwLock` due to platform limitations.
/// - Can be statically constructed (requires the `const_fn` nightly feature).
/// - Can be statically constructed.
/// - Does not require any drop glue when dropped.
/// - Inline fast path for the uncontended case.
/// - Efficient handling of micro-contention using adaptive spinning.