Skip to content

Commit cbafd75

Browse files
NobodyXuhawkw
authored andcommitted
Remove dep cfg-if from tracing (#2553)
Same reason as rust-lang/log#536 : `cfg_if` is only used in a single place and `tracing` is used by many other crates, so even removing one dependency will be beneficial. Remove dependency `cfg-if` and replace `cfg_if::cfg_if!` with a `const fn get_max_level_inner() -> LevelFilter` and uses `if cfg!(...)` inside. Using if in const function is stablised in [1.46](https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1460-2020-08-27) so this should work fine in msrv 1.56 Signed-off-by: Jiahao XU <[email protected]> ; Conflicts: ; tracing/Cargo.toml ; tracing/src/level_filters.rs
1 parent 63ae090 commit cbafd75

File tree

2 files changed

+30
-27
lines changed

2 files changed

+30
-27
lines changed

tracing/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ rust-version = "1.56.0"
3131
tracing-core = { path = "../tracing-core", version = "0.1.30", default-features = false }
3232
log = { version = "0.4.17", optional = true }
3333
tracing-attributes = { path = "../tracing-attributes", version = "0.1.23", optional = true }
34-
cfg-if = "1.0.0"
3534
pin-project-lite = "0.2.9"
3635

3736
[dev-dependencies]

tracing/src/level_filters.rs

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -62,33 +62,37 @@ pub use tracing_core::{metadata::ParseLevelFilterError, LevelFilter};
6262
/// `Span` constructors should compare the level against this value to
6363
/// determine if those spans or events are enabled.
6464
///
65-
/// [module-level documentation]: super#compile-time-filters
66-
pub const STATIC_MAX_LEVEL: LevelFilter = MAX_LEVEL;
65+
/// [module-level documentation]: self#compile-time-filters
66+
pub const STATIC_MAX_LEVEL: LevelFilter = get_max_level_inner();
6767

68-
cfg_if::cfg_if! {
69-
if #[cfg(all(not(debug_assertions), feature = "release_max_level_off"))] {
70-
const MAX_LEVEL: LevelFilter = LevelFilter::OFF;
71-
} else if #[cfg(all(not(debug_assertions), feature = "release_max_level_error"))] {
72-
const MAX_LEVEL: LevelFilter = LevelFilter::ERROR;
73-
} else if #[cfg(all(not(debug_assertions), feature = "release_max_level_warn"))] {
74-
const MAX_LEVEL: LevelFilter = LevelFilter::WARN;
75-
} else if #[cfg(all(not(debug_assertions), feature = "release_max_level_info"))] {
76-
const MAX_LEVEL: LevelFilter = LevelFilter::INFO;
77-
} else if #[cfg(all(not(debug_assertions), feature = "release_max_level_debug"))] {
78-
const MAX_LEVEL: LevelFilter = LevelFilter::DEBUG;
79-
} else if #[cfg(all(not(debug_assertions), feature = "release_max_level_trace"))] {
80-
const MAX_LEVEL: LevelFilter = LevelFilter::TRACE;
81-
} else if #[cfg(feature = "max_level_off")] {
82-
const MAX_LEVEL: LevelFilter = LevelFilter::OFF;
83-
} else if #[cfg(feature = "max_level_error")] {
84-
const MAX_LEVEL: LevelFilter = LevelFilter::ERROR;
85-
} else if #[cfg(feature = "max_level_warn")] {
86-
const MAX_LEVEL: LevelFilter = LevelFilter::WARN;
87-
} else if #[cfg(feature = "max_level_info")] {
88-
const MAX_LEVEL: LevelFilter = LevelFilter::INFO;
89-
} else if #[cfg(feature = "max_level_debug")] {
90-
const MAX_LEVEL: LevelFilter = LevelFilter::DEBUG;
68+
const fn get_max_level_inner() -> LevelFilter {
69+
if cfg!(not(debug_assertions)) {
70+
if cfg!(feature = "release_max_level_off") {
71+
LevelFilter::OFF
72+
} else if cfg!(feature = "release_max_level_error") {
73+
LevelFilter::ERROR
74+
} else if cfg!(feature = "release_max_level_warn") {
75+
LevelFilter::WARN
76+
} else if cfg!(feature = "release_max_level_info") {
77+
LevelFilter::INFO
78+
} else if cfg!(feature = "release_max_level_debug") {
79+
LevelFilter::DEBUG
80+
} else {
81+
// Same as branch cfg!(feature = "release_max_level_trace")
82+
LevelFilter::TRACE
83+
}
84+
} else if cfg!(feature = "max_level_off") {
85+
LevelFilter::OFF
86+
} else if cfg!(feature = "max_level_error") {
87+
LevelFilter::ERROR
88+
} else if cfg!(feature = "max_level_warn") {
89+
LevelFilter::WARN
90+
} else if cfg!(feature = "max_level_info") {
91+
LevelFilter::INFO
92+
} else if cfg!(feature = "max_level_debug") {
93+
LevelFilter::DEBUG
9194
} else {
92-
const MAX_LEVEL: LevelFilter = LevelFilter::TRACE;
95+
// Same as branch cfg!(feature = "max_level_trace")
96+
LevelFilter::TRACE
9397
}
9498
}

0 commit comments

Comments
 (0)