Skip to content

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

Open
@scottmcm

Description

@scottmcm

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsL-correctnessLint: Belongs in the correctness lint group

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions