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

-(-0.0) raises const_err "attempt to negate with overflow" #64059

Closed
sinkuu opened this issue Sep 1, 2019 · 2 comments · Fixed by #64063
Closed

-(-0.0) raises const_err "attempt to negate with overflow" #64059

sinkuu opened this issue Sep 1, 2019 · 2 comments · Fixed by #64063
Labels
A-const-eval Area: constant evaluation (mir interpretation) A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@sinkuu
Copy link
Contributor

sinkuu commented Sep 1, 2019

fn main() {
    let _ = -(-0.0);
}
error: this expression will panic at runtime
 --> test.rs:2:13
  |
2 |     let _ = -(-0.0);
  |             ^^^^^^^ attempt to negate with overflow
  |
  = note: `#[deny(const_err)]` on by default

error: aborting due to previous error
Meta
rustc 1.39.0-nightly (fba38ac27 2019-08-31)
binary: rustc
commit-hash: fba38ac27e2ade309f4c2504a6d6cd3556972a28
commit-date: 2019-08-31
host: x86_64-unknown-linux-gnu
release: 1.39.0-nightly
LLVM version: 9.0
@Centril Centril added A-const-eval Area: constant evaluation (mir interpretation) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. labels Sep 1, 2019
@Centril
Copy link
Contributor

Centril commented Sep 1, 2019

cc @oli-obk

@oli-obk
Copy link
Contributor

oli-obk commented Sep 1, 2019

Huh...

const X: f32 = -(-0.0);
const Y: f64 = -(-0.0);

compiles fine.

if prim.to_bits()? == (1 << (prim.layout.size.bits() - 1)) {

is the cause. It was created just for signed integers, and I believe we don't need this anymore. We are now emitting the warning on the TerminatorKind::Assert that precedes it (actually causing duplicate warnings: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=432142e19caa14135dfa261f9549a2b7)

So in order to fix this (and deduplicate a bunch of warnings in our test suite), remove

match op {
UnOp::Neg => {
// Need to do overflow check here: For actual CTFE, MIR
// generation emits code that does this before calling the op.
if prim.to_bits()? == (1 << (prim.layout.size.bits() - 1)) {
throw_panic!(OverflowNeg)
}
}
UnOp::Not => {
// Cannot overflow
}
}
and rerun all ui tests with --bless

@oli-obk oli-obk added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Sep 1, 2019
Centril added a commit to Centril/rust that referenced this issue Sep 1, 2019
Centril added a commit to Centril/rust that referenced this issue Sep 3, 2019
Centril added a commit to Centril/rust that referenced this issue Sep 3, 2019
Centril added a commit to Centril/rust that referenced this issue Sep 5, 2019
Centril added a commit to Centril/rust that referenced this issue Sep 5, 2019
@bors bors closed this as completed in 2238d19 Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: constant evaluation (mir interpretation) A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants