diff --git a/tracing-core/src/callsite.rs b/tracing-core/src/callsite.rs index eeed16ca66..cb638f4633 100644 --- a/tracing-core/src/callsite.rs +++ b/tracing-core/src/callsite.rs @@ -420,10 +420,9 @@ mod dispatchers { #[cfg(not(feature = "std"))] mod dispatchers { use crate::dispatcher; - use core::marker::PhantomData; pub(super) struct Dispatchers(()); - pub(super) struct Rebuilder<'a>(PhantomData<&'a ()>); + pub(super) struct Rebuilder<'a>(Option<&'a dispatcher::Dispatch>); impl Dispatchers { pub(super) const fn new() -> Self { @@ -431,20 +430,32 @@ mod dispatchers { } pub(super) fn rebuilder(&self) -> Rebuilder<'_> { - Rebuilder(PhantomData) - } + Rebuilder(None) + }E - pub(super) fn register_dispatch(&self, _: &dispatcher::Dispatch) -> Rebuilder<'_> { + pub(super) fn register_dispatch<'dispatch>( + &self, + dispatch: &'dispatch dispatcher::Dispatch, + ) -> Rebuilder<'dispatch> { // nop; on no_std, there can only ever be one dispatcher - Rebuilder(PhantomData) + Rebuilder(Some(dispatch)) } } impl Rebuilder<'_> { - #[inline(always)] + #[inline] pub(super) fn for_each(&self, mut f: impl FnMut(&dispatcher::Dispatch)) { - // on no_std, there can only ever be one dispatcher - dispatcher::get_default(f) + if let Some(dispatch) = self.0 { + // we are rebuilding the interest cache because a new dispatcher + // is about to be set. on `no_std`, this should only happen + // once, because the new dispatcher will be the global default. + f(dispatch) + } else { + // otherwise, we are rebuilding the cache because the subscriber + // configuration changed, so use the global default. + // on no_std, there can only ever be one dispatcher + dispatcher::get_default(f) + } } } } diff --git a/tracing-mock/src/subscriber.rs b/tracing-mock/src/subscriber.rs index 8fbffbb396..17e1a7ed73 100644 --- a/tracing-mock/src/subscriber.rs +++ b/tracing-mock/src/subscriber.rs @@ -198,7 +198,9 @@ where Interest::never() } } + fn max_level_hint(&self) -> Option { + println!("[{}] max_level_hint -> {:?}", self.name, self.max_level); self.max_level }