Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
scottmcm opened this Issue Apr 17, 2018 · 2 comments

Comments

Projects
None yet
4 participants
@scottmcm
Copy link
Member

scottmcm commented Apr 17, 2018

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

@MajorBreakfast

This comment has been minimized.

Copy link

MajorBreakfast commented May 11, 2018

I think that there should be a warning whenever a binding is created that shadows a type in general. This has got to be accidental in 99.9% of all cases!

let u32 = 42i32; // No warning

Try in Playground

This might even make sense to put into the compiler directly.

@vks

This comment has been minimized.

Copy link

vks commented Aug 16, 2018

This might even make sense to put into the compiler directly.

The standard library contains modules that share a name with primitives. Other libraries might want to do the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.