-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement Testable for Fn* #56
Comments
Errm, try: |
That does work, thank you. I'm a bit baffled that it's required since it's trivially inferrable type information... |
I'm pretty sure it's a known bug, but I can't find it in the Rust issue tracker at the moment. I think this happened when Rust moved everything over to unboxed closures. Unfortunately, I can't remember why this happens. |
The PR that introduced this, I think, is rust-lang/rust#19891. I too remember seeing something that indicated this coercion is supposed to exist at some point but can't find it either. |
Afaik, functions now implement the Edit: that does not work together with the coherence rules, does it? |
I've tried really hard to work around this (by pursuing impls with |
I think I'm currently blocked on this by this bug: rust-lang/rust#25041 (Well, I think it's a bug. It sure feels like it.) |
cc me |
Just to clarify: we are currently blocked on being able to quickcheck an arbitrary closure? (Important to be able to nest to stage generation of values, as in Haskell QuickCheck and Scala ScalaCheck.) |
@FranklinChen Yup. I might be missing another solution to the problem, but the straight-forward path is to implement |
While this still doesn't seem possible at the type level yet, you can reduce a bit of boilerplate by using fn prop(xs: Vec<i32>) -> bool {
xs == reverse(&reverse(&xs[..])[..])
}
quickcheck(prop as fn(_) -> _); This is a bit nicer as you only have to duplicate the number of arguments, not the types. |
@shepmaster Ah, thanks for that tip. Could a macro automate that? |
As far as I can tell, this is just never going to work. See rust-lang/rust#25041 for more discussion, where it seems to me the issue has been interpreted as "confusing" rather than a bug to fix. Some reasons are given but I don't quite understand them. I don't see any movement to resolve it, so after half a decade, I'm giving up and calling this I would very much love to make quickcheck work with closures though. So if there are any fresh ideas, we can re-open is this issue. |
Using rustc 1.0.0-nightly (3d0d9bb6f 2015-01-12 22:56:20 +0000):
produces
quickcheck(false)
compiles; this appears to be specific to the fn impls, including the zero-arg fn.The text was updated successfully, but these errors were encountered: