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

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

Closed
japaric opened this issue Apr 29, 2016 · 1 comment · Fixed by #33339
Closed

Comments

@japaric
Copy link
Member

japaric commented Apr 29, 2016

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

@oli-obk
Copy link
Contributor

oli-obk commented Apr 29, 2016

hmmm... I think const_eval is treating -1i8 << 7 as -(1i8 << 7), and 1i8 << 7 is -128, I'll look into it.

japaric pushed a commit to japaric/cast.rs that referenced this issue Apr 29, 2016
expressions like `i32::MIN as f32` are wrongly being warned as
`const_error`s. Allow these kind of warnings until the bug is fixed.
Manishearth added a commit to Manishearth/rust that referenced this issue May 3, 2016
fix various const eval errors

These were found after const_evaluating arbitrary expressions and linting if the const evaluator failed

fixes rust-lang#33275 (int -> float casts for negative ints)
fixes rust-lang#33291 (int -> char casts (new! wasn't allowed in constants until this PR))

r? @eddyb

cc @bluss @japaric
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants