Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
paolobarbolini opened this issue Jan 4, 2025 · 0 comments
Labels
A-lint Area: New lints

Comments

@paolobarbolini
Copy link
Contributor

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
}
@paolobarbolini paolobarbolini added the A-lint Area: New lints label Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

No branches or pull requests

1 participant