Skip to content

Prematurely lint against const numbers that would trigger overflowing_literals on platforms with smaller usize/isizes #13943

Open
@paolobarbolini

Description

@paolobarbolini

What it does

Detect const usize/isize values that correctly build for 64 bit targets but break the build with overflowing_literals on 32 bit or 16 bit targets.

Advantage

  • Detect obvious cases in which a program won't build for a different platform
  • Detect incorrect uses of usize/isize, and suggest replacing them with u64/i64

Drawbacks

No response

Example

// Example 1
const VALUE: usize = 5000000000;

// Example 2
fn check(val: usize) -> bool {
    val < 5000000000
}

Could be written as:

// Example 1
const VALUE: u64 = 5000000000;

// Example 2
fn check(val: u64) -> bool {
    val < 5000000000
}

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