Skip to content

Instantly share code, notes, and snippets.

@Centril
Created November 2, 2018 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Centril/5be8f6383c888a16d75b8c46f4310e82 to your computer and use it in GitHub Desktop.
Save Centril/5be8f6383c888a16d75b8c46f4310e82 to your computer and use it in GitHub Desktop.
src/error-index.md

Error Index

E0001

This error occurs when #[derive(Arbitrary)] is used on a type which has any lifetime parameters. For example:

#[derive(Debug, Arbitrary)]
struct Foo<'a> {
    bar: &'a str,
}

Due to the lack of generic associated types (GATs) on stable Rust, it is currently impossible to define a Strategy which generates a type that is lifetime-generic (e.g. &'a T). Thus, proptest cannot implement Arbitrary for such types either and therefore you cannot #[derive(Arbitrary)] for such types. Once GATs are available, we will try to lift this restriction. To follow the progress, consult the tracking issue on the matter.

E0002

This error occurs when #[derive(Arbitrary)] is used on a union type. An example:

#[derive(Debug, Arbitrary)]
union IU32 {
    signed: i32,
    unsigned: u32,
}

There are two main reasons for the error.

  1. It is not possible to #[derive(Debug)] on union types and manual implementations cannot know which variant is valid so there are not many valid implementations which are possible.

  2. Second, we cannot mechanically tell which variant out of signed and unsigned to generate. While we could allow you to tell the macro, with an attribute such as #[proptest(select)] on the variant, we have opted for a more conservative approach for the time being. If you have a use case for #[derive(Arbitrary)] on union types, please reach out on the issue tracker.

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