Skip to content

derivable_impls false positive on array sizes that do not implement Default #7683

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

Closed
shssoichiro opened this issue Sep 18, 2021 · 0 comments · Fixed by #7684
Closed

derivable_impls false positive on array sizes that do not implement Default #7683

shssoichiro opened this issue Sep 18, 2021 · 0 comments · Fixed by #7684
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

@shssoichiro
Copy link
Contributor

Lint name: derivable_impls

I have the following code:

struct RCDeserialize {
  pass2_buffer: [u8; 68],
}

impl Default for RCDeserialize {
  fn default() -> Self {
    RCDeserialize {
      pass2_buffer: [0; 68],
    }
  }
}

I receive this warning:

warning: this `impl` can be derived
   --> src/rate.rs:466:1
    |
466 | / impl Default for RCDeserialize {
467 | |   fn default() -> Self {
468 | |     RCDeserialize {
469 | |       pass2_buffer: [0; 68],
...   |
473 | |   }
474 | | }
    | |_^
    |
    = help: try annotating `rate::RCDeserialize` with `#[derive(Default)]`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#derivable_impls

I try the suggestion:

#[derive(Default)]
struct RCDeserialize {
  pass2_buffer: [u8; 68],
}

I receive the following compiler error:

error[E0277]: the trait bound `[u8; 68]: std::default::Default` is not satisfied
   --> src/rate.rs:464:3
    |
456 | #[derive(Default)]
    |          ------- in this derive macro expansion
...
464 |   pass2_buffer: [u8; 68],
    |   ^^^^^^^^^^^^^^^^^^^^^^ the trait `std::default::Default` is not implemented for `[u8; 68]`
    |
    = help: the following implementations were found:
              <&[T] as std::default::Default>
              <&mut [T] as std::default::Default>
              <[T; 0] as std::default::Default>
              <[T; 10] as std::default::Default>
            and 31 others
note: required by `std::default::Default::default`

Meta

Rust version (rustc -Vv):

rustc 1.57.0-nightly (9dd4ce80f 2021-09-17)
binary: rustc
commit-hash: 9dd4ce80fb01d1ff5cb5002f08b7b3847b59e664
commit-date: 2021-09-17
host: x86_64-unknown-linux-gnu
release: 1.57.0-nightly
LLVM version: 13.0.0

@rustbot label +I-suggestion-causes-error

@shssoichiro shssoichiro 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 Sep 18, 2021
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Sep 18, 2021
surechen added a commit to surechen/rust-clippy that referenced this issue Sep 18, 2021
@bors bors closed this as completed in ab99eec Sep 30, 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.

2 participants