tkaitchuck / constrandom

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

Include suffix on literal tokens #6

Closed dtolnay closed 4 years ago

dtolnay commented 4 years ago

It looks like the integer literals emitted by const_random are plain integers without a type suffix. The below program compiles and prints i32, which is probably not what would be expected.

use const_random::const_random;

fn f<T>(_: T) {
    println!("{}", std::any::type_name::<T>());
}

fn main() {
    f(const_random!(u8));
}

The const_random invocation in this code should expand to 0xNNu8 instead.