rust-lang / rust-lang/rust-clippy
Unable to allow clippy::similar_names
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
I am unable to disable (allow) the clippy::similar_names lint the way I expect. Usually I would place #[allow(clippy::x)] before the offending line, and the lint error would go away. In this case the allow seems to have no effect.
For example, this code shows the lint error being given despite being allowed on the testb line (playground):
#![deny(clippy::pedantic)]
fn main() {
let testa = 0u32;
#[allow(clippy::similar_names)]
let testb = 0u32;
println!("{testa}, {testb}"); // Use variables
}
error: binding's name is too similar to existing binding
--> src/main.rs:6:9
|
6 | let testb = 0u32;
| ^^^^^
|
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![deny(clippy::pedantic)]
| ^^^^^^^^^^^^^^^^
= note: `#[deny(clippy::similar_names)]` implied by `#[deny(clippy::pedantic)]`
note: existing binding defined here
--> src/main.rs:4:9
|
4 | let testa = 0u32;
| ^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#similar_names
I expected that allowing on the testb line would hide the error since that's the line referenced by the error message. To cover my bases, I can also put the allow on testa with the same result (playground):
#![deny(clippy::pedantic)]
fn main() {
#[allow(clippy::similar_names)]
let testa = 0u32;
#[allow(clippy::similar_names)]
let testb = 0u32;
println!("{testa}, {testb}"); // Use variables
}
What does work is allowing on the containing function (playground). But of course this prevents other instances from being caught so is not an ideal workaround.
#![deny(clippy::pedantic)]
#[allow(clippy::similar_names)]
fn main() {
let testa = 0u32;
let testb = 0u32;
println!("{testa}, {testb}"); // Use variables
}
I found this on stable 1.63 but also seems to occur on beta and nightly.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the minimal Rust example from the issue, using the linked Playground cases to compare line-level and function-level allowances. Trace the similar_names lint entry point and its reported spans and lint levels. Done means a targeted allow suppresses only the intended diagnostic while other similar_names warnings remain enabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100