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

Comments

Projects
None yet
2 participants
@lu-zero
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

This comment has been minimized.

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 Oct 8, 2018

@lu-zero

This comment has been minimized.

Contributor

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

This comment has been minimized.

Contributor

oli-obk commented Oct 13, 2018

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

@lu-zero lu-zero referenced this issue Oct 23, 2018

Open

Uplift lints from clippy to rustc #53224

32 of 49 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment