Skip to content

Commit

Permalink
subscriber: fix FmtSubscriber's auto traits inheriting Cs (#2024)
Browse files Browse the repository at this point in the history
Depends on #2023 

## Motivation

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

## Solution

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

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
  • Loading branch information
hawkw authored Mar 25, 2022
1 parent 6a6383a commit c1de498
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tracing-subscriber/src/fmt/fmt_subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub struct Subscriber<C, N = format::DefaultFields, E = format::Format, W = fn()
fmt_event: E,
fmt_span: format::FmtSpanConfig,
is_ansi: bool,
_inner: PhantomData<C>,
_inner: PhantomData<fn(C)>,
}

impl<C> Subscriber<C> {
Expand Down
2 changes: 1 addition & 1 deletion tracing-subscriber/src/subscribe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
//! impl LogConfig {
//! pub fn subscriber<C>(self) -> Box<dyn Subscribe<C> + Send + Sync + 'static>
//! where
//! C: tracing_core::Collect + Send + Sync,
//! C: tracing_core::Collect,
//! for<'a> C: LookupSpan<'a>,
//! {
//! // Shared configuration regardless of where logs are output to.
Expand Down

0 comments on commit c1de498

Please sign in to comment.