From f0214e1c95c0a72f867058b21b59579567d2380c Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Tue, 19 Oct 2021 10:26:29 -0700 Subject: [PATCH] subscriber: remove `Layer` impls for `Arc`s (#1649) Implementing `Layer` for `Arc`s, which are immutable, breaks the ability to implement `Layer::on_layer` with a mutable reference. This is necessary for per-layer filtering. See https://github.com/tokio-rs/tracing/pull/1576#discussion_r711609810 for details. Therefore, the `Layer` impls for `Arc`s should not be used. In 0.3, we have the opportunity to remove these APIs. Therefore, this PR removes them. --- tracing-subscriber/src/layer/mod.rs | 46 ++++------------------------- 1 file changed, 5 insertions(+), 41 deletions(-) diff --git a/tracing-subscriber/src/layer/mod.rs b/tracing-subscriber/src/layer/mod.rs index cebbb3d9c2..2a647623f8 100644 --- a/tracing-subscriber/src/layer/mod.rs +++ b/tracing-subscriber/src/layer/mod.rs @@ -1175,6 +1175,11 @@ where macro_rules! layer_impl_body { () => { + #[inline] + fn on_layer(&mut self, subscriber: &mut S) { + self.deref_mut().on_layer(subscriber); + } + #[inline] fn new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) { self.deref().new_span(attrs, id, ctx) @@ -1238,48 +1243,11 @@ macro_rules! layer_impl_body { }; } -impl Layer for Arc -where - L: Layer, - S: Subscriber, -{ - fn on_layer(&mut self, subscriber: &mut S) { - if let Some(inner) = Arc::get_mut(self) { - // XXX(eliza): this may behave weird if another `Arc` clone of this - // layer is layered onto a _different_ subscriber...but there's no - // good solution for that... - inner.on_layer(subscriber); - } - } - - layer_impl_body! {} -} - -impl Layer for Arc + Send + Sync> -where - S: Subscriber, -{ - fn on_layer(&mut self, subscriber: &mut S) { - if let Some(inner) = Arc::get_mut(self) { - // XXX(eliza): this may behave weird if another `Arc` clone of this - // layer is layered onto a _different_ subscriber...but there's no - // good solution for that... - inner.on_layer(subscriber); - } - } - - layer_impl_body! {} -} - impl Layer for Box where L: Layer, S: Subscriber, { - fn on_layer(&mut self, subscriber: &mut S) { - self.deref_mut().on_layer(subscriber); - } - layer_impl_body! {} } @@ -1287,10 +1255,6 @@ impl Layer for Box + Send + Sync> where S: Subscriber, { - fn on_layer(&mut self, subscriber: &mut S) { - self.deref_mut().on_layer(subscriber); - } - layer_impl_body! {} }