Skip to content

Warn on shadowing built-in types #36046

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

Closed
Wilfred opened this issue Aug 27, 2016 · 4 comments
Closed

Warn on shadowing built-in types #36046

Wilfred opened this issue Aug 27, 2016 · 4 comments

Comments

@Wilfred
Copy link
Contributor

Wilfred commented Aug 27, 2016

I got a little confused by the following code:

struct Foo<T> {
    value: T
}

impl<u32> Foo<u32> {
    fn impl_func(&self) -> u32 {
        42
    }
}

rustc gives the error: 42: expected type parameter, found integral variable.

The mistake is that I've created a type parameter named u32. Could we warn on this case? I can't see any legitimate use case for shadowing u32.

@nagisa
Copy link
Member

nagisa commented Aug 27, 2016

Should report an issue to clippy in case they don’t already have such a lint instead.

@Wilfred
Copy link
Contributor Author

Wilfred commented Aug 27, 2016

Since this code is also a compile error, I believe clippy can't help.

@mcarton
Copy link
Member

mcarton commented Aug 28, 2016

@Wilfred Sure it can. Purely syntactic lints are run before type checking.

This had already been reported on Clippy: https://github.com/Manishearth/rust-clippy/issues/949. I implemented it: https://github.com/Manishearth/rust-clippy/pull/1199.

@Wilfred
Copy link
Contributor Author

Wilfred commented Aug 28, 2016

Aha, this is well-trodden ground then. I'm going to close as a duplicate of #35030.

Huge thanks for implementing it in clippy! I did not know clippy could help with code that can't compile.

@Wilfred Wilfred closed this as completed Aug 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants