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

False positive of lint similar-names for identifiers with trailing underscore #6479

Closed
fmease opened this issue Dec 20, 2020 · 3 comments
Closed
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@fmease
Copy link
Member

fmease commented Dec 20, 2020

I tried this code:

#![allow(unused_variables)]
#![warn(clippy::similar_names)]

fn main() {
    let types = [1, 2, 3];
    let type_ = 3;
}

I expected Clippy to not emit any warnings since types and type_ are visually distinct (in my eyes).
Instead, Clippy reported similar_names suggesting to change type_ to type__ which does not make much sense to me.

Edit: Together with types, I use the identifier type_ quite a lot in my code base, which is a compiler. The unusual name obviously stems from the fact that type is a keyword in Rust and thus I cannot use it (but I prefer it to typ or r#type). All that to say, this is not an artificial corner case.

Meta

  • clippy 0.0.212 (1c389ff 2020-11-24)
  • rustc 1.50.0-nightly (1c389ffef 2020-11-24)
Full Standard Error

warning: binding's name is too similar to existing binding
 --> src/main.rs:6:9
  |
6 |     let type_ = 3;
  |         ^^^^^
  |
note: the lint level is defined here
 --> src/main.rs:2:9
  |
2 | #![warn(clippy::similar_names)]
  |         ^^^^^^^^^^^^^^^^^^^^^
note: existing binding defined here
 --> src/main.rs:5:9
  |
5 |     let types = [1, 2, 3];
  |         ^^^^^
help: separate the discriminating character by an underscore like: `type__`
 --> src/main.rs:6:9
  |
6 |     let type_ = 3;
  |         ^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#similar_names

warning: 1 warning emitted

@fmease fmease added the C-bug Category: Clippy is not doing the correct thing label Dec 20, 2020
@phansch phansch added the I-false-positive Issue: The lint was triggered on code it shouldn't have label Dec 21, 2020
@camsteffen camsteffen added the good-first-issue These issues are a good way to get started with Clippy label Feb 8, 2021
@th1000s
Copy link
Contributor

th1000s commented May 13, 2021

Fixed in PR #7221 by comparing it to a (hardcoded) list of known keywords.

@arieluy
Copy link
Contributor

arieluy commented May 4, 2022

Should this be closed?

@fmease
Copy link
Member Author

fmease commented May 4, 2022

I guess it should.
Closed via #7221.

@fmease fmease closed this as completed May 4, 2022
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 good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

5 participants