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

Wrong suggestion for new_without_default_derive? #3806

Closed
Yatekii opened this issue Feb 23, 2019 · 1 comment
Closed

Wrong suggestion for new_without_default_derive? #3806

Yatekii opened this issue Feb 23, 2019 · 1 comment

Comments

@Yatekii
Copy link

Yatekii commented Feb 23, 2019

I get

warning: you should consider deriving a `Default` implementation for `access_ports::memory_ap::mock::MockMemoryAP`
  --> coresight/src/access_ports/memory_ap/mock.rs:25:5
   |
25 | /     pub fn new() -> Self {
26 | |         let mut store = HashMap::new();
27 | |         store.insert((CSW::ADDRESS, CSW::APBANKSEL), 0);
28 | |         store.insert((TAR::ADDRESS, TAR::APBANKSEL), 0);
...  |
33 | |         }
34 | |     }
   | |_____^
   |
   = note: #[warn(clippy::new_without_default_derive)] on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default_derive
help: try this
   |
13 | #[derive(Default)]
   |

suggested from clippy, which is imo plain wrong.
The automatically derived function would not do the same as it would not insert anything into the hasmap or initialize a 256 elements sized vector:

       let mut store = HashMap::new();
        store.insert((CSW::ADDRESS, CSW::APBANKSEL), 0);
        store.insert((TAR::ADDRESS, TAR::APBANKSEL), 0);
        store.insert((DRW::ADDRESS, DRW::APBANKSEL), 0);
        Self {
            data: vec![0; 256],
            store,
        }

This happens with clippy installed through rustup on
stable-x86_64-unknown-linux-gnu unchanged - rustc 1.32.0 (9fda7c223 2019-01-16)

Trying to update clippy tells me
info: component 'clippy' for target 'x86_64-unknown-linux-gnu' is up to date

@flip1995
Copy link
Member

Duplicate of #3697

@flip1995 flip1995 marked this as a duplicate of #3697 Feb 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants