Skip to content

u8::max as usize instead of u8::MAX as usize should warn #13973

@theemathas

Description

@theemathas

What it does

It should warn on code like u8::max as usize, or similar code with min or with other integer types.

Advantage

u8::MAX is a constant equal to 2^8-1. u8::MAX as usize casts that value to a larger integer size.

u8::max is a function that takes two u8 values and returns the larger one. u8::max as usize takes the address of that function, which is almost certainly not intended.

Drawbacks

No response

Example

u8::max as usize

Could be written as:

u8::MAX as usize

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions