Skip to content

Commit 3d061b8

Browse files
committed
Made error messages when using portable_atomic without appropriate cfg flag easier to understand
1 parent 1f2e06c commit 3d061b8

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/lib.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,34 +68,37 @@ extern crate portable_atomic;
6868

6969
#[cfg(not(feature = "portable_atomic"))]
7070
use core::sync::atomic;
71-
#[cfg(feature = "portable_atomic")]
71+
#[cfg(all(feature = "portable_atomic", portable_atomic_unsafe_assume_single_core))]
7272
use portable_atomic as atomic;
7373

74-
#[cfg(feature = "barrier")]
74+
#[cfg(all(feature = "portable_atomic", not(portable_atomic_unsafe_assume_single_core)))]
75+
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.");
76+
77+
#[cfg(all(feature = "barrier", any(not(feature = "portable_atomic"), all(feature = "portable_atomic", portable_atomic_unsafe_assume_single_core))))]
7578
#[cfg_attr(docsrs, doc(cfg(feature = "barrier")))]
7679
pub mod barrier;
77-
#[cfg(feature = "lazy")]
80+
#[cfg(all(feature = "lazy", any(not(feature = "portable_atomic"), all(feature = "portable_atomic", portable_atomic_unsafe_assume_single_core))))]
7881
#[cfg_attr(docsrs, doc(cfg(feature = "lazy")))]
7982
pub mod lazy;
80-
#[cfg(feature = "mutex")]
83+
#[cfg(all(feature = "mutex", any(not(feature = "portable_atomic"), all(feature = "portable_atomic", portable_atomic_unsafe_assume_single_core))))]
8184
#[cfg_attr(docsrs, doc(cfg(feature = "mutex")))]
8285
pub mod mutex;
83-
#[cfg(feature = "once")]
86+
#[cfg(all(feature = "once", any(not(feature = "portable_atomic"), all(feature = "portable_atomic", portable_atomic_unsafe_assume_single_core))))]
8487
#[cfg_attr(docsrs, doc(cfg(feature = "once")))]
8588
pub mod once;
8689
pub mod relax;
87-
#[cfg(feature = "rwlock")]
90+
#[cfg(all(feature = "rwlock", any(not(feature = "portable_atomic"), all(feature = "portable_atomic", portable_atomic_unsafe_assume_single_core))))]
8891
#[cfg_attr(docsrs, doc(cfg(feature = "rwlock")))]
8992
pub mod rwlock;
9093

91-
#[cfg(feature = "mutex")]
94+
#[cfg(all(feature = "mutex", any(not(feature = "portable_atomic"), all(feature = "portable_atomic", portable_atomic_unsafe_assume_single_core))))]
9295
#[cfg_attr(docsrs, doc(cfg(feature = "mutex")))]
9396
pub use mutex::MutexGuard;
9497
#[cfg(feature = "std")]
9598
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
9699
pub use relax::Yield;
97100
pub use relax::{RelaxStrategy, Spin};
98-
#[cfg(feature = "rwlock")]
101+
#[cfg(all(feature = "rwlock", any(not(feature = "portable_atomic"), all(feature = "portable_atomic", portable_atomic_unsafe_assume_single_core))))]
99102
#[cfg_attr(docsrs, doc(cfg(feature = "rwlock")))]
100103
pub use rwlock::RwLockReadGuard;
101104

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)