Skip to content

Commit

Permalink
Made error messages when using portable_atomic without appropriate cf…
Browse files Browse the repository at this point in the history
…g flag easier to understand
  • Loading branch information
zesterer committed Apr 25, 2023
1 parent 1f2e06c commit 3d061b8
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,34 +68,37 @@ extern crate portable_atomic;

#[cfg(not(feature = "portable_atomic"))]
use core::sync::atomic;
#[cfg(feature = "portable_atomic")]
#[cfg(all(feature = "portable_atomic", portable_atomic_unsafe_assume_single_core))]
use portable_atomic as atomic;

#[cfg(feature = "barrier")]
#[cfg(all(feature = "portable_atomic", not(portable_atomic_unsafe_assume_single_core)))]
core::compile_error!("The feature \"portable_atomic\" requires the \"portable_atomic_unsafe_assume_single_core\" cfg flag to be enabled. See https://docs.rs/portable-atomic/latest/portable_atomic/#optional-cfg.");

#[cfg(all(feature = "barrier", any(not(feature = "portable_atomic"), all(feature = "portable_atomic", portable_atomic_unsafe_assume_single_core))))]
#[cfg_attr(docsrs, doc(cfg(feature = "barrier")))]
pub mod barrier;
#[cfg(feature = "lazy")]
#[cfg(all(feature = "lazy", any(not(feature = "portable_atomic"), all(feature = "portable_atomic", portable_atomic_unsafe_assume_single_core))))]
#[cfg_attr(docsrs, doc(cfg(feature = "lazy")))]
pub mod lazy;
#[cfg(feature = "mutex")]
#[cfg(all(feature = "mutex", any(not(feature = "portable_atomic"), all(feature = "portable_atomic", portable_atomic_unsafe_assume_single_core))))]
#[cfg_attr(docsrs, doc(cfg(feature = "mutex")))]
pub mod mutex;
#[cfg(feature = "once")]
#[cfg(all(feature = "once", any(not(feature = "portable_atomic"), all(feature = "portable_atomic", portable_atomic_unsafe_assume_single_core))))]
#[cfg_attr(docsrs, doc(cfg(feature = "once")))]
pub mod once;
pub mod relax;
#[cfg(feature = "rwlock")]
#[cfg(all(feature = "rwlock", any(not(feature = "portable_atomic"), all(feature = "portable_atomic", portable_atomic_unsafe_assume_single_core))))]
#[cfg_attr(docsrs, doc(cfg(feature = "rwlock")))]
pub mod rwlock;

#[cfg(feature = "mutex")]
#[cfg(all(feature = "mutex", any(not(feature = "portable_atomic"), all(feature = "portable_atomic", portable_atomic_unsafe_assume_single_core))))]
#[cfg_attr(docsrs, doc(cfg(feature = "mutex")))]
pub use mutex::MutexGuard;
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub use relax::Yield;
pub use relax::{RelaxStrategy, Spin};
#[cfg(feature = "rwlock")]
#[cfg(all(feature = "rwlock", any(not(feature = "portable_atomic"), all(feature = "portable_atomic", portable_atomic_unsafe_assume_single_core))))]
#[cfg_attr(docsrs, doc(cfg(feature = "rwlock")))]
pub use rwlock::RwLockReadGuard;

Expand All @@ -107,39 +110,39 @@ pub use rwlock::RwLockReadGuard;
///
/// A note for advanced users: this alias exists to avoid subtle type inference errors due to the default relax
/// strategy type parameter. If you need a non-default relax strategy, use the fully-qualified path.
#[cfg(feature = "barrier")]
#[cfg(all(feature = "barrier", any(not(feature = "portable_atomic"), all(feature = "portable_atomic", portable_atomic_unsafe_assume_single_core))))]
#[cfg_attr(docsrs, doc(cfg(feature = "barrier")))]
pub type Barrier = crate::barrier::Barrier;

/// A value which is initialized on the first access. See [`lazy::Lazy`] for documentation.
///
/// A note for advanced users: this alias exists to avoid subtle type inference errors due to the default relax
/// strategy type parameter. If you need a non-default relax strategy, use the fully-qualified path.
#[cfg(feature = "lazy")]
#[cfg(all(feature = "lazy", any(not(feature = "portable_atomic"), all(feature = "portable_atomic", portable_atomic_unsafe_assume_single_core))))]
#[cfg_attr(docsrs, doc(cfg(feature = "lazy")))]
pub type Lazy<T, F = fn() -> T> = crate::lazy::Lazy<T, F>;

/// A primitive that synchronizes the execution of multiple threads. See [`mutex::Mutex`] for documentation.
///
/// A note for advanced users: this alias exists to avoid subtle type inference errors due to the default relax
/// strategy type parameter. If you need a non-default relax strategy, use the fully-qualified path.
#[cfg(feature = "mutex")]
#[cfg(all(feature = "mutex", any(not(feature = "portable_atomic"), all(feature = "portable_atomic", portable_atomic_unsafe_assume_single_core))))]
#[cfg_attr(docsrs, doc(cfg(feature = "mutex")))]
pub type Mutex<T> = crate::mutex::Mutex<T>;

/// A primitive that provides lazy one-time initialization. See [`once::Once`] for documentation.
///
/// A note for advanced users: this alias exists to avoid subtle type inference errors due to the default relax
/// strategy type parameter. If you need a non-default relax strategy, use the fully-qualified path.
#[cfg(feature = "once")]
#[cfg(all(feature = "once", any(not(feature = "portable_atomic"), all(feature = "portable_atomic", portable_atomic_unsafe_assume_single_core))))]
#[cfg_attr(docsrs, doc(cfg(feature = "once")))]
pub type Once<T = ()> = crate::once::Once<T>;

/// A lock that provides data access to either one writer or many readers. See [`rwlock::RwLock`] for documentation.
///
/// A note for advanced users: this alias exists to avoid subtle type inference errors due to the default relax
/// strategy type parameter. If you need a non-default relax strategy, use the fully-qualified path.
#[cfg(feature = "rwlock")]
#[cfg(all(feature = "rwlock", any(not(feature = "portable_atomic"), all(feature = "portable_atomic", portable_atomic_unsafe_assume_single_core))))]
#[cfg_attr(docsrs, doc(cfg(feature = "rwlock")))]
pub type RwLock<T> = crate::rwlock::RwLock<T>;

Expand All @@ -148,15 +151,15 @@ pub type RwLock<T> = crate::rwlock::RwLock<T>;
///
/// A note for advanced users: this alias exists to avoid subtle type inference errors due to the default relax
/// strategy type parameter. If you need a non-default relax strategy, use the fully-qualified path.
#[cfg(feature = "rwlock")]
#[cfg(all(feature = "rwlock", any(not(feature = "portable_atomic"), all(feature = "portable_atomic", portable_atomic_unsafe_assume_single_core))))]
#[cfg_attr(docsrs, doc(cfg(feature = "rwlock")))]
pub type RwLockUpgradableGuard<'a, T> = crate::rwlock::RwLockUpgradableGuard<'a, T>;

/// A guard that provides mutable data access. See [`rwlock::RwLockWriteGuard`] for documentation.
///
/// A note for advanced users: this alias exists to avoid subtle type inference errors due to the default relax
/// strategy type parameter. If you need a non-default relax strategy, use the fully-qualified path.
#[cfg(feature = "rwlock")]
#[cfg(all(feature = "rwlock", any(not(feature = "portable_atomic"), all(feature = "portable_atomic", portable_atomic_unsafe_assume_single_core))))]
#[cfg_attr(docsrs, doc(cfg(feature = "rwlock")))]
pub type RwLockWriteGuard<'a, T> = crate::rwlock::RwLockWriteGuard<'a, T>;

Expand Down

0 comments on commit 3d061b8

Please sign in to comment.