Enums with Infallible Variants and Derivative Clone Impls make Clippy Overreact on Nightly
bhgomes opened this issue · comments
NB: Not sure if fixing this issue is the responsibility of derivative
or clippy
, but there may be a proactive solution that derivative
can implement that can future-proof against these kinds of bugs.
Describe the bug
On nightly, if we implement Clone
using derivative::Derivative
on the following enum
pub enum Enum<T> {
/// First Choice
First,
/// Second Choice
Second,
/// Parameter Marker
#[doc(hidden)]
__(Infallible, PhantomData<T>),
}
clippy
overreacts with
warning: unreachable expression
|
| #[derive(derivative::Derivative)]
| ^^^^^^^^^^^^^^^^^^^^^^
| |
| unreachable expression
| any code following this expression is unreachable
|
= note: `#[warn(unreachable_code)]` on by default
note: this expression has type `Infallible`, which is uninhabited
|
| #[derive(derivative::Derivative)]
| ^^^^^^^^^^^^^^^^^^^^^^
= note: this warning originates in the derive macro `derivative::Derivative` (in Nightly builds, run with -Z macro-backtrace for more info)
Implementing Clone
using the standard library derive
macro doesn't give the error but it has the undesirable property that it automatically adds the T: Clone
constraint where derivative
does not.
To Reproduce
Here's a rust playground example with the standard library derive
and derivative::Derivative
.
Expected behavior
I expected no warning since it did not give a warning in the past (and the warning is not helpful either).
Errors
N/A
Version (please complete the following information):
rustup 1.24.3 (2021-05-31)
cargo 1.56.0-nightly (18751dd3f 2021-09-01)
rustc 1.57.0-nightly (fdf65053e 2021-09-07)
derivative 2.2.0
Additional context
You can also just try to silence the warning from clippy
by adding #[allow(unreachable_code)]
but no matter where you put it on the enum
, above the variant, above the pub enum Enum<T>
line, or above the #[derive(derivative::Derivative)]
line, clippy
still complains. You can only silence the warning by putting a global #![allow(unreachable_code)]
but this is not safe.