Skip to content

Commit a1ce787

Browse files
hawkwdavidbarsky
authored andcommitted
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 b83a228 commit a1ce787

File tree

10 files changed

+98
-78
lines changed

10 files changed

+98
-78
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 & 4 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) 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 (but can be enabled explicitly).
331333
///
332334
/// # Example Output
333335
///
@@ -1086,8 +1088,12 @@ where
10861088

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

10931099
if self.display_filename {

tracing-subscriber/src/fmt/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ where
737737

738738
/// Sets the subscriber being built to use a less verbose formatter.
739739
///
740-
/// See [`format::Compact`].
740+
/// See [`format::Compact`] for details.
741741
pub fn compact(self) -> SubscriberBuilder<N, format::Format<format::Compact, T>, F, W>
742742
where
743743
N: for<'writer> FormatFields<'writer> + 'static,
@@ -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: 19 additions & 21 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
@@ -491,6 +490,21 @@ pub trait MakeWriterExt<'a>: MakeWriter<'a> {
491490
}
492491
}
493492

493+
/// A type implementing [`io::Write`] for a [`MutexGuard`] where the type
494+
/// inside the [`Mutex`] implements [`io::Write`].
495+
///
496+
/// This is used by the [`MakeWriter`] implementation for [`Mutex`], because
497+
/// [`MutexGuard`] itself will not implement [`io::Write`] — instead, it
498+
/// _dereferences_ to a type implementing [`io::Write`]. Because [`MakeWriter`]
499+
/// requires the `Writer` type to implement [`io::Write`], it's necessary to add
500+
/// a newtype that forwards the trait implementation.
501+
///
502+
/// [`MutexGuard`]: https://doc.rust-lang.org/std/sync/struct.MutexGuard.html
503+
/// [`Mutex`]: https://doc.rust-lang.org/std/sync/struct.Mutex.html
504+
/// [`MakeWriter`]: trait.MakeWriter.html
505+
#[derive(Debug)]
506+
pub struct MutexGuardWriter<'a, W>(MutexGuard<'a, W>);
507+
494508
/// A writer intended to support [`libtest`'s output capturing][capturing] for use in unit tests.
495509
///
496510
/// `TestWriter` is used by [`fmt::Subscriber`] or [`fmt::Layer`] to enable capturing support.
@@ -538,13 +552,12 @@ pub struct TestWriter {
538552
/// ```
539553
///
540554
/// [`Subscriber`]: tracing::Subscriber
541-
/// [`io::Write`]: std::io::Write
542555
pub struct BoxMakeWriter {
543556
inner: Box<dyn for<'a> MakeWriter<'a, Writer = Box<dyn Write + 'a>> + Send + Sync>,
544557
name: &'static str,
545558
}
546559

547-
/// A [writer] that is one of two types implementing [`io::Write`][writer].
560+
/// A [writer] that is one of two types implementing [`io::Write`].
548561
///
549562
/// This may be used by [`MakeWriter`] implementations that may conditionally
550563
/// return one of two writers.
@@ -637,21 +650,6 @@ pub struct Tee<A, B> {
637650
b: B,
638651
}
639652

640-
/// A type implementing [`io::Write`] for a [`MutexGuard`] where the type
641-
/// inside the [`Mutex`] implements [`io::Write`].
642-
///
643-
/// This is used by the [`MakeWriter`] implementation for [`Mutex`], because
644-
/// [`MutexGuard`] itself will not implement [`io::Write`] — instead, it
645-
/// _dereferences_ to a type implementing [`io::Write`]. Because [`MakeWriter`]
646-
/// requires the `Writer` type to implement [`io::Write`], it's necessary to add
647-
/// a newtype that forwards the trait implementation.
648-
///
649-
/// [`io::Write`]: std::io::Write
650-
/// [`MutexGuard`]: std::sync::MutexGuard
651-
/// [`Mutex`]: std::sync::Mutex
652-
#[derive(Debug)]
653-
pub struct MutexGuardWriter<'a, W>(MutexGuard<'a, W>);
654-
655653
/// Implements [`std::io::Write`] for an [`Arc`]<W> where `&W: Write`.
656654
///
657655
/// This is an implementation detail of the [`MakeWriter`] impl for [`Arc`].

tracing-subscriber/src/layer/mod.rs

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,38 +1397,37 @@ feature! {
13971397
true
13981398
}
13991399

1400-
/// Returns an optional hint of the highest [verbosity level][level] that
1401-
/// this `Filter` will enable.
1402-
///
1403-
/// If this method returns a [`LevelFilter`], it will be used as a hint to
1404-
/// determine the most verbose level that will be enabled. This will allow
1405-
/// spans and events which are more verbose than that level to be skipped
1406-
/// more efficiently. An implementation of this method is optional, but
1407-
/// strongly encouraged.
1408-
///
1409-
/// If the maximum level the `Filter` will enable can change over the
1410-
/// course of its lifetime, it is free to return a different value from
1411-
/// multiple invocations of this method. However, note that changes in the
1412-
/// maximum level will **only** be reflected after the callsite [`Interest`]
1413-
/// cache is rebuilt, by calling the
1414-
/// [`tracing_core::callsite::rebuild_interest_cache`][rebuild] function.
1415-
/// Therefore, if the `Filter will change the value returned by this
1416-
/// method, it is responsible for ensuring that
1417-
/// [`rebuild_interest_cache`][rebuild] is called after the value of the max
1418-
/// level changes.
1419-
///
1420-
/// ## Default Implementation
1421-
///
1422-
/// By default, this method returns `None`, indicating that the maximum
1423-
/// level is unknown.
1424-
///
1425-
/// [level]: tracing_core::metadata::Level
1426-
/// [`LevelFilter`]: crate::filter::LevelFilter
1427-
/// [`Interest`]: tracing_core::subscriber::Interest
1428-
/// [rebuild]: tracing_core::callsite::rebuild_interest_cache
1429-
fn max_level_hint(&self) -> Option<LevelFilter> {
1430-
None
1431-
}
1400+
/// Returns an optional hint of the highest [verbosity level][level] that
1401+
/// this `Filter` will enable.
1402+
///
1403+
/// If this method returns a [`LevelFilter`], it will be used as a hint to
1404+
/// determine the most verbose level that will be enabled. This will allow
1405+
/// spans and events which are more verbose than that level to be skipped
1406+
/// more efficiently. An implementation of this method is optional, but
1407+
/// strongly encouraged.
1408+
///
1409+
/// If the maximum level the `Filter` will enable can change over the
1410+
/// course of its lifetime, it is free to return a different value from
1411+
/// multiple invocations of this method. However, note that changes in the
1412+
/// maximum level will **only** be reflected after the callsite [`Interest`]
1413+
/// cache is rebuilt, by calling the
1414+
/// [`tracing_core::callsite::rebuild_interest_cache`] function.
1415+
/// Therefore, if the `Filter will change the value returned by this
1416+
/// method, it is responsible for ensuring that [`rebuild_interest_cache`]
1417+
/// is called after the value of the max level changes.
1418+
///
1419+
/// ## Default Implementation
1420+
///
1421+
/// By default, this method returns `None`, indicating that the maximum
1422+
/// level is unknown.
1423+
///
1424+
/// [level]: tracing_core::metadata::Level
1425+
/// [`LevelFilter`]: crate::filter::LevelFilter
1426+
/// [`Interest`]: tracing_core::subscriber::Interest
1427+
/// [`rebuild_interest_cache`]: tracing_core::callsite::rebuild_interest_cache
1428+
fn max_level_hint(&self) -> Option<LevelFilter> {
1429+
None
1430+
}
14321431

14331432
/// Notifies this filter that a new span was constructed with the given
14341433
/// `Attributes` and `Id`.

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)