Skip to content

Wrong warning?: literal out of range for i8 #48073

Closed
@kkayal

Description

@kkayal

I have this code:

fn main() {
    println!("-1 = {:b}", -1 as i8);
    println!("0b11111111 = {}", 0b11111111 as i8);
}

Both lines return the expected result, namely

-1 = 11111111
0b11111111 = -1

However, the compiler raises a warning as follows:

warning: src\main.rs:3: literal out of range for i8
note: src\main.rs:3: #[warn(overflowing_literals)] on by default

To my understanding, 0b11111111 is a valid signed integer and means -1 in decimal. Therefore the warning seems to be wrong to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions