mirror of
https://github.com/tokio-rs/tracing.git
synced 2025-10-02 15:24:47 +00:00
subscriber: mark builders as must_use (#2239)
## Motivation Builders not marked `#[must_use]` can not be initialized sometimes, causing silent failures. Eg. ```rust fn main() { tracing_subscriber::fmt(); tracing::info!("hello"); } ``` won't print anything. ## Solution Added `#[must_use]` to builder types in the tracing-subscriber crate.
This commit is contained in:
parent
522437d51c
commit
1b89aa950a
1
tracing-subscriber/src/filter/env/builder.rs
vendored
1
tracing-subscriber/src/filter/env/builder.rs
vendored
@ -11,6 +11,7 @@ use tracing::level_filters::STATIC_MAX_LEVEL;
|
|||||||
///
|
///
|
||||||
/// [builder]: https://rust-unofficial.github.io/patterns/patterns/creational/builder.html
|
/// [builder]: https://rust-unofficial.github.io/patterns/patterns/creational/builder.html
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
#[must_use]
|
||||||
pub struct Builder {
|
pub struct Builder {
|
||||||
regex: bool,
|
regex: bool,
|
||||||
env: Option<String>,
|
env: Option<String>,
|
||||||
|
@ -243,6 +243,7 @@ pub type Formatter<
|
|||||||
/// Configures and constructs `Subscriber`s.
|
/// Configures and constructs `Subscriber`s.
|
||||||
#[cfg_attr(docsrs, doc(cfg(all(feature = "fmt", feature = "std"))))]
|
#[cfg_attr(docsrs, doc(cfg(all(feature = "fmt", feature = "std"))))]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[must_use]
|
||||||
pub struct SubscriberBuilder<
|
pub struct SubscriberBuilder<
|
||||||
N = format::DefaultFields,
|
N = format::DefaultFields,
|
||||||
E = format::Format<format::Full>,
|
E = format::Format<format::Full>,
|
||||||
@ -465,7 +466,8 @@ impl Default for SubscriberBuilder {
|
|||||||
SubscriberBuilder {
|
SubscriberBuilder {
|
||||||
filter: Subscriber::DEFAULT_MAX_LEVEL,
|
filter: Subscriber::DEFAULT_MAX_LEVEL,
|
||||||
inner: Default::default(),
|
inner: Default::default(),
|
||||||
}.log_internal_errors(true)
|
}
|
||||||
|
.log_internal_errors(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -631,7 +633,10 @@ where
|
|||||||
/// as a fallback.
|
/// as a fallback.
|
||||||
///
|
///
|
||||||
/// [`FormatEvent`]: crate::fmt::FormatEvent
|
/// [`FormatEvent`]: crate::fmt::FormatEvent
|
||||||
pub fn log_internal_errors(self, log_internal_errors: bool) -> SubscriberBuilder<N, format::Format<L, T>, F, W> {
|
pub fn log_internal_errors(
|
||||||
|
self,
|
||||||
|
log_internal_errors: bool,
|
||||||
|
) -> SubscriberBuilder<N, format::Format<L, T>, F, W> {
|
||||||
SubscriberBuilder {
|
SubscriberBuilder {
|
||||||
inner: self.inner.log_internal_errors(log_internal_errors),
|
inner: self.inner.log_internal_errors(log_internal_errors),
|
||||||
..self
|
..self
|
||||||
|
Loading…
x
Reference in New Issue
Block a user