Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistently pass a ref to a Dispatch #1045

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tracing-core/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
//! // no default subscriber
//!
//! # #[cfg(feature = "std")]
//! dispatcher::set_global_default(my_dispatch)
//! dispatcher::set_global_default(&my_dispatch)
//! // `set_global_default` will return an error if the global default
//! // subscriber has already been set.
//! .expect("global default was already set!");
Expand Down Expand Up @@ -307,12 +307,12 @@ pub fn set_default(dispatcher: &Dispatch) -> DefaultGuard {
/// [span]: super::span
/// [`Subscriber`]: super::subscriber::Subscriber
/// [`Event`]: super::event::Event
pub fn set_global_default(dispatcher: Dispatch) -> Result<(), SetGlobalDefaultError> {
pub fn set_global_default(dispatcher: &Dispatch) -> Result<(), SetGlobalDefaultError> {
if GLOBAL_INIT.compare_and_swap(UNINITIALIZED, INITIALIZING, Ordering::SeqCst) == UNINITIALIZED
{
#[cfg(feature = "alloc")]
let subscriber = {
let subscriber = match dispatcher.subscriber {
let subscriber = match dispatcher.subscriber.clone() {
Kind::Global(s) => s,
Kind::Scoped(s) => unsafe {
// safety: this leaks the subscriber onto the heap. the
Expand Down Expand Up @@ -527,7 +527,7 @@ impl Dispatch {
///
/// let dispatch = Dispatch::from_static(&SUBSCRIBER);
///
/// dispatcher::set_global_default(dispatch)
/// dispatcher::set_global_default(&dispatch)
/// .expect("no global default subscriber should have been set previously!");
/// }
/// ```
Expand Down
2 changes: 1 addition & 1 deletion tracing-core/tests/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use tracing_core::dispatcher::*;
#[cfg(feature = "std")]
#[test]
fn set_default_dispatch() {
set_global_default(Dispatch::new(TestSubscriberA)).expect("global dispatch set failed");
set_global_default(&Dispatch::new(TestSubscriberA)).expect("global dispatch set failed");
get_default(|current| {
assert!(
current.is::<TestSubscriberA>(),
Expand Down
4 changes: 2 additions & 2 deletions tracing-core/tests/global_dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use tracing_core::dispatcher::*;
#[test]
fn global_dispatch() {
static TEST: TestSubscriberA = TestSubscriberA;
set_global_default(Dispatch::from_static(&TEST)).expect("global dispatch set failed");
set_global_default(&Dispatch::from_static(&TEST)).expect("global dispatch set failed");
get_default(|current| {
assert!(
current.is::<TestSubscriberA>(),
Expand All @@ -30,6 +30,6 @@ fn global_dispatch() {
)
});

set_global_default(Dispatch::from_static(&TEST))
set_global_default(&Dispatch::from_static(&TEST))
.expect_err("double global dispatch set succeeded");
}
2 changes: 1 addition & 1 deletion tracing-subscriber/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ where
#[cfg(feature = "tracing-log")]
tracing_log::LogTracer::init().map_err(Box::new)?;

tracing_core::dispatcher::set_global_default(tracing_core::dispatcher::Dispatch::new(
tracing_core::dispatcher::set_global_default(&tracing_core::dispatcher::Dispatch::new(
self.finish(),
))?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion tracing-subscriber/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ where
#[cfg(feature = "tracing-log")]
tracing_log::LogTracer::init().map_err(TryInitError::new)?;

dispatcher::set_global_default(self.into()).map_err(TryInitError::new)?;
dispatcher::set_global_default(&self.into()).map_err(TryInitError::new)?;

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion tracing/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
//! // no default subscriber
//!
//! # #[cfg(feature = "alloc")]
//! dispatcher::set_global_default(my_dispatch)
//! dispatcher::set_global_default(&my_dispatch)
//! // `set_global_default` will return an error if the global default
//! // subscriber has already been set.
//! .expect("global default was already set!");
Expand Down
2 changes: 1 addition & 1 deletion tracing/src/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn set_global_default<S>(subscriber: S) -> Result<(), SetGlobalDefaultError>
where
S: Subscriber + Send + Sync + 'static,
{
crate::dispatcher::set_global_default(crate::Dispatch::new(subscriber))
crate::dispatcher::set_global_default(&crate::Dispatch::new(subscriber))
}

/// Sets the subscriber as the default for the duration of the lifetime of the
Expand Down