Lint for functions/variables/etc using the same name as a type (`str`, `u32`, ...)
Open
Nobody has claimed this yet.
A-lints
C-feature-request
T-lang
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
fn func(u32: u32) {
println!("{u32}");
}
fn main() {
let u32 = 42;
func(u32);
let closure = |str: &str| {
println!("{}", str.len());
};
closure("hello");
}
Current output
(none)
Desired output
warning: variable `u32` should use a name that doesn't conflict with a standard type
--> src/main.rs:1:9
|
1 | fn func(u32: u32) {
| ^^^ help: rename the identifier
Rationale and extra context
It's confusing to read code where str (or another standard type name) is used as an identifier. It also produces misleading syntax highlighting.
Other cases
Rust Version
rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: x86_64-unknown-linux-gnu
release: 1.83.0
LLVM version: 19.1.1
Anything else?
No response
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 by reproducing the provided Rust example with rustc 1.83.0 and inspect how existing compiler lints handle identifiers that shadow types. Check the lint output for function parameters, local variables, and closure parameters, then add coverage for the requested cases. Done means the compiler emits the requested warning and the relevant tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100