Skip to content

Commit

Permalink
fix nightly clippy warnings
Browse files Browse the repository at this point in the history
This will avoid breaking CI on new releases of clippy. It also makes the
code a little easier to read.

- 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 error 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
```
  • Loading branch information
jyn514 committed Sep 26, 2020
1 parent a8cc977 commit f1e3e00
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 74 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 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
10 changes: 2 additions & 8 deletions tracing-core/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,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 @@ -117,10 +114,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
13 changes: 3 additions & 10 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 @@ -553,8 +547,7 @@ impl FromStr for LevelFilter {
s if s.eq_ignore_ascii_case("trace") => Some(LevelFilter::TRACE),
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
15 changes: 3 additions & 12 deletions tracing-subscriber/src/fmt/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,22 +1052,13 @@ impl FmtSpanConfig {
}
}
pub(super) fn trace_new(&self) -> bool {
match self.kind {
FmtSpan::FULL => true,
_ => false,
}
matches!(self.kind, FmtSpan::FULL)
}
pub(super) fn trace_active(&self) -> bool {
match self.kind {
FmtSpan::ACTIVE | FmtSpan::FULL => true,
_ => false,
}
matches!(self.kind, FmtSpan::ACTIVE | FmtSpan::FULL)
}
pub(super) fn trace_close(&self) -> bool {
match self.kind {
FmtSpan::CLOSE | FmtSpan::FULL => true,
_ => false,
}
matches!(self.kind, FmtSpan::CLOSE | FmtSpan::FULL)
}
}

Expand Down
10 changes: 2 additions & 8 deletions tracing-subscriber/src/reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,13 @@ impl Error {
/// Returns `true` if this error occurred because the layer was poisoned by
/// a panic on another thread.
pub fn is_poisoned(&self) -> bool {
match self.kind {
ErrorKind::Poisoned => true,
_ => false,
}
matches!(self.kind, ErrorKind::Poisoned)
}

/// Returns `true` if this error occurred because the `Subscriber`
/// containing the reloadable layer was dropped.
pub fn is_dropped(&self) -> bool {
match self.kind {
ErrorKind::SubscriberGone => true,
_ => false,
}
matches!(self.kind, ErrorKind::SubscriberGone)
}
}

Expand Down
11 changes: 2 additions & 9 deletions tracing/tests/support/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,7 @@ where
"[{}] record: {}; id={:?}; values={:?};",
self.name, span.name, id, values
);
let was_expected = if let Some(Expect::Visit(_, _)) = expected.front() {
true
} else {
false
};
let was_expected = matches!(expected.front(), Some(Expect::Visit(_, _)));
if was_expected {
if let Expect::Visit(expected_span, mut expected_values) = expected.pop_front().unwrap()
{
Expand Down Expand Up @@ -319,10 +315,7 @@ where
id
);
let mut expected = self.expected.lock().unwrap();
let was_expected = match expected.front() {
Some(Expect::NewSpan(_)) => true,
_ => false,
};
let was_expected = matches!(expected.front(), Some(Expect::NewSpan(_)));
let mut spans = self.spans.lock().unwrap();
if was_expected {
if let Expect::NewSpan(mut expected) = expected.pop_front().unwrap() {
Expand Down

0 comments on commit f1e3e00

Please sign in to comment.