Skip to content

unnecessary_cast suggestion for type aliasses  #6923

Closed
@mgacek8

Description

@mgacek8

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingL-suggestionLint: Improving, adding or fixing lint suggestionsgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions