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

derivable_impls wants derive(Default) on enum #7753

Closed
Arnavion opened this issue Oct 3, 2021 · 3 comments · Fixed by #7755
Closed

derivable_impls wants derive(Default) on enum #7753

Arnavion opened this issue Oct 3, 2021 · 3 comments · Fixed by #7755
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@Arnavion
Copy link
Contributor

Arnavion commented Oct 3, 2021

Lint name: derivable_impls

I tried this code:

pub enum IntOrString {
    Int(i32),
    String(String),
}

impl Default for IntOrString {
    fn default() -> Self {
        IntOrString::Int(0)
    }
}

Clippy says:

warning: this `impl` can be derived
  --> src/lib.rs:6:1
   |
6  | / impl Default for IntOrString {
7  | |     fn default() -> Self {
8  | |         IntOrString::Int(0)
9  | |     }
10 | | }
   | |_^
   |
   = note: `#[warn(clippy::derivable_impls)]` on by default
   = help: try annotating `IntOrString` with `#[derive(Default)]`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#derivable_impls

This is incorrect because rustc cannot derive Default on enums (until feature(derive_enum_default) is stabilized.)

Meta

Rust version (rustc -Vv):

rustc 1.57.0-nightly (2b862bed9 2021-09-23)
binary: rustc
commit-hash: 2b862bed9889808b69629fd7246317189b9517a5
commit-date: 2021-09-23
host: x86_64-unknown-linux-gnu
release: 1.57.0-nightly
LLVM version: 13.0.0

The playground repro uses 2021-10-02 f03eb6bef8ced8a24385


cc @HKalbasi

@rustbot label +I-suggestion-causes-error

@Arnavion Arnavion added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Oct 3, 2021
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Oct 3, 2021
@HKalbasi
Copy link
Member

HKalbasi commented Oct 3, 2021

🤦‍♂️

@rustbot claim

bors added a commit that referenced this issue Oct 3, 2021
exclude enum from derivable impls

fix #7753

changelog:

Exclude enum from ``[`derivable_impls`]``
@bors bors closed this as completed in 63b04f7 Oct 3, 2021
@AlexApps99
Copy link

I found a similar bug with unions, I assume this may fix that too.
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=617310465c57a719c089bb30374fb0f4

@AlexApps99
Copy link

AlexApps99 commented Oct 4, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants