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

Strange behavior from similar_names in most recent clippy version #2927

Closed
sgrif opened this issue Jul 17, 2018 · 4 comments
Closed

Strange behavior from similar_names in most recent clippy version #2927

sgrif opened this issue Jul 17, 2018 · 4 comments
Labels
C-bug Category: Clippy is not doing the correct thing T-macros Type: Issues with macros and macro expansion

Comments

@sgrif
Copy link

sgrif commented Jul 17, 2018

I'm updating Diesel to the most recent nightly for our tests. This issue occurred with rustup component add clippy-preview on the most recent nightly (rustc 1.29.0-nightly (1ecf6929d 2018-07-16)).

When running cargo clippy on our code base, I receive the following error:


error: binding's name is too similar to existing binding
  |
note: existing binding defined here
 --> diesel_cli/src/main.rs:121:27
  |
12|         ("generate", Some(args)) => {
  |                           ^^^^
help: separate the discriminating character by an underscore like: `arg_1`
  = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#similar_names

error: binding's name is too similar to existing binding
  |
note: existing binding defined here
 --> diesel_cli/src/main.rs:121:27
  |
12|         ("generate", Some(args)) => {
  |                           ^^^^
help: separate the discriminating character by an underscore like: `arg_0`
  = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#similar_names

The first point of note is that it doesn't seem to be pointing to the line that is causing the error, the only span it's showing is in the note section for the existing binding. The second problem is that it's just pointing to the same line multiple times. There is no binding in scope at all close to args other than that one, so it seems to think that the name is too similar to itself.

@phansch phansch added C-bug Category: Clippy is not doing the correct thing T-macros Type: Issues with macros and macro expansion labels Jul 17, 2018
@phansch
Copy link
Member

phansch commented Jul 17, 2018

I think this is similar to #2651. The span is wrong and the suggestion makes it look like it tries to match on some macro expansion somewhere. This might be fixed by rust-lang/rust#52467, and I will try to reproduce it once that's merged.

@H2CO3
Copy link

H2CO3 commented Jul 22, 2018

I am also encountering strange error messages. Here's one:

error: binding's name is too similar to existing binding
   --> redacted/src/lib.rs:111:5
    |
111 |     pub tls_identity_pwd: String,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
note: existing binding defined here
   --> redacted/src/lib.rs:89:5
    |
89  |     pub host: String,
    |     ^^^^^^^^^^^^^^^^
    = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#similar_names

error: aborting due to 2 previous errors

error: Could not compile `redacted`.

Clearly, it's either thinking host and tls_identity_pwd are too similar, or the span is wrong.

@flip1995
Copy link
Member

Still happening with the newest nightly: #3050

oli-obk added a commit that referenced this issue Aug 16, 2018
@H2CO3
Copy link

H2CO3 commented Aug 16, 2018

🎉

bors added a commit that referenced this issue May 26, 2020
Register redundant_field_names and non_expressive_names as early passes

Similar names was moved to a pre-expansion pass to solve #2927, so I'm avoiding linting on code from expansion, which makes the dogfood (mostly, see below) pass.

I had to change new_without_default though, and although I understand why it was not triggering before, TBH I don't see why the binding inside the nested `if_chain` is being linted now. Any ideas? (it seems legit though as the code can be changed by the user)

changelog: Register redundant_field_names and non_expressive_names as early passes

Fixes #5356
Fixes #5521
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 T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

No branches or pull requests

4 participants