diff --git a/README.md b/README.md index 6cdd8d82..70fdca7c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lock_api/Cargo.toml b/lock_api/Cargo.toml index e5bb831b..01673764 100644 --- a/lock_api/Cargo.toml +++ b/lock_api/Cargo.toml @@ -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 = [] diff --git a/lock_api/build.rs b/lock_api/build.rs new file mode 100644 index 00000000..470c4177 --- /dev/null +++ b/lock_api/build.rs @@ -0,0 +1,16 @@ +fn main() { + let cfg = match autocfg::AutoCfg::new() { + Ok(cfg) => cfg, + Err(e) => { + println!( + "cargo:warning=lock_api: unable to determine rustc version: {}", + e + ); + return; + } + }; + + if cfg.probe_rustc_version(1, 61) { + println!("cargo:rustc-cfg=has_const_fn_trait_bound"); + } +} diff --git a/lock_api/src/lib.rs b/lock_api/src/lib.rs index c99c68bd..cfa53bce 100644 --- a/lock_api/src/lib.rs +++ b/lock_api/src/lib.rs @@ -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; diff --git a/lock_api/src/mutex.rs b/lock_api/src/mutex.rs index 81c25fb5..ad8ea3c5 100644 --- a/lock_api/src/mutex.rs +++ b/lock_api/src/mutex.rs @@ -149,7 +149,7 @@ unsafe impl Sync for Mutex {} impl Mutex { /// 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 { Mutex { @@ -159,7 +159,7 @@ impl Mutex { } /// 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 { Mutex { diff --git a/lock_api/src/remutex.rs b/lock_api/src/remutex.rs index dd992b46..fa0e934d 100644 --- a/lock_api/src/remutex.rs +++ b/lock_api/src/remutex.rs @@ -230,7 +230,7 @@ unsafe impl Sync impl ReentrantMutex { /// 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 { ReentrantMutex { @@ -245,7 +245,7 @@ impl ReentrantMutex { } /// 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 { ReentrantMutex { diff --git a/lock_api/src/rwlock.rs b/lock_api/src/rwlock.rs index 9bfa1dac..e947f1ec 100644 --- a/lock_api/src/rwlock.rs +++ b/lock_api/src/rwlock.rs @@ -366,7 +366,7 @@ unsafe impl Sync for RwLock impl RwLock { /// Creates a new instance of an `RwLock` which is unlocked. - #[cfg(feature = "nightly")] + #[cfg(has_const_fn_trait_bound)] #[inline] pub const fn new(val: T) -> RwLock { RwLock { @@ -376,7 +376,7 @@ impl RwLock { } /// Creates a new instance of an `RwLock` which is unlocked. - #[cfg(not(feature = "nightly"))] + #[cfg(not(has_const_fn_trait_bound))] #[inline] pub fn new(val: T) -> RwLock { RwLock { @@ -892,7 +892,7 @@ impl RwLock { /// 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) -> Option> { diff --git a/src/condvar.rs b/src/condvar.rs index 9eaf3007..27fd4c82 100644 --- a/src/condvar.rs +++ b/src/condvar.rs @@ -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. /// diff --git a/src/fair_mutex.rs b/src/fair_mutex.rs index 3e4c163c..d7d7a77c 100644 --- a/src/fair_mutex.rs +++ b/src/fair_mutex.rs @@ -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. diff --git a/src/mutex.rs b/src/mutex.rs index 71bc3519..f3f8aa92 100644 --- a/src/mutex.rs +++ b/src/mutex.rs @@ -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. diff --git a/src/rwlock.rs b/src/rwlock.rs index 512114c1..4167a858 100644 --- a/src/rwlock.rs +++ b/src/rwlock.rs @@ -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.