Skip to content

Commit

Permalink
subscriber: add must_use for CollectorBuilder::finish (#2271)
Browse files Browse the repository at this point in the history
## Motivation

Follow up to #2239.

Discovered that

```rust
    tracing_subscriber::fmt().with_ansi(false).finish();
    tracing::info!("hello");
```
doesn't actually do anything, because `finish` returns a `Collector` and
`init` is the thing that actually installs the collector.

## Solution

Added `#[must_use]` which suggests using `try_init` instead.
  • Loading branch information
DesmondWillowbrook committed Aug 10, 2022
1 parent 1b2a054 commit 9a8e7e6
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions tracing-subscriber/src/fmt/mod.rs
Expand Up @@ -476,6 +476,7 @@ where
subscribe::Subscribe<Registry> + Send + Sync + 'static,
{
/// Finish the builder, returning a new `FmtCollector`.
#[must_use = "you may want to use `try_init` or similar to actually install the collector."]
pub fn finish(self) -> Collector<N, E, F, W> {
let collector = self.inner.with_collector(Registry::default());
Collector {
Expand Down

0 comments on commit 9a8e7e6

Please sign in to comment.