Skip to content

Commit

Permalink
chore: fix nightly clippy warnings (#991) (#1025)
Browse files Browse the repository at this point in the history
This backports PR #991 to v0.1.x. This is primarily necessary for the MSRV
bump, since some dependencies no longer compile on Rust 1.40.0.

This has already been approved on `master`, in PR #991, so it should be 
fine to ship.

## Motivation

This will avoid breaking CI on new releases of clippy. It also makes the
code a little easier to read.

## Solution

- Convert `match val { pat => true, _ => false }` to `matches!(val, pat)`
- Remove unnecessary closures
- Convert `self: &mut Self` to `&mut self`

This bumps the MSRV to 1.42.0 for `matches!`.
The latest version of rust is 1.46.0, so as per
https://github.com/tokio-rs/tracing#supported-rust-versions this is not
considered a breaking change.

I didn't fix the following warning because the fix was not trivial/needed
a decision:

```
warning: you are deriving `Ord` but have implemented `PartialOrd` explicitly
   --> tracing-subscriber/src/filter/env/field.rs:16:32
    |
16  | #[derive(Debug, Eq, PartialEq, Ord)]
    |                                ^^^
    |
    = note: `#[warn(clippy::derive_ord_xor_partial_ord)]` on by default
note: `PartialOrd` implemented here
   --> tracing-subscriber/src/filter/env/field.rs:98:1
    |
98  | / impl PartialOrd for Match {
99  | |     fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
100 | |         // Ordering for `Match` directives is based first on _whether_ a value
101 | |         // is matched or not. This is semantically meaningful --- we would
...   |
121 | |     }
122 | | }
    | |_^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#derive_ord_xor_partial_ord
```

As a side note, this found a bug in clippy 😆 rust-lang/rust-clippy#6089
  • Loading branch information
hawkw authored Oct 7, 2020
1 parent a14ff8d commit 4b54cbc
Show file tree
Hide file tree
Showing 34 changed files with 71 additions and 123 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
rust: [stable, 1.40.0]
rust: [stable, 1.42.0]
steps:
- uses: actions/checkout@main
- uses: actions-rs/toolchain@v1
Expand Down Expand Up @@ -145,7 +145,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
rust: [stable, beta, nightly, 1.40.0]
rust: [stable, beta, nightly, 1.42.0]
steps:
- uses: actions/checkout@main
- uses: actions-rs/toolchain@v1
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ attachment that `Future::instrument` does.
## Supported Rust Versions

Tracing is built against the latest stable release. The minimum supported
version is 1.40. The current Tracing version is not guaranteed to build on Rust
version is 1.42. The current Tracing version is not guaranteed to build on Rust
versions earlier than the minimum supported version.

Tracing follows the same compiler support policies as the rest of the Tokio
Expand Down
4 changes: 2 additions & 2 deletions tracing-appender/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ allows events and spans to be recorded in a non-blocking manner through a
dedicated logging thread. It also provides a [`RollingFileAppender`][file_appender]
that can be used with _or_ without the non-blocking writer.

*Compiler support: [requires `rustc` 1.40+][msrv]*
*Compiler support: [requires `rustc` 1.42+][msrv]*

[msrv]: #supported-rust-versions

Expand Down Expand Up @@ -146,7 +146,7 @@ fn main() {
## Supported Rust Versions

Tracing is built against the latest stable release. The minimum supported
version is 1.40. The current Tracing version is not guaranteed to build on Rust
version is 1.42. The current Tracing version is not guaranteed to build on Rust
versions earlier than the minimum supported version.

Tracing follows the same compiler support policies as the rest of the Tokio
Expand Down
4 changes: 2 additions & 2 deletions tracing-appender/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! a dedicated logging thread. It also provides a [`RollingFileAppender`][file_appender] that can
//! be used with _or_ without the non-blocking writer.
//!
//! *Compiler support: [requires `rustc` 1.40+][msrv]*
//! *Compiler support: [requires `rustc` 1.42+][msrv]*
//!
//! [msrv]: #supported-rust-versions
//! [file_appender]: ./rolling/struct.RollingFileAppender.html
Expand Down Expand Up @@ -111,7 +111,7 @@
//! ## Supported Rust Versions
//!
//! Tracing is built against the latest stable release. The minimum supported
//! version is 1.40. The current Tracing version is not guaranteed to build on
//! version is 1.42. The current Tracing version is not guaranteed to build on
//! Rust versions earlier than the minimum supported version.
//!
//! Tracing follows the same compiler support policies as the rest of the Tokio
Expand Down
4 changes: 2 additions & 2 deletions tracing-attributes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ structured, event-based diagnostic information. This crate provides the

Note that this macro is also re-exported by the main `tracing` crate.

*Compiler support: [requires `rustc` 1.40+][msrv]*
*Compiler support: [requires `rustc` 1.42+][msrv]*

[msrv]: #supported-rust-versions

Expand Down Expand Up @@ -69,7 +69,7 @@ pub fn my_function(my_arg: usize) {
## Supported Rust Versions

Tracing is built against the latest stable release. The minimum supported
version is 1.40. The current Tracing version is not guaranteed to build on Rust
version is 1.42. The current Tracing version is not guaranteed to build on Rust
versions earlier than the minimum supported version.

Tracing follows the same compiler support policies as the rest of the Tokio
Expand Down
4 changes: 2 additions & 2 deletions tracing-attributes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//!
//! Note that this macro is also re-exported by the main `tracing` crate.
//!
//! *Compiler support: [requires `rustc` 1.40+][msrv]*
//! *Compiler support: [requires `rustc` 1.42+][msrv]*
//!
//! [msrv]: #supported-rust-versions
//!
Expand Down Expand Up @@ -41,7 +41,7 @@
//! ## Supported Rust Versions
//!
//! Tracing is built against the latest stable release. The minimum supported
//! version is 1.40. The current Tracing version is not guaranteed to build on
//! version is 1.42. The current Tracing version is not guaranteed to build on
//! Rust versions earlier than the minimum supported version.
//!
//! Tracing follows the same compiler support policies as the rest of the Tokio
Expand Down
2 changes: 1 addition & 1 deletion tracing-attributes/tests/async_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ fn async_fn_with_async_trait_and_fields_expressions_with_generic_parameter() {
async fn call_with_self(&self) {}

#[instrument(fields(Self=std::any::type_name::<Self>()))]
async fn call_with_mut_self(self: &mut Self) {}
async fn call_with_mut_self(&mut self) {}
}

//let span = span::mock().named("call");
Expand Down
4 changes: 2 additions & 2 deletions tracing-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ The crate provides:
In addition, it defines the global callsite registry and per-thread current
dispatcher which other components of the tracing system rely on.

*Compiler support: [requires `rustc` 1.40+][msrv]*
*Compiler support: [requires `rustc` 1.42+][msrv]*

[msrv]: #supported-rust-versions

Expand Down Expand Up @@ -99,7 +99,7 @@ The following crate feature flags are available:
## Supported Rust Versions

Tracing is built against the latest stable release. The minimum supported
version is 1.40. The current Tracing version is not guaranteed to build on Rust
version is 1.42. The current Tracing version is not guaranteed to build on Rust
versions earlier than the minimum supported version.

Tracing follows the same compiler support policies as the rest of the Tokio
Expand Down
10 changes: 2 additions & 8 deletions tracing-core/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ impl<'a> Event<'a> {

/// Returns true if the new event should be a root.
pub fn is_root(&self) -> bool {
match self.parent {
Parent::Root => true,
_ => false,
}
matches!(self.parent, Parent::Root)
}

/// Returns true if the new event's parent should be determined based on the
Expand All @@ -115,10 +112,7 @@ impl<'a> Event<'a> {
/// thread is _not_ inside a span, then the new event will be the root of its
/// own trace tree.
pub fn is_contextual(&self) -> bool {
match self.parent {
Parent::Current => true,
_ => false,
}
matches!(self.parent, Parent::Current)
}

/// Returns the new event's explicitly-specified parent, if there is one.
Expand Down
4 changes: 2 additions & 2 deletions tracing-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//! In addition, it defines the global callsite registry and per-thread current
//! dispatcher which other components of the tracing system rely on.
//!
//! *Compiler support: [requires `rustc` 1.40+][msrv]*
//! *Compiler support: [requires `rustc` 1.42+][msrv]*
//!
//! [msrv]: #supported-rust-versions
//!
Expand Down Expand Up @@ -61,7 +61,7 @@
//! ## Supported Rust Versions
//!
//! Tracing is built against the latest stable release. The minimum supported
//! version is 1.40. The current Tracing version is not guaranteed to build on
//! version is 1.42. The current Tracing version is not guaranteed to build on
//! Rust versions earlier than the minimum supported version.
//!
//! Tracing follows the same compiler support policies as the rest of the Tokio
Expand Down
12 changes: 3 additions & 9 deletions tracing-core/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,12 @@ impl Kind {

/// Return true if the callsite kind is `Span`
pub fn is_span(&self) -> bool {
match self {
Kind(KindInner::Span) => true,
_ => false,
}
matches!(self, Kind(KindInner::Span))
}

/// Return true if the callsite kind is `Event`
pub fn is_event(&self) -> bool {
match self {
Kind(KindInner::Event) => true,
_ => false,
}
matches!(self, Kind(KindInner::Event))
}
}

Expand Down Expand Up @@ -554,7 +548,7 @@ impl FromStr for LevelFilter {
s if s.eq_ignore_ascii_case("off") => Some(LevelFilter::OFF),
_ => None,
})
.ok_or_else(|| ParseLevelFilterError(()))
.ok_or(ParseLevelFilterError(()))
}
}

Expand Down
15 changes: 3 additions & 12 deletions tracing-core/src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,7 @@ impl<'a> Attributes<'a> {

/// Returns true if the new span should be a root.
pub fn is_root(&self) -> bool {
match self.parent {
Parent::Root => true,
_ => false,
}
matches!(self.parent, Parent::Root)
}

/// Returns true if the new span's parent should be determined based on the
Expand All @@ -167,10 +164,7 @@ impl<'a> Attributes<'a> {
/// thread is _not_ inside a span, then the new span will be the root of its
/// own trace tree.
pub fn is_contextual(&self) -> bool {
match self.parent {
Parent::Current => true,
_ => false,
}
matches!(self.parent, Parent::Current)
}

/// Returns the new span's explicitly-specified parent, if there is one.
Expand Down Expand Up @@ -270,10 +264,7 @@ impl Current {
/// [`metadata`]: #method.metadata
/// [`into_inner`]: #method.into_inner
pub fn is_known(&self) -> bool {
match self.inner {
CurrentInner::Unknown => false,
_ => true,
}
!matches!(self.inner, CurrentInner::Unknown)
}

/// Consumes `self` and returns the span `Id` and `Metadata` of the current
Expand Down
15 changes: 3 additions & 12 deletions tracing-core/src/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,30 +528,21 @@ impl Interest {
/// about this callsite.
#[inline]
pub fn is_never(&self) -> bool {
match self.0 {
InterestKind::Never => true,
_ => false,
}
matches!(self.0, InterestKind::Never)
}

/// Returns `true` if the subscriber is sometimes interested in being notified
/// about this callsite.
#[inline]
pub fn is_sometimes(&self) -> bool {
match self.0 {
InterestKind::Sometimes => true,
_ => false,
}
matches!(self.0, InterestKind::Sometimes)
}

/// Returns `true` if the subscriber is always interested in being notified
/// about this callsite.
#[inline]
pub fn is_always(&self) -> bool {
match self.0 {
InterestKind::Always => true,
_ => false,
}
matches!(self.0, InterestKind::Always)
}

/// Returns the common interest between these two Interests.
Expand Down
4 changes: 2 additions & 2 deletions tracing-error/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ The crate provides the following:

**Note**: This crate is currently experimental.

*Compiler support: [requires `rustc` 1.40+][msrv]*
*Compiler support: [requires `rustc` 1.42+][msrv]*

[msrv]: #supported-rust-versions

Expand Down Expand Up @@ -186,7 +186,7 @@ fn main() {
## Supported Rust Versions

Tracing is built against the latest stable release. The minimum supported
version is 1.40. The current Tracing version is not guaranteed to build on Rust
version is 1.42. The current Tracing version is not guaranteed to build on Rust
versions earlier than the minimum supported version.

Tracing follows the same compiler support policies as the rest of the Tokio
Expand Down
4 changes: 2 additions & 2 deletions tracing-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//!
//! **Note**: This crate is currently experimental.
//!
//! *Compiler support: [requires `rustc` 1.40+][msrv]*
//! *Compiler support: [requires `rustc` 1.42+][msrv]*
//!
//! [msrv]: #supported-rust-versions
//!
Expand Down Expand Up @@ -174,7 +174,7 @@
//! ## Supported Rust Versions
//!
//! Tracing is built against the latest stable release. The minimum supported
//! version is 1.40. The current Tracing version is not guaranteed to build on
//! version is 1.42. The current Tracing version is not guaranteed to build on
//! Rust versions earlier than the minimum supported version.
//!
//! Tracing follows the same compiler support policies as the rest of the Tokio
Expand Down
4 changes: 2 additions & 2 deletions tracing-flame/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ flamegraph/flamechart. Flamegraphs/flamecharts are useful for identifying perfor
bottlenecks in an application. For more details, see Brendan Gregg's [post]
on flamegraphs.

*Compiler support: [requires `rustc` 1.40+][msrv]*
*Compiler support: [requires `rustc` 1.42+][msrv]*

[msrv]: #supported-rust-versions
[post]: http://www.brendangregg.com/flamegraphs.html
Expand Down Expand Up @@ -107,7 +107,7 @@ _flamechart_, which _does not_ sort or collapse identical stack frames.
## Supported Rust Versions

Tracing is built against the latest stable release. The minimum supported
version is 1.40. The current Tracing version is not guaranteed to build on Rust
version is 1.42. The current Tracing version is not guaranteed to build on Rust
versions earlier than the minimum supported version.

Tracing follows the same compiler support policies as the rest of the Tokio
Expand Down
4 changes: 2 additions & 2 deletions tracing-flame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! issues bottlenecks in an application. For more details, see Brendan Gregg's [post]
//! on flamegraphs.
//!
//! *Compiler support: [requires `rustc` 1.40+][msrv]*
//! *Compiler support: [requires `rustc` 1.42+][msrv]*
//!
//! [msrv]: #supported-rust-versions
//! [post]: http://www.brendangregg.com/flamegraphs.html
Expand Down Expand Up @@ -98,7 +98,7 @@
//! ## Supported Rust Versions
//!
//! Tracing is built against the latest stable release. The minimum supported
//! version is 1.40. The current Tracing version is not guaranteed to build on
//! version is 1.42. The current Tracing version is not guaranteed to build on
//! Rust versions earlier than the minimum supported version.
//!
//! Tracing follows the same compiler support policies as the rest of the Tokio
Expand Down
4 changes: 2 additions & 2 deletions tracing-futures/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ The crate provides the following traits:
[`Subscriber`]: https://docs.rs/tracing/latest/tracing/subscriber/index.html
[`tracing`]: https://crates.io/tracing

*Compiler support: [requires `rustc` 1.40+][msrv]*
*Compiler support: [requires `rustc` 1.42+][msrv]*

[msrv]: #supported-rust-versions

## Supported Rust Versions

Tracing is built against the latest stable release. The minimum supported
version is 1.40. The current Tracing version is not guaranteed to build on Rust
version is 1.42. The current Tracing version is not guaranteed to build on Rust
versions earlier than the minimum supported version.

Tracing follows the same compiler support policies as the rest of the Tokio
Expand Down
4 changes: 2 additions & 2 deletions tracing-futures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//! * [`WithSubscriber`] allows a `tracing` [`Subscriber`] to be attached to a
//! future, sink, stream, or executor.
//!
//! *Compiler support: [requires `rustc` 1.40+][msrv]*
//! *Compiler support: [requires `rustc` 1.42+][msrv]*
//!
//! [msrv]: #supported-rust-versions
//!
Expand Down Expand Up @@ -62,7 +62,7 @@
//! ## Supported Rust Versions
//!
//! Tracing is built against the latest stable release. The minimum supported
//! version is 1.40. The current Tracing version is not guaranteed to build on
//! version is 1.42. The current Tracing version is not guaranteed to build on
//! Rust versions earlier than the minimum supported version.
//!
//! Tracing follows the same compiler support policies as the rest of the Tokio
Expand Down
4 changes: 2 additions & 2 deletions tracing-journald/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ scoped, structured, and async-aware diagnostics. `tracing-journald` provides a
and events to [`systemd-journald`][journald], on Linux distributions that use
`systemd`.

*Compiler support: [requires `rustc` 1.40+][msrv]*
*Compiler support: [requires `rustc` 1.42+][msrv]*

[msrv]: #supported-rust-versions
[`tracing`]: https://crates.io/crates/tracing
Expand All @@ -38,7 +38,7 @@ and events to [`systemd-journald`][journald], on Linux distributions that use
## Supported Rust Versions

Tracing is built against the latest stable release. The minimum supported
version is 1.40. The current Tracing version is not guaranteed to build on Rust
version is 1.42. The current Tracing version is not guaranteed to build on Rust
versions earlier than the minimum supported version.

Tracing follows the same compiler support policies as the rest of the Tokio
Expand Down
Loading

0 comments on commit 4b54cbc

Please sign in to comment.