proptest_derive/lib.rs
1// Copyright 2018 The proptest developers
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9//! This is the API documentation for the `proptest-derive` crate. As this
10//! crate does not have an API _per se_, there isn't much to see here.
11//!
12//! You are probably looking for the [`proptest-derive` section of the Proptest
13//! Book](https://proptest-rs.github.io/proptest/proptest-derive/index.html).
14
15// # Known issues
16//
17// ## Fields with `[T; N]` where `N > 32`
18//
19// We can't derive for fields having arrays with sizes over 32.
20// While proptest only supports in UniformArrayStrategy arrays of sizes up to
21// 32, we can overcome that restriction by generating custom types on the
22// fly here. What we can't overcome is that `T: Arbititrary |- T: Debug` due
23// to the requirement by proptest. Since `T: Debug` must hold, we must also
24// ensure that arrays with sizes over 33 are also Debug. We can't do this.
25// Doing so would create orphan instances, which Rust does not allow to preserve
26// coherence. Therefore, until const generics lands in stable or when
27// we can remove the `T: Debug` bound on Arbitrary, we can not support arrays
28// sized over 32.
29//
30// # Recursive types
31//
32// We can't handle self-recursive or mutually recursive types at all right now.
33
34extern crate proc_macro as pm;
35extern crate proc_macro2;
36
37#[macro_use]
38extern crate syn;
39#[macro_use]
40extern crate quote;
41
42mod ast;
43mod attr;
44mod derive;
45mod error;
46mod interp;
47mod use_tracking;
48mod util;
49mod void;
50
51/// See module level documentation for more information.
52#[proc_macro_derive(Arbitrary, attributes(proptest))]
53pub fn derive_proptest_arbitrary(input: pm::TokenStream) -> pm::TokenStream {
54 // Bootstrap!
55 // This function just delegates to impl_proptest_arbitrary.
56 derive::impl_proptest_arbitrary(syn::parse(input).unwrap()).into()
57}
58
59#[cfg(test)]
60mod tests;