Skip to content

!0u32/2 gives “error: attempted to divide with overflow in a constant expression [E0020]” #23968

Closed
@andersk

Description

@andersk
println!("{}", !0u32);  // 4294967295
println!("{}", !0u32/2);  // error: attempted to divide with overflow in a constant expression [E0020]
const A: u32 = !0;
println!("{}", A/2);  // error: attempted to divide with overflow in a constant expression [E0020]
let a: u32 = !0;
println!("{}", a/2);  // 2147483647
const B: u32 = 4294967295;
println!("{}", A == B);  // true
println!("{}", B/2);  // 2147483647

This affects the test suites for the num and rand crates.

$ rustc --version
rustc 1.0.0-dev (built 2015-04-02)
$ dpkg-query -W rust-nightly
rust-nightly    201504020407~2e3b0c0~vivid

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions