rust-lang / rust-lang/rust-clippy

New Lint: use of built-in (or prelude) type as identifier

Open
#2,676 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

This compiles today, but doesn't do what many expect:

    struct Foo { x: u32 }
    let y = Foo { x: 4 };
    let Foo { x: u32 } = y;

https://play.rust-lang.org/?gist=2b9bb2b1e25b5a9d85c7adecf301fd22&version=stable

It would be nice if that gave a lint like "variable/module/function/macro u32 has the same name as a built-in type". Could possibly also apply to things like let Vec = 4; too, but I suspect that's less likely because of casing conventions.

cc https://internals.rust-lang.org/t/random-musings-types-in-patterns/7316/9?u=scottmcm
cc https://github.com/rust-lang/rust/blob/9da2112238c565a7e36ada0a1f9c899961910131/src/test/run-pass/weird-exprs.rs#L87-L104

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 with the example in the issue and the referenced run-pass test, src/test/run-pass/weird-exprs.rs lines 87-104. Read the linked Rust Internals discussion to understand the intended scope for built-in types and identifiers. Done means a Clippy lint consistently detects the demonstrated pattern and has coverage for the agreed identifier cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.