rust-lang / rust-lang/rust-clippy

Warn when using a variable named the same as a type

Open
#2,053 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint E-medium L-style T-middle
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Some examples from Rust 1.20:

🙅 — compiler generates an error (can't shadow unit structs)

struct Dog;
fn x(Dog: Dog) {}

⚠️ — compiler generates a warning (non-snake case variable)

struct Dog {}
fn x(Dog: Dog) {}

😖 — compiler doesn't generate a warning (and indeed the variable str is valid to use)

struct Dog {}
fn x(str: Dog) {}

I propose that Clippy warn when a variable name matches an in-scope type. I'm not even sure if it's possible to know all the types, but using the built-in lowercase primitive types (e.g. bool, str, i32) would be a great start.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing Clippy's existing lint architecture and Rust's name-resolution capabilities. Use the issue's examples as the initial behavior cases, especially variables matching primitive or in-scope type names. Done means Clippy warns for the proposed name collision without rejecting valid variable usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.