Skip to content

Commit

Permalink
subscriber: remove Layer impls for Arcs (#1649)
Browse files Browse the repository at this point in the history
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
#1576 (comment) 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.
  • Loading branch information
davidbarsky authored and hawkw committed Mar 23, 2022
1 parent 0428412 commit 601bf67
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions tracing-subscriber/src/subscribe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1146,21 +1155,6 @@ macro_rules! layer_impl_body {
};
}

impl<S, C> Subscribe<C> for Arc<S>
where
S: Subscribe<C>,
C: Collect,
{
layer_impl_body! {}
}

impl<C> Subscribe<C> for Arc<dyn Subscribe<C>>
where
C: Collect,
{
layer_impl_body! {}
}

impl<S, C> Subscribe<C> for Box<S>
where
S: Subscribe<C>,
Expand Down

0 comments on commit 601bf67

Please sign in to comment.