From 89ba57736e1a183f55f6831458d54e1b265577be Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Wed, 20 Oct 2021 12:36:41 -0700 Subject: [PATCH] subscriber: feature flags that require `std` enable it (#1660) ## Motivation Currently, some `tracing-subscriber` dependencies in other crates use `default-features = false`, to ensure that unneeded default features of `tracing-subscriber` are not inadvertently enabled. However, some of the features those crates enable also require the `std` feature flag. The `default-features = false` config _disables_ the `std` feature, so the required features are not available. ## Solution This branch changes `tracing-subscriber`'s `fmt`, `registry`, and `env-filter` feature flags to also enable the `std` feature flag automatically. ## Alternatives As an alternative solution, we could change crates that depend on `tracing-subscriber` with `default-features = false` to also explicitly ensure that the `std` feature is enabled (which might be worth doing regardless). This is what PR #1659 does. However, I think the approach in this branch is more correct; the feature flags that require standard library support should automatically enable it. This provides a better experience for most users, who are simply adding `default-features = false` in order to avoid enabling un-needed features, not to support `no_std`, and would like enabling a feature flag to *actually* enable that feature. `no_std` users will know not to enable `registry`, `fmt`, and `env-filter` because the documentation notes that those features require the standard library. --- tracing-subscriber/Cargo.toml | 6 +++--- tracing-subscriber/src/lib.rs | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tracing-subscriber/Cargo.toml b/tracing-subscriber/Cargo.toml index 0b3da12788..dcea8dcb82 100644 --- a/tracing-subscriber/Cargo.toml +++ b/tracing-subscriber/Cargo.toml @@ -26,10 +26,10 @@ keywords = ["logging", "tracing", "metrics", "subscriber"] default = ["smallvec", "fmt", "ansi", "tracing-log", "std"] alloc = [] std = ["alloc", "tracing-core/std"] -env-filter = ["matchers", "regex", "lazy_static", "tracing"] -fmt = ["registry"] +env-filter = ["matchers", "regex", "lazy_static", "tracing", "std"] +fmt = ["registry", "std"] ansi = ["fmt", "ansi_term"] -registry = ["sharded-slab", "thread_local"] +registry = ["sharded-slab", "thread_local", "std"] json = ["tracing-serde", "serde", "serde_json"] # Enables support for local time when using the `time` crate timestamp # formatters. diff --git a/tracing-subscriber/src/lib.rs b/tracing-subscriber/src/lib.rs index 730fc05f36..209045283e 100644 --- a/tracing-subscriber/src/lib.rs +++ b/tracing-subscriber/src/lib.rs @@ -50,15 +50,16 @@ //! (enabled by default). //! - `alloc`: Depend on [`liballoc`] (enabled by "std"). //! - `env-filter`: Enables the [`EnvFilter`] type, which implements filtering -//! similar to the [`env_logger` crate]. +//! similar to the [`env_logger` crate]. **Requires "std"**. //! - `fmt`: Enables the [`fmt`] module, which provides a subscriber //! implementation for printing formatted representations of trace events. -//! Enabled by default. +//! Enabled by default. **Requires "std"**. //! - `ansi`: Enables `fmt` support for ANSI terminal colors. Enabled by //! default. //! - `registry`: enables the [`registry`] module. Enabled by default. +//! **Requires "std"**. //! - `json`: Enables `fmt` support for JSON output. In JSON output, the ANSI -//! feature does nothing. +//! feature does nothing. **Requires "fmt" and "std"**. //! - [`local-time`]: Enables local time formatting when using the [`time` //! crate]'s timestamp formatters with the `fmt` subscriber. //!