From 601bf6735ae7f92b0a73026a33e43cd8a84edca7 Mon Sep 17 00:00:00 2001 From: David Barsky Date: Fri, 18 Mar 2022 17:49:38 -0400 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/subscribe/mod.rs | 26 ++++++++++--------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/tracing-subscriber/src/subscribe/mod.rs b/tracing-subscriber/src/subscribe/mod.rs index 475d138b76..d56401aec6 100644 --- a/tracing-subscriber/src/subscribe/mod.rs +++ b/tracing-subscriber/src/subscribe/mod.rs @@ -417,7 +417,11 @@ //! [`LevelFilter`]: crate::filter::LevelFilter //! [feat]: crate#feature-flags use crate::filter; -use std::{any::TypeId, ops::Deref, ptr::NonNull, sync::Arc}; +use std::{ + any::TypeId, + ops::{Deref, DerefMut}, + ptr::NonNull, +}; use tracing_core::{ collect::{Collect, Interest}, metadata::Metadata, @@ -1083,6 +1087,11 @@ where macro_rules! layer_impl_body { () => { + #[inline] + fn on_subscribe(&mut self, collect: &mut C) { + self.deref_mut().on_subscribe(collect); + } + #[inline] fn on_new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, C>) { self.deref().on_new_span(attrs, id, ctx) @@ -1146,21 +1155,6 @@ macro_rules! layer_impl_body { }; } -impl Subscribe for Arc -where - S: Subscribe, - C: Collect, -{ - layer_impl_body! {} -} - -impl Subscribe for Arc> -where - C: Collect, -{ - layer_impl_body! {} -} - impl Subscribe for Box where S: Subscribe,