tkaitchuck / constrandom

Macro to generate random constants in Rust https://xkcd.com/221/
Apache License 2.0
73 stars 14 forks source link

Violates overflowing_literals on negative literals #8

Closed dtolnay closed 4 years ago

dtolnay commented 4 years ago

const-random currently emits signed integers in lowercase hex representation:

https://github.com/tkaitchuck/constrandom/blob/3425388e7fd027c21e3ac7fcffc8c1ea3e9b0e32/macro/src/lib.rs#L28

but this leads to an error if the random number is negative.

error: literal out of range for i32
  --> src/main.rs:14:13
   |
14 |     const RAND: i32 = const_random!(i32);
   |                       ^^^^^^^^^^^^^^^^^^
   |
   = note: `#[deny(overflowing_literals)]` on by default
   = note: the literal `0xda324e7e` (decimal `3660729982`) does not fit into the type `i32` and will become `-634237314i32`
   = help: consider using `u32` instead

Deterministic repro:

pub const RAND: i32 = 0xda324e7e;

fn main() {}