BurntSushi / quickcheck

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

Why is the ... as ... part needed to evaluate property functions? #216

Closed mcandre closed 5 years ago

mcandre commented 5 years ago

Curious, why do I need to remind the compiler that my fn (seed : usize, password : String) -> bool { ... } is a fn(usize, String) -> bool with the as token when I pass this function to quickcheck::quickcheck()?

As a workaround, I am declaring my properties as lambdas variables, explicitly typed to their signatures. But I would prefer not to have to do this.

BurntSushi commented 5 years ago

Nobody would prefer to do this. I think this requirement was introduced here by making each fn item have its own distinct type: https://github.com/rust-lang/rust/pull/19891

There is already an issue tracking this problem for quickcheck, and in particular, we would like to be ablw to use closures for property functions: https://github.com/BurntSushi/quickcheck/issues/56

The quickcheck macro is meant to alleviate this annoyance in some cases.

DestyNova commented 4 years ago

Hi @BurntSushi -- I'm just a beginner with Rust but I'm struggling to understand what the benefit of that "unique type per fn item" PR was. We can see the downside of it is lots of extra as fn(...) -> ... annotations in heavily functional code, but there must have been some good reason to do it that outweighed the noise?

BurntSushi commented 4 years ago

That PR was from 6 years ago. I don't have any context on it now. FWIW, I've only ever run into this problem with quickcheck specifically. I do not think it is endemic to "heavily functional" code.