Skip to content

Commit

Permalink
subscriber: fix clippy lints (#636)
Browse files Browse the repository at this point in the history
## Motivation

Looks like Clippy is once again complaining about the
`match_wild_err_arm` lint, presumably as a result of the Rust 1.42
release. This lint triggers on the `try_lock!` macro that
`tracing-subscriber` uses to avoid double panics when a mutex is
poisoned. In this case, the lint is something of a false positive here,
since we _do_ actually have two different `Err(...)` arms; the
differentiation between the two arms is not in the match pattern but in
a guard. See rust-lang/rust-clippy#3688 for
details on the lint.

## Solution

I've refactored the code in question to use `if`/`else`, avoiding the
lint.

Signed-off-by: Eliza Weisman <[email protected]>
  • Loading branch information
hawkw authored Mar 13, 2020
1 parent 12fde2d commit 77624f0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tracing-subscriber/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ macro_rules! try_lock {
try_lock!($lock, else return)
};
($lock:expr, else $els:expr) => {
match $lock {
Ok(l) => l,
Err(_err) if std::thread::panicking() => $els,
Err(_err) => panic!("lock poisoned"),
if let Ok(l) = $lock {
l
} else if std::thread::panicking() {
$els
} else {
panic!("lock poisoned")
}
};
}
Expand Down

0 comments on commit 77624f0

Please sign in to comment.