Skip to content

Commit e03a831

Browse files
committed
chore: fix new warnings in Rust 1.72.0 (#2700)
This branch fixes a handful of new warnings which have shown up after updating to Rust 1.72.0. This includes: * `clippy::redundant_closure_call` in macros --- allowed because the macro sometimes calls a function that isn't a closure, and the closure is just used in the case where it's not a function. * Unnecessary uses of `#` in raw string literals that don't contain `"` characters. * Dead code warnings with specific feature flag combinations in `tracing-subscriber`. In addition, I've fixed a broken RustDoc link that was making the Netlify build sad.
1 parent 72bbf0f commit e03a831

File tree

9 files changed

+51
-28
lines changed

9 files changed

+51
-28
lines changed

netlify.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
[build.environment]
99
RUSTDOCFLAGS="""
1010
-D warnings \
11+
--force-warn rustdoc::redundant-explicit-links \
1112
--force-warn renamed-and-removed-lints \
1213
--cfg docsrs \
1314
--cfg tracing_unstable

tracing-core/src/field.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,10 @@ macro_rules! impl_one_value {
470470
impl $crate::sealed::Sealed for $value_ty {}
471471
impl $crate::field::Value for $value_ty {
472472
fn record(&self, key: &$crate::field::Field, visitor: &mut dyn $crate::field::Visit) {
473+
// `op` is always a function; the closure is used because
474+
// sometimes there isn't a real function corresponding to that
475+
// operation. the clippy warning is not that useful here.
476+
#[allow(clippy::redundant_closure_call)]
473477
visitor.$record(key, $op(*self))
474478
}
475479
}
@@ -485,6 +489,10 @@ macro_rules! impl_one_value {
485489
impl $crate::sealed::Sealed for ty_to_nonzero!($value_ty) {}
486490
impl $crate::field::Value for ty_to_nonzero!($value_ty) {
487491
fn record(&self, key: &$crate::field::Field, visitor: &mut dyn $crate::field::Visit) {
492+
// `op` is always a function; the closure is used because
493+
// sometimes there isn't a real function corresponding to that
494+
// operation. the clippy warning is not that useful here.
495+
#[allow(clippy::redundant_closure_call)]
488496
visitor.$record(key, $op(self.get()))
489497
}
490498
}

tracing-subscriber/src/field/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub trait VisitOutput<Out>: Visit {
5555
/// Extension trait implemented by types which can be recorded by a [visitor].
5656
///
5757
/// This allows writing code that is generic over `tracing_core`'s
58-
/// [`span::Attributes`][attr], [`span::Record`][rec], and [`Event`][event]
58+
/// [`span::Attributes`][attr], [`span::Record`][rec], and [`Event`]
5959
/// types. These types all provide inherent `record` methods that allow a
6060
/// visitor to record their fields, but there is no common trait representing this.
6161
///
@@ -85,7 +85,6 @@ pub trait VisitOutput<Out>: Visit {
8585
/// [visitor]: tracing_core::field::Visit
8686
/// [attr]: tracing_core::span::Attributes
8787
/// [rec]: tracing_core::span::Record
88-
/// [event]: tracing_core::event::Event
8988
pub trait RecordFields: crate::sealed::Sealed<RecordFieldsMarker> {
9089
/// Record all the fields in `self` with the provided `visitor`.
9190
fn record(&self, visitor: &mut dyn Visit);

tracing-subscriber/src/filter/directive.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ enum ParseErrorKind {
4949
// === impl DirectiveSet ===
5050

5151
impl<T> DirectiveSet<T> {
52-
#[cfg(feature = "env-filter")]
52+
// this is only used by `env-filter`.
53+
#[cfg(all(feature = "std", feature = "env-filter"))]
5354
pub(crate) fn is_empty(&self) -> bool {
5455
self.directives.is_empty()
5556
}
@@ -397,7 +398,7 @@ impl FromStr for StaticDirective {
397398
// === impl ParseError ===
398399

399400
impl ParseError {
400-
#[cfg(feature = "env-filter")]
401+
#[cfg(all(feature = "std", feature = "env-filter"))]
401402
pub(crate) fn new() -> Self {
402403
ParseError {
403404
kind: ParseErrorKind::Other(None),

tracing-subscriber/src/filter/env/directive.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ impl Directive {
120120
}
121121

122122
pub(super) fn parse(from: &str, regex: bool) -> Result<Self, ParseError> {
123-
static DIRECTIVE_RE: Lazy<Regex> = Lazy::new(|| Regex::new(
124-
r"(?x)
123+
static DIRECTIVE_RE: Lazy<Regex> = Lazy::new(|| {
124+
Regex::new(
125+
r"(?x)
125126
^(?P<global_level>(?i:trace|debug|info|warn|error|off|[0-5]))$ |
126127
# ^^^.
127128
# `note: we match log level names case-insensitively
@@ -135,15 +136,18 @@ impl Directive {
135136
# `note: we match log level names case-insensitively
136137
)?
137138
$
138-
"
139-
)
140-
.unwrap());
139+
",
140+
)
141+
.unwrap()
142+
});
141143
static SPAN_PART_RE: Lazy<Regex> =
142-
Lazy::new(|| Regex::new(r#"(?P<name>[^\]\{]+)?(?:\{(?P<fields>[^\}]*)\})?"#).unwrap());
144+
Lazy::new(|| Regex::new(r"(?P<name>[^\]\{]+)?(?:\{(?P<fields>[^\}]*)\})?").unwrap());
143145
static FIELD_FILTER_RE: Lazy<Regex> =
144146
// TODO(eliza): this doesn't _currently_ handle value matchers that include comma
145147
// characters. We should fix that.
146-
Lazy::new(|| Regex::new(r#"(?x)
148+
Lazy::new(|| {
149+
Regex::new(
150+
r"(?x)
147151
(
148152
# field name
149153
[[:word:]][[[:word:]]\.]*
@@ -152,7 +156,10 @@ impl Directive {
152156
)
153157
# trailing comma or EOS
154158
(?:,\s?|$)
155-
"#).unwrap());
159+
",
160+
)
161+
.unwrap()
162+
});
156163

157164
let caps = DIRECTIVE_RE.captures(from).ok_or_else(ParseError::new)?;
158165

tracing-subscriber/src/fmt/format/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,10 @@ pub struct FieldFnVisitor<'a, F> {
326326
/// Marker for [`Format`] that indicates that the compact log format should be used.
327327
///
328328
/// The compact format includes fields from all currently entered spans, after
329-
/// the event's fields. Span names are listed in order before fields are
330-
/// displayed.
329+
/// the event's fields. Span fields are ordered (but not grouped) by
330+
/// span, and span names are not shown. A more compact representation of the
331+
/// event's [`Level`] is used, and additional information—such as the event's
332+
/// target—is disabled by default.
331333
///
332334
/// # Example Output
333335
///
@@ -1086,7 +1088,12 @@ where
10861088

10871089
let mut needs_space = false;
10881090
if self.display_target {
1089-
write!(writer, "{}{}", dimmed.paint(meta.target()), dimmed.paint(":"))?;
1091+
write!(
1092+
writer,
1093+
"{}{}",
1094+
dimmed.paint(meta.target()),
1095+
dimmed.paint(":")
1096+
)?;
10901097
needs_space = true;
10911098
}
10921099

tracing-subscriber/src/fmt/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ where
762762

763763
/// Sets the subscriber being built to use a JSON formatter.
764764
///
765-
/// See [`format::Json`][super::fmt::format::Json]
765+
/// See [`format::Json`] for details.
766766
#[cfg(feature = "json")]
767767
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
768768
pub fn json(
@@ -783,7 +783,7 @@ where
783783
impl<T, F, W> SubscriberBuilder<format::JsonFields, format::Format<format::Json, T>, F, W> {
784784
/// Sets the json subscriber being built to flatten event metadata.
785785
///
786-
/// See [`format::Json`][super::fmt::format::Json]
786+
/// See [`format::Json`] for details.
787787
pub fn flatten_event(
788788
self,
789789
flatten_event: bool,
@@ -797,7 +797,7 @@ impl<T, F, W> SubscriberBuilder<format::JsonFields, format::Format<format::Json,
797797
/// Sets whether or not the JSON subscriber being built will include the current span
798798
/// in formatted events.
799799
///
800-
/// See [`format::Json`][super::fmt::format::Json]
800+
/// See [`format::Json`] for details.
801801
pub fn with_current_span(
802802
self,
803803
display_current_span: bool,
@@ -811,7 +811,7 @@ impl<T, F, W> SubscriberBuilder<format::JsonFields, format::Format<format::Json,
811811
/// Sets whether or not the JSON subscriber being built will include a list (from
812812
/// root to leaf) of all currently entered spans in formatted events.
813813
///
814-
/// See [`format::Json`][super::fmt::format::Json]
814+
/// See [`format::Json`] for details.
815815
pub fn with_span_list(
816816
self,
817817
display_span_list: bool,
@@ -1304,6 +1304,9 @@ mod test {
13041304
Self { buf }
13051305
}
13061306

1307+
// this is currently only used by the JSON formatter tests. if we need
1308+
// it elsewhere in the future, feel free to remove the `#[cfg]`
1309+
// attribute!
13071310
#[cfg(feature = "json")]
13081311
pub(crate) fn buf(&self) -> MutexGuard<'_, Vec<u8>> {
13091312
self.buf.lock().unwrap()

tracing-subscriber/src/fmt/writer.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use tracing_core::Metadata;
1616
/// This trait is already implemented for function pointers and
1717
/// immutably-borrowing closures that return an instance of [`io::Write`], such
1818
/// as [`io::stdout`] and [`io::stderr`]. Additionally, it is implemented for
19-
/// [`std::sync::Mutex`][mutex] when the type inside the mutex implements
19+
/// [`std::sync::Mutex`] when the type inside the mutex implements
2020
/// [`io::Write`].
2121
///
2222
/// # Examples
@@ -66,7 +66,7 @@ use tracing_core::Metadata;
6666
/// ```
6767
///
6868
/// A single instance of a type implementing [`io::Write`] may be used as a
69-
/// `MakeWriter` by wrapping it in a [`Mutex`][mutex]. For example, we could
69+
/// `MakeWriter` by wrapping it in a [`Mutex`]. For example, we could
7070
/// write to a file like so:
7171
///
7272
/// ```
@@ -88,7 +88,6 @@ use tracing_core::Metadata;
8888
/// [`Event`]: tracing_core::event::Event
8989
/// [`io::stdout`]: std::io::stdout()
9090
/// [`io::stderr`]: std::io::stderr()
91-
/// [mutex]: std::sync::Mutex
9291
/// [`MakeWriter::make_writer_for`]: MakeWriter::make_writer_for
9392
/// [`Metadata`]: tracing_core::Metadata
9493
/// [levels]: tracing_core::Level
@@ -325,7 +324,7 @@ pub trait MakeWriterExt<'a>: MakeWriter<'a> {
325324

326325
/// Wraps `self` with a predicate that takes a span or event's [`Metadata`]
327326
/// and returns a `bool`. The returned [`MakeWriter`]'s
328-
/// [`MakeWriter::make_writer_for`][mwf] method will check the predicate to
327+
/// [`MakeWriter::make_writer_for`] method will check the predicate to
329328
/// determine if a writer should be produced for a given span or event.
330329
///
331330
/// If the predicate returns `false`, the wrapped [`MakeWriter`]'s
@@ -544,7 +543,7 @@ pub struct BoxMakeWriter {
544543
name: &'static str,
545544
}
546545

547-
/// A [writer] that is one of two types implementing [`io::Write`][writer].
546+
/// A [writer] that is one of two types implementing [`io::Write`].
548547
///
549548
/// This may be used by [`MakeWriter`] implementations that may conditionally
550549
/// return one of two writers.

tracing-subscriber/src/registry/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,9 @@ pub trait SpanData<'a> {
200200

201201
/// A reference to [span data] and the associated [registry].
202202
///
203-
/// This type implements all the same methods as [`SpanData`][span data], and
204-
/// provides additional methods for querying the registry based on values from
205-
/// the span.
203+
/// This type implements all the same methods as [`SpanData`], and provides
204+
/// additional methods for querying the registry based on values from the span.
206205
///
207-
/// [span data]: SpanData
208206
/// [registry]: LookupSpan
209207
#[derive(Debug)]
210208
pub struct SpanRef<'a, R: LookupSpan<'a>> {

0 commit comments

Comments
 (0)