Skip to content

Lint for functions/variables/etc using the same name as a type (str, u32, ...) #135196

@joshtriplett

Description

@joshtriplett

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-langRelevant to the language team

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions