rust-lang / rust-lang/rust-clippy
some #[allow(...)] outer attributes do not apply to just_underscores_and_digits lint
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
Clippy produces false warnings for the following code. The code is not expected to produce warnings as the #[allow(...)] outer attribute should apply to the following line
fn main() {}
fn _just_underscores_and_digits_0() {
#[allow(clippy::just_underscores_and_digits)]
let _1 = 1; // warning
}
fn _just_underscores_and_digits_1() {
#[allow(warnings)]
let _1 = 1; // warning
}
These examples work fine
#[allow(clippy::just_underscores_and_digits)]
fn _just_underscores_and_digits_2() {
let _1 = 1;
}
fn _just_underscores_and_digits_3() {
#![allow(clippy::just_underscores_and_digits)]
let _1 = 1;
}
Try it in the rust playground
just_underscores_and_digits can be found in clippy_lints/src/non_expressive_names.rs, which houses 2 other related lints (many_single_char_names and similar_names) .
many_single_char_names shares the same problem as just_underscores_and_digits (run with -W clippy::many_single_char_names since the lint group is pedantic)
fn _many_single_char_names_0() {
#[allow(clippy::many_single_char_names)]
let (a, b, c, d, e, f, g) = (1, 2, 3, 4, 5, 6, 7); // warning
}
fn _many_single_char_names_1() {
#[allow(warnings)]
let (a, b, c, d, e, f, g) = (1, 2, 3, 4, 5, 6, 7); // warning
}
The remaining lint (similar_names) seems to be a false negative (use -W clippy::similar_names)
// this should warn but does not
fn _similar_names() {
let checked_exp = 1;
let checked_expr = 1;
}
I've skimmed through the code but frankly the more I look the more I wonder if it works at all:
similar_namesis not working aslevenstein_not_1doesn't seem to work as expected (tryassert!(!levenstein_not_1("checked_exp", "checked_expr")))just_underscores_and_digitsandmany_single_char_namesAST walks share the same visitor assimilar_names(SimilarNamesLocalVisitor). The customvisit_localimplementation in the visitor seems to prevent outer attributes from applying correctly
To be clear, I don't use these lints so they don't bother me, but I did spend good time trying to understand why #[allow(...)] wasn't working. Perhaps if we can determine that these lints are somewhat unused deprecating them can also be an option
Lint Name
just_underscores_and_digits, many_single_char_names, similar_names
Version
rustc 1.77.0-nightly (7ffc697ce 2024-01-24)
binary: rustc
commit-hash: 7ffc697ce10f19447c0ce338428ae4b9bc0c041c
commit-date: 2024-01-24
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6
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
Start in clippy_lints/src/non_expressive_names.rs and inspect SimilarNamesLocalVisitor, especially its custom visit_local implementation. Reproduce the reported examples for just_underscores_and_digits, many_single_char_names, and similar_names, then verify that outer allow attributes behave correctly and that the similar_names result matches the issue's expectations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100