Skip to content

similar_names triggers for levensthein distance of 8 #3057

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
matthiaskrgr opened this issue Aug 16, 2018 · 6 comments
Closed

similar_names triggers for levensthein distance of 8 #3057

matthiaskrgr opened this issue Aug 16, 2018 · 6 comments
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Aug 16, 2018

clippy 0.0.212 / rustc 1.30.0-nightly (d767ee1 2018-08-15)

code:

#[cfg_attr(feature = "cargo-clippy", warn(similar_names))]
#[derive(Debug, Clone)]
pub(crate) struct DirSizes {
    pub(crate) total_size: u64,                // total size of cargo root dir
    pub(crate) numb_bins: u64,                 // number of binaries found
    pub(crate) total_bin_size: u64,            // total size of binaries found
    pub(crate) total_reg_size: u64,            // registry size
    pub(crate) total_git_db_size: u64,         // size of bare repos and checkouts combined
    pub(crate) total_git_repos_bare_size: u64, // git db size
    pub(crate) numb_git_repos_bare_repos: u64, // number of cloned repos
    pub(crate) numb_git_checkouts: u64,        // number of checked out repos
    pub(crate) total_git_chk_size: u64,        // git checkout size
    pub(crate) total_reg_cache_size: u64,      // registry cache size
    pub(crate) total_reg_src_size: u64,        // registry sources size
    pub(crate) numb_reg_cache_entries: u64,    // number of source archives
    pub(crate) numb_reg_src_checkouts: u64,    // number of source checkouts
}
fn main() {
    println!("Hello, world!");
}

I'm getting similar_names warning for binding names total_reg_src_size and total_size although levensthein distance of these is 8.
Was the check tightened recently?

Also:
numb_reg_src_checkouts and total_bin_size (????)

@matthiaskrgr
Copy link
Member Author

o_O The warnings disappear as soon as I remove #[derive(Debug, Clone)]

@mati865
Copy link
Contributor

mati865 commented Aug 16, 2018

Duplicate of #2651

@flip1995
Copy link
Member

flip1995 commented Aug 16, 2018

Something really weird is happening here Playground (original):

insane thinks I tried

The lint gets always triggered on the 10th line after total_size and total_bin_size. So if we move total_bin_size it will trigger on the 10th line after it. If we remove a field from the struct it won't get triggered on total_bin_size anymore, because there are only 9 fields defined after that. Playground

Well, or maybe not... If we remove a field above total_bin_size it also won't get triggered, even if the 10th field after it is still the same. Playground

With total_size it's always the 10th element below. Except we remove total_size itself, then it triggers on numb_bins and numb_reg_cache_entries Playground. It also doesn't matter what the 11th field is... It just lints..

Let's move total_size to the bottom Playground. It just lints on the 11th and 13th field with the field 10 lines above.

So it seems, that this lint doesn't like odd numbers greater than 10. Time to go crazy: let's add a 14th and 15th field and see what happens: Playground
Well it lints on.. both.... But the 10 field distance is still the same.

Why stop at 15 fields? Playground

It lints on field11, field13..20 with field1, field3..10. So it likes field12.
It lints on field21..22, field24..30 with field1..2, field4..10. So it likes field23.
It lints on field31..33, field35..30 with field1..3, field5..10. So it likes field34.
I think it will go on like this.

You're seeing the same things right? Am I going crazy? Send help!! 😄

EDIT: Deriving both Debug and Clone will lint on field11 twice, but not on every other field.

@flip1995 flip1995 added C-bug Category: Clippy is not doing the correct thing A-musing labels Aug 16, 2018
@ghost
Copy link

ghost commented Aug 17, 2018

It's a macro expansion problem. If you use cargo rustc -- -Z unpretty=hir and fix the compilation errors, it starts to make more sense.

 Checking playground v0.0.1 (file:///playground)
warning: binding's name is too similar to existing binding
  --> src/main.rs:47:41
   |
47 |                 total_reg_src_size: ref __self_0_10,
   |                                         ^^^^^^^^^^^
   |
note: lint level defined here
  --> src/main.rs:1:44
   |
1  | #![cfg_attr(feature = "cargo-clippy", warn(similar_names))]
   |                                            ^^^^^^^^^^^^^
note: existing binding defined here
  --> src/main.rs:37:33
   |
37 |                 total_size: ref __self_0_0,
   |                                 ^^^^^^^^^^
   = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#similar_names

Playground

It's already been fixed by #3056.

@flip1995
Copy link
Member

Oh I thought this was already in the Clippy version of yesterday. Even better then!

@mati865
Copy link
Contributor

mati865 commented Aug 17, 2018

@flip1995 it can take few days before rust module is updated.

matthiaskrgr added a commit to matthiaskrgr/rust-clippy that referenced this issue Sep 7, 2018
matthiaskrgr added a commit to matthiaskrgr/rust-clippy that referenced this issue Sep 8, 2018
@ghost ghost closed this as completed in #3149 Sep 9, 2018
ghost pushed a commit that referenced this issue Sep 9, 2018
This issue was closed.
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
Projects
None yet
Development

No branches or pull requests

3 participants