Skip to content

Commit b36d59d

Browse files
authored
core: adjust Once to not violate feature additivity principle (#760)
When the following dependencies and their features were specified: ```toml tracing-core = { version = "0.1", default-features = false, features = ["std"] } tracing = { version = "0.1", default-features = false } ``` The build would fail with the following error: ``` error[E0412]: cannot find type `Once` in crate `tracing_core` --> tracing/src/lib.rs:840:35 | 840 | pub type Once = tracing_core::Once<()>; | ^^^^ not found in `tracing_core` | ``` This happened because `tracing-core` exports `Once` only if its `std` feature is disabled. And the depending `tracing` crate assumed that if its `std` feature was disabled, so would be the `std` feature in `tracing-core`. This is a violation of the [undocumented "features must be additive" guideline][ag]. In this commit tracing-core is adjusted to export `Once` regardless of whether `std` is disabled or not. [ag]: rust-lang/cargo#4328
1 parent 4fe9033 commit b36d59d

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

tracing-core/src/lazy_static/core_lazy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// http://opensource.org/licenses/MIT>, at your option. This file may not be
66
// copied, modified, or distributed except according to those terms.
77

8-
use crate::Once;
8+
use crate::spin::Once;
99

1010
pub(crate) struct Lazy<T: Sync>(Once<T>);
1111

tracing-core/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ pub(crate) mod spin;
226226

227227
#[cfg(not(feature = "std"))]
228228
#[doc(hidden)]
229-
pub use self::spin::Once;
229+
pub type Once = self::spin::Once<()>;
230+
231+
#[cfg(feature = "std")]
232+
pub use stdlib::sync::Once;
230233

231234
pub mod callsite;
232235
pub mod dispatcher;

tracing-core/src/spin/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Synchronization primitives based on spinning
22
33
pub(crate) use mutex::*;
4-
pub use once::Once;
4+
pub(crate) use once::Once;
55

66
mod mutex;
77
mod once;

tracing/src/lib.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -832,12 +832,7 @@ pub mod subscriber;
832832
#[doc(hidden)]
833833
pub mod __macro_support {
834834
pub use crate::stdlib::sync::atomic::{AtomicUsize, Ordering};
835-
836-
#[cfg(feature = "std")]
837-
pub use crate::stdlib::sync::Once;
838-
839-
#[cfg(not(feature = "std"))]
840-
pub type Once = tracing_core::Once<()>;
835+
pub type Once = tracing_core::Once;
841836
}
842837

843838
mod sealed {

0 commit comments

Comments
 (0)