Skip to content

Lint against casts from the size_of function itemΒ #146364

@Noratrieb

Description

@Noratrieb

When using size_of, it is a common mistake to forget to call the function and instead cast the function item to an integer, which has a nonsense result.

There should be a lint, likely deny-by-default against this pattern.

example:

let size = size_of::<u16> as u16;

This is a pretty common mistake: https://github.com/search?q=language%3Arust+%2Fsize_of%3A%3A%3C%5B%5E(%5D*%3E+as%2F&type=code

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions