Skip to content

Commit

Permalink
subscriber: fix FmtLayer's auto traits inheriting S's (tokio-rs#2024
Browse files Browse the repository at this point in the history
)

Depends on tokio-rs#2023

## Motivation

Currently, `FmtLayer` holds a `PhantomData<S>` with the `Subscriber`
type it wraps. This is unfortunate because it means that the
layer's auto traits such as `Send`, `Sync`, and `'static` (as well
as `UnwindSafe`, `Unpin`, etc) depend on the `Subscriber` type's auto
traits...but the layer will never actually _store_ a value of type
`S`. While all `Subscriber` will be `Send + Sync + 'static` in practice,
the `PhantomData` means that functions returning a boxed `FmtLayer`
must unnecessarily bound the subscriber type parameter.

## Solution

This commit changes the `PhantomData` to `PhantomData<fn(S)>`, solving
the problem.

Signed-off-by: Eliza Weisman <[email protected]>
  • Loading branch information
hawkw authored and kaffarell committed May 22, 2024
1 parent 3bd249d commit 8cbe3c5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tracing-subscriber/src/fmt/fmt_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub struct Layer<
fmt_event: E,
fmt_span: format::FmtSpanConfig,
is_ansi: bool,
_inner: PhantomData<S>,
_inner: PhantomData<fn(S)>,
}

impl<S> Layer<S> {
Expand Down
6 changes: 3 additions & 3 deletions tracing-subscriber/src/layer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@
//! }
//!
//! impl LogConfig {
//! pub fn layer<C>(self) -> Box<dyn Layer<C> + Send + Sync + 'static>
//! pub fn layer<S>(self) -> Box<dyn Layer<S> + Send + Sync + 'static>
//! where
//! C: tracing_core::Subscriber + Send + Sync,
//! for<'a> C: LookupSpan<'a>,
//! S: tracing_core::Subscriber,
//! for<'a> S: LookupSpan<'a>,
//! {
//! // Shared configuration regardless of where logs are output to.
//! let fmt = tracing_subscriber::fmt::layer()
Expand Down

0 comments on commit 8cbe3c5

Please sign in to comment.