BurntSushi / quickcheck

Automated property based testing for Rust (with shrinking).
The Unlicense
2.4k stars 149 forks source link

Trivial cast error when using `#[quickcheck]` inside macro #261

Open cmichi opened 3 years ago

cmichi commented 3 years ago

This is a minimal example:

crate::my_macro!(u32);

#[macro_export]
macro_rules! my_macro {
    ($my_type:ty) => {
        #[quickcheck]
        fn fuzz_my_type(my: $my_type) {
            // ...
        }
    }
}

Results in

error: trivial cast: `fn(u32) {fuzz_my_type::fuzz_my_type}` as `fn(u32)`
   --> ~/fuzz_tests.rs:13:9
    |
  2 |   crate::my_macro!(u32);
    |   ---------------------- in this macro invocation
... 
 13 | /         #[quickcheck]
 14 | |         fn fuzz_my_type(my: $my_type) {
    | |_______________________^

It works if I add #[allow(trivial_casts)], but it should work without flags to the compiler.

BurntSushi commented 3 years ago

Someone is welcome to submit a PR fixing this, if possible. I don't use or really work on the #[quickcheck] macro. It's almost never worth the added dependencies IMO.