Closed
Description
Lint name: unnecessary_cast
I tried this code:
#[allow(non_camel_case_types)]
pub type size_t = usize;
pub struct Foo {
pub len: size_t,
}
impl Foo {
#[allow(dead_code)]
fn new() -> Foo {
Foo {
len: 0 as size_t,
}
}
}
I expected to see this happen:
No lint triggered, or, ideally, a suggestion to omit the cast completely and write just len: 0,
Instead, this happened:
Clippy suggested using 0_usize
instead of 0 as size_t
.
The suggestion is not good, because then changing size_t
to e.g. u64
causes the compiler error.
Meta
- clippy 0.1.52 (2021-03-16 f5d8117)
- rustc the Stable version: 1.50.0