Skip to content
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

Arbitrary is not implemented for HashMap (quickcheck) #118

Closed
realcr opened this issue Jan 2, 2020 · 1 comment
Closed

Arbitrary is not implemented for HashMap (quickcheck) #118

realcr opened this issue Jan 2, 2020 · 1 comment

Comments

@realcr
Copy link

realcr commented Jan 2, 2020

Hi, thank you for your work on im-rs!

I am trying to compile the following code:

    use im::hashset::HashSet as ImHashSet;

    #[derive(Arbitrary, Clone)]
    struct ExampleHashSet {
        my_set: ImHashSet<u32>,
    }

    use im::hashmap::HashMap as ImHashMap;

    #[derive(Arbitrary, Clone)]
    struct ExampleHashMap {
        my_map: ImHashMap<u32, u64>,
    }

The first part (ExampleHashSet) compiles, but the second one (ExampleHashMap) does not. The second example fails with the following compilation error:

$ cargo test -p offst-proto
   Compiling offst-proto v0.1.0 (...)
error[E0277]: the trait bound `im::hash::map::HashMap<u32, u64>: quickcheck::arbitrary::Arbitrary` is not satisfied
   --> components/proto/src/funder/messages.rs:858:14
    |
858 |     #[derive(Arbitrary, Clone)]
    |              ^^^^^^^^^ the trait `quickcheck::arbitrary::Arbitrary` is not implemented for `im::hash::map::HashMap<u32, u64>`
    |
    = note: required by `quickcheck::arbitrary::Arbitrary::arbitrary`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
error: could not compile `offst-proto`.
warning: build failed, waiting for other jobs to finish...
error: build failed

This is the relevant line I have in my Cargo.toml:

im = {version = "14.1.0", features = ["serde", "quickcheck"]}

I am on the stable channel, this is the version of my rustc:

rustc 1.40.0 (73528e339 2019-12-16)

Guess for solution

I have seen this chunk of code at src/hash/map.rs:

#[cfg(all(feature = "arc", any(test, feature = "quickcheck")))]
impl<K: Hash + Eq + Arbitrary + Sync, V: Arbitrary + Sync> Arbitrary for HashMap<K, V> {
    fn arbitrary<G: Gen>(g: &mut G) -> Self {
        HashMap::from(Vec::<(K, V)>::arbitrary(g))
    }
}

It has the "feature = "arc". I am not sure what this feature is, and how to opt into it.
I did notice that it does not exist at src/hash/set.rs:

#[cfg(all(threadsafe, feature = "quickcheck"))]
impl<A, S> Arbitrary for HashSet<A, S>
where
    A: Hash + Eq + Arbitrary + Sync,
    S: BuildHasher + Default + Send + Sync + 'static,
{
    fn arbitrary<G: Gen>(g: &mut G) -> Self {
        HashSet::from_iter(Vec::<A>::arbitrary(g))
    }
}
@bodil
Copy link
Owner

bodil commented Jan 17, 2020

Oops, yes, it looks like HashMap's Arbitrary implementation wasn't updates along with the rest of them when I got rid of the feature flags. Will fix.

@bodil bodil closed this as completed in f8228ae Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants