Skip to content

Integral literals larger than i64::MAX are not detected as overflow #14269

Closed
@lilyball

Description

@lilyball

The type_overflow lint does not catch integral literals larger than i64::MAX. I have to assume the problem is the overflow happens when generating the AST, and the lint operates on the AST, so it can't tell that it overflowed.

Example:

println!("{}", 9223372036854775808i64);
// prints -9223372036854775808
println!("{}", 18446744073709551615i64);
// prints -1

It does manage to catch 18446744073709551616, which is a parse error ("int literal is too large"). This is u64::MAX + 1, so the parser can definitively tell it's too large even though it doesn't know which integral type is being used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions