Skip to content

Commit b21d236

Browse files
committed
subscriber: fix FmtLayer's auto traits inheriting S's (#2024)
Depends on #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]>
1 parent e856d8f commit b21d236

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

tracing-subscriber/src/fmt/fmt_layer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub struct Layer<
7070
fmt_event: E,
7171
fmt_span: format::FmtSpanConfig,
7272
is_ansi: bool,
73-
_inner: PhantomData<S>,
73+
_inner: PhantomData<fn(S)>,
7474
}
7575

7676
impl<S> Layer<S> {

tracing-subscriber/src/layer/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,10 @@
236236
//! }
237237
//!
238238
//! impl LogConfig {
239-
//! pub fn layer<C>(self) -> Box<dyn Layer<C> + Send + Sync + 'static>
239+
//! pub fn layer<S>(self) -> Box<dyn Layer<S> + Send + Sync + 'static>
240240
//! where
241-
//! C: tracing_core::Subscriber + Send + Sync,
242-
//! for<'a> C: LookupSpan<'a>,
241+
//! S: tracing_core::Subscriber,
242+
//! for<'a> S: LookupSpan<'a>,
243243
//! {
244244
//! // Shared configuration regardless of where logs are output to.
245245
//! let fmt = tracing_subscriber::fmt::layer()

0 commit comments

Comments
 (0)