Skip to content

Commit

Permalink
subscriber: revert "impl LookupSpan for Box<LS> and Arc<LS> (#2247
Browse files Browse the repository at this point in the history
)"

This reverts commit a0824d3 (PR #2247).
As discussed in [this comment][1], the implementation for `Arc`s may
cause subtly incorrect behavior if actually used, due to the `&mut self`
receiver of the `LookupSpan::register_filter` method, since the `Arc`
cannot be mutably borrowed if any clones of it exist.

The APIs added in PRs #2269 and #2293 offer an alternative solution to
the same problems this change was intended to solve, and --- since this
change hasn't been published yet --- it can safely be reverted.

[1]:
    https://giethub.com/tokio-rs/tracing/pull/2247#issuecomment-1199924876
  • Loading branch information
hawkw committed Oct 6, 2022
1 parent 8e35927 commit a4fc92c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 66 deletions.
4 changes: 3 additions & 1 deletion tracing-subscriber/src/layer/mod.rs
Expand Up @@ -685,7 +685,7 @@ use core::any::TypeId;

feature! {
#![feature = "alloc"]
use alloc::{vec::Vec, boxed::Box};
use alloc::boxed::Box;
use core::ops::{Deref, DerefMut};
}

Expand Down Expand Up @@ -1656,6 +1656,8 @@ where

feature! {
#![any(feature = "std", feature = "alloc")]
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

macro_rules! layer_impl_body {
() => {
Expand Down
65 changes: 0 additions & 65 deletions tracing-subscriber/src/registry/mod.rs
Expand Up @@ -230,11 +230,6 @@ pub struct Scope<'a, R> {
feature! {
#![any(feature = "alloc", feature = "std")]

use alloc::{
boxed::Box,
sync::Arc
};

#[cfg(not(feature = "smallvec"))]
use alloc::vec::{self, Vec};

Expand All @@ -256,66 +251,6 @@ feature! {
#[cfg(feature = "smallvec")]
type SpanRefVecArray<'span, L> = [SpanRef<'span, L>; 16];

impl<'a, S> LookupSpan<'a> for Arc<S>
where
S: LookupSpan<'a>,
{
type Data = <S as LookupSpan<'a>>::Data;

fn span_data(&'a self, id: &Id) -> Option<Self::Data> {
self.as_ref().span_data(id)
}

fn span(&'a self, id: &Id) -> Option<SpanRef<'_, Self>>
where
Self: Sized,
{
self.as_ref().span(id).map(
|SpanRef {
registry: _,
data,
#[cfg(feature = "registry")]
filter,
}| SpanRef {
registry: self,
data,
#[cfg(feature = "registry")]
filter,
},
)
}
}

impl<'a, S> LookupSpan<'a> for Box<S>
where
S: LookupSpan<'a>,
{
type Data = <S as LookupSpan<'a>>::Data;

fn span_data(&'a self, id: &Id) -> Option<Self::Data> {
self.as_ref().span_data(id)
}

fn span(&'a self, id: &Id) -> Option<SpanRef<'_, Self>>
where
Self: Sized,
{
self.as_ref().span(id).map(
|SpanRef {
registry: _,
data,
#[cfg(feature = "registry")]
filter,
}| SpanRef {
registry: self,
data,
#[cfg(feature = "registry")]
filter,
},
)
}
}

impl<'a, R> Scope<'a, R>
where
R: LookupSpan<'a>,
Expand Down

0 comments on commit a4fc92c

Please sign in to comment.