Skip to content

Commit 3250d0b

Browse files
committed
core: Use const initializers instead of once_cell
1 parent 6e59a13 commit 3250d0b

File tree

5 files changed

+12
-90
lines changed

5 files changed

+12
-90
lines changed

tracing-core/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ rust-version = "1.65.0"
2626

2727
[features]
2828
default = ["std", "valuable?/std"]
29-
std = ["once_cell"]
29+
std = []
30+
# used to be an implicit feature from an optional dependency
31+
# FIXME: remove with the next breaking-change release
32+
once_cell = []
3033

3134
[badges]
3235
maintenance = { status = "actively-developed" }
3336

3437
[dependencies]
35-
once_cell = { version = "1.13.0", optional = true }
3638

3739
[target.'cfg(tracing_unstable)'.dependencies]
3840
valuable = { version = "0.1.0", optional = true, default-features = false }

tracing-core/src/callsite.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ use crate::stdlib::{
109109
};
110110
use crate::{
111111
dispatcher::Dispatch,
112-
lazy::Lazy,
113112
metadata::{LevelFilter, Metadata},
114113
subscriber::Interest,
115114
};
@@ -260,7 +259,7 @@ static CALLSITES: Callsites = Callsites {
260259

261260
static DISPATCHERS: Dispatchers = Dispatchers::new();
262261

263-
static LOCKED_CALLSITES: Lazy<Mutex<Vec<&'static dyn Callsite>>> = Lazy::new(Default::default);
262+
static LOCKED_CALLSITES: Mutex<Vec<&'static dyn Callsite>> = Mutex::new(Vec::new());
264263

265264
struct Callsites {
266265
list_head: AtomicPtr<DefaultCallsite>,
@@ -515,7 +514,7 @@ mod private {
515514

516515
#[cfg(feature = "std")]
517516
mod dispatchers {
518-
use crate::{dispatcher, lazy::Lazy};
517+
use crate::dispatcher;
519518
use std::sync::{
520519
atomic::{AtomicBool, Ordering},
521520
RwLock, RwLockReadGuard, RwLockWriteGuard,
@@ -525,8 +524,7 @@ mod dispatchers {
525524
has_just_one: AtomicBool,
526525
}
527526

528-
static LOCKED_DISPATCHERS: Lazy<RwLock<Vec<dispatcher::Registrar>>> =
529-
Lazy::new(Default::default);
527+
static LOCKED_DISPATCHERS: RwLock<Vec<dispatcher::Registrar>> = RwLock::new(Vec::new());
530528

531529
pub(super) enum Rebuilder<'a> {
532530
JustOne,

tracing-core/src/lazy.rs

Lines changed: 0 additions & 76 deletions
This file was deleted.

tracing-core/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,6 @@ macro_rules! metadata {
261261
};
262262
}
263263

264-
pub(crate) mod lazy;
265-
266264
// Trimmed-down vendored version of spin 0.5.2 (0387621)
267265
// Dependency of no_std lazy_static, not required in a std build
268266
#[cfg(not(feature = "std"))]

tracing-core/src/stdlib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ mod no_std {
6464
}
6565

6666
impl<T> Mutex<T> {
67-
// pub(crate) fn new(data: T) -> Self {
68-
// Self {
69-
// inner: crate::spin::Mutex::new(data),
70-
// }
71-
// }
67+
pub(crate) const fn new(data: T) -> Self {
68+
Self {
69+
inner: crate::spin::Mutex::new(data),
70+
}
71+
}
7272

7373
pub(crate) fn lock(&self) -> Result<MutexGuard<'_, T>, ()> {
7474
Ok(self.inner.lock())

0 commit comments

Comments
 (0)