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

Warn when known types are used as generic placeholders #54905

Closed
lu-zero opened this issue Oct 8, 2018 · 3 comments
Closed

Warn when known types are used as generic placeholders #54905

lu-zero opened this issue Oct 8, 2018 · 3 comments

Comments

@lu-zero
Copy link
Contributor

lu-zero commented Oct 8, 2018

Since hardly it is what you want and it leads to funny error messages, here an example:

struct S<T> {
    foo: T,
}
impl<u16> S<u16> {
    fn fee(&self, idx: usize) -> u16 {
        if (self.foo as usize) < idx {
            idx as u16
        } else {
            4
        }
    }
}
fn main() {
    let f: S<u16> = S { foo: 42 };
    println!(" {}", f.fee(13));
}
@oli-obk
Copy link
Contributor

oli-obk commented Oct 8, 2018

Clippy reports

warning: This generic shadows the built-in type `u16`
 --> src/main.rs:4:6
  |
4 | impl<u16> S<u16> {
  |      ^^^
  |
  = note: #[warn(clippy::builtin_type_shadow)] on by default
  = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#builtin_type_shadow

Adding new warnings to rustc requires an RFC, as such I am going to close this. If the existing clippy lint is not covering your use cases, please don't hesitate to open an issue on the clippy repository

@oli-obk oli-obk closed this as completed Oct 8, 2018
@lu-zero
Copy link
Contributor Author

lu-zero commented Oct 13, 2018

I'd rather have this in rustc since the current error is quite confusing, do you have an example rfc I can use as template?

@oli-obk
Copy link
Contributor

oli-obk commented Oct 13, 2018

Unfortunately not, I don't know of any RFC that just added a lint.

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

2 participants