Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enums with Infallible Variants and Derivative Clone Impls make Clippy Overreact on Nightly #100

Open
bhgomes opened this issue Sep 9, 2021 · 0 comments
Labels
bug The crate does not work as expected

Comments

@bhgomes
Copy link

bhgomes commented Sep 9, 2021

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.

@bhgomes bhgomes added the bug The crate does not work as expected label Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The crate does not work as expected
Projects
None yet
Development

No branches or pull requests

1 participant