Skip to content

Instantly share code, notes, and snippets.

@ulidtko
Last active December 23, 2020 18:59
Show Gist options
  • Select an option

  • Save ulidtko/c67e7a7d000c0ac81d69c1f7dfba4fce to your computer and use it in GitHub Desktop.

Select an option

Save ulidtko/c67e7a7d000c0ac81d69c1f7dfba4fce to your computer and use it in GitHub Desktop.
[package]
name = "foobar"
version = "0.1.0"
authors = ["max ulidtko <[email protected]>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand = "0.8.*"
quickcheck = "0.9.*"
[[bin]]
name = "foobar"
path = "main.rs"
Compiling foobar v0.1.0 (/tmp/foobar)
error[E0277]: the trait bound `G: rand::RngCore` is not satisfied
--> src/main.rs:20:28
|
8 | fn new_random<R: Rng>(rng: &mut R) -> Self {
| --- required by this bound in `Foobar::new_random`
...
20 | Foobar::new_random(g)
| ^ the trait `rand::RngCore` is not implemented for `G`
|
= note: required because of the requirements on the impl of `rand::Rng` for `G`
help: consider further restricting this bound
|
19 | fn arbitrary<G: Gen + rand::RngCore>(g: &mut G) -> Self {
| ^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
error: could not compile `foobar`
To learn more, run the command again with --verbose.
extern crate rand;
use rand::prelude::*;
#[derive(Debug,Clone)]
enum Foobar { Foo, Bar }
impl Foobar {
fn new_random<R: Rng>(rng: &mut R) -> Self {
match rng.gen() {
true => Foobar::Foo,
false => Foobar::Bar,
}
}
}
extern crate quickcheck;
use quickcheck::{Gen,Arbitrary};
impl Arbitrary for Foobar {
fn arbitrary<G: Gen>(g: &mut G) -> Self {
Foobar::new_random(g)
}
}
fn main() {
let mut rng = rand::thread_rng();
println!("{:?}", Foobar::new_random(&mut rng));
}
@ulidtko
Copy link
Author

ulidtko commented Dec 23, 2020

Fix

diff --git i/Cargo.toml w/Cargo.toml
index b9b156b..bea7ca5 100644
--- i/Cargo.toml
+++ w/Cargo.toml
@@ -7,7 +7,7 @@ edition = "2018"
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
-rand = "0.8.*"
+rand = "<0.8"
 quickcheck = "0.9.*"
 
 [[bin]]

to avoid this:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment