Skip to content

i8::MIN as f32: warning: attempted to negate with overflow, #[warn(const_err)] on by default #33275

Closed
@japaric

Description

@japaric

STR

// cast.rs
use std::i8;

fn main() {
    i8::MIN as f32;
}
$ rustc cast.rs
cast.rs:5:5: 5:19 warning: attempted to negate with overflow, #[warn(const_err)] on by default
cast.rs:5     i8::MIN as f32;
              ^~~~~~~~~~~~~~

The "evaluated" expression -128 as f32 doesn't trigger the warning. But if you expand the definition of i8::MIN i.e. ((-1 as i8) << 8 - 1) as f32 you also get a warning.

Neither of these three equivalent expressions should trigger a warning.

Metadata

$ rustc -V
rustc 1.10.0-nightly (cda7c1cf2 2016-04-27)

cc @oli-obk might be related to #33214

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions