Skip to content

Commit

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

This reverts commit a0824d3 (PR tokio-rs#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 tokio-rs#2269 and tokio-rs#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 authored and kaffarell committed May 22, 2024
1 parent ebeed8b commit 63b254d
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,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 @@ -260,66 +255,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 63b254d

Please sign in to comment.