Skip to content

with_timer() doesn't put bound on argument, causes bad error messages if it's not FormatTime #1846

@lilyball

Description

@lilyball

Bug Report

Version

└── tracing-core v0.1.21
├── tracing v0.1.29
│   ├── tracing-attributes v0.1.18 (proc-macro)
│   └── tracing-core v0.1.21 (*)
└── tracing-subscriber v0.3.6
    ├── tracing-core v0.1.21 (*)
    └── tracing-log v0.1.2
        └── tracing-core v0.1.21 (*)

Platform

Darwin DeerBook 21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:54 PST 2021; root:xnu-8019.61.5~1/RELEASE_X86_64 x86_64

Crates

tracing-subscriber

Description

The various with_timer() methods take a completely unbounded generic parameter. Similarly the Format type puts no restrictions on its T generic parameter. What it does do is bound its implementations of FormatEvent on T: FormatTime.

The problem here is that I get bad error messages if I pass something that's not FormatTime. I get told that Format doesn't satisfy FormatEvent, but rather than telling me it's due to the T parameter it goes on to complain about LevelFilter not satisfying tracing_subscriber::layer::Layer<Layered<tracing_subscriber::fmt::Layer<Registry, DefaultFields, tracing_subscriber::fmt::format::Format<Compact, T>>, Registry>>. It also complains that tracing_subscriber::fmt::Layer<…> doesn't satisfy tracing_subscriber::layer::Layer<Registry>.

This is all a mess, and it has to be due to my T type not being FormatTime. This is especially annoying because I'm attempting to use the impl on fn(&mut Writer<'_>) and there's probably some lifetime issue. If with_timer() actually put the FormatTime bound on the parameter then I'd get a much more useful error.

I don't understand why it doesn't have this bound. The Format type only exists for its FormatEvent impls and so it should not offer a way of configuring it that disables that impl. For comparison, the SubscriberBuilder::event_format(), fmt_fields(), and with_writer() methods put bounds on their arguments, so the lack of such a bound on with_timer() is inconsistent. It also makes it much harder to figure out what the actual requirement on that type is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    crate/subscriberRelated to the `tracing-subscriber` cratekind/bugSomething isn't workingmeta/breakingThis is a breaking change, and should wait until the next breaking release.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions