The exceeding_bitshifts error vs C-like enum discriminant value larger than u32::MAX


There seem to be something special going on inside enum definition:

enum E {
  C = 1 << 63  // legal

fn main() {
  println!("{}", 1 << 63);  // A
  println!("{}", E::C as u64);  // B

I’m not complaining to anything, but it seems a bit odd to me that only the A line produces this error:

error: bitshift exceeds the type's number of bits, #[deny(exceeding_bitshifts)] on by default

In other words, there seems to be a minor inconsistency between C-like enums and RFC212:

Related discussion:


I just learned

enum E { C = ... }

means pretty much the same thing as

const E_C: isize = ...;
enum E { C = E_C }

So in my example, an untyped int literal 1 in 1 << 63 is typed as isize, which nowadays commonly means i64.

But all these things should be explained in the Rust reference…

Also, the choice of isize as the default type may be pragmatic but is debatable.