Skip to content

Commit

Permalink
rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed Nov 23, 2020
1 parent f80cefc commit 7bc17a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 32 deletions.
11 changes: 8 additions & 3 deletions derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ static ARBITRARY_LIFETIME_NAME: &str = "'a";
#[proc_macro_derive(Arbitrary)]
pub fn derive_arbitrary(tokens: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input = syn::parse_macro_input!(tokens as syn::DeriveInput);
let arbitrary_lifetime = LifetimeDef::new(Lifetime::new(ARBITRARY_LIFETIME_NAME, Span::call_site()));
let arbitrary_lifetime =
LifetimeDef::new(Lifetime::new(ARBITRARY_LIFETIME_NAME, Span::call_site()));

let arbitrary_method = gen_arbitrary_method(&input, arbitrary_lifetime.clone());
let size_hint_method = gen_size_hint_method(&input);
Expand All @@ -19,7 +20,9 @@ pub fn derive_arbitrary(tokens: proc_macro::TokenStream) -> proc_macro::TokenStr

// Build ImplGeneric with a lifetime (https://github.com/dtolnay/syn/issues/90)
let mut generics_with_lifetime = generics.clone();
generics_with_lifetime.params.push(GenericParam::Lifetime(arbitrary_lifetime.clone()));
generics_with_lifetime
.params
.push(GenericParam::Lifetime(arbitrary_lifetime.clone()));
let (impl_generics, _, _) = generics_with_lifetime.split_for_impl();

// Build TypeGenerics and WhereClause without a lifetime
Expand All @@ -38,7 +41,9 @@ pub fn derive_arbitrary(tokens: proc_macro::TokenStream) -> proc_macro::TokenStr
fn add_trait_bounds(mut generics: Generics, lifetime: LifetimeDef) -> Generics {
for param in generics.params.iter_mut() {
if let GenericParam::Type(type_param) = param {
type_param.bounds.push(parse_quote!(arbitrary::Arbitrary<#lifetime>));
type_param
.bounds
.push(parse_quote!(arbitrary::Arbitrary<#lifetime>));
}
}
generics
Expand Down
36 changes: 7 additions & 29 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ impl<'a> Arbitrary<'a> for bool {
fn size_hint(depth: usize) -> (usize, Option<usize>) {
<u8 as Arbitrary<'a>>::size_hint(depth)
}

}

macro_rules! impl_arbitrary_for_integers {
Expand Down Expand Up @@ -364,7 +363,6 @@ impl<'a> Arbitrary<'a> for char {
fn size_hint(depth: usize) -> (usize, Option<usize>) {
<u32 as Arbitrary<'a>>::size_hint(depth)
}

}

impl<'a> Arbitrary<'a> for AtomicBool {
Expand All @@ -376,7 +374,6 @@ impl<'a> Arbitrary<'a> for AtomicBool {
fn size_hint(depth: usize) -> (usize, Option<usize>) {
<bool as Arbitrary<'a>>::size_hint(depth)
}

}

impl<'a> Arbitrary<'a> for AtomicIsize {
Expand Down Expand Up @@ -422,7 +419,6 @@ macro_rules! impl_range {
fn size_hint(depth: usize) -> (usize, Option<usize>) {
$size_hint_closure(depth)
}

}
};
}
Expand Down Expand Up @@ -505,7 +501,6 @@ impl<'a> Arbitrary<'a> for Duration {
<u32 as Arbitrary>::size_hint(depth),
)
}

}

impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for Option<A> {
Expand All @@ -524,7 +519,6 @@ impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for Option<A> {
crate::size_hint::or((0, Some(0)), <A as Arbitrary>::size_hint(depth)),
)
}

}

impl<'a, A: Arbitrary<'a>, B: Arbitrary<'a>> Arbitrary<'a> for std::result::Result<A, B> {
Expand All @@ -546,7 +540,6 @@ impl<'a, A: Arbitrary<'a>, B: Arbitrary<'a>> Arbitrary<'a> for std::result::Resu
),
)
}

}

macro_rules! arbitrary_tuple {
Expand Down Expand Up @@ -625,7 +618,6 @@ impl<'a, T: Arbitrary<'a>> Arbitrary<'a> for [T; 0] {
fn size_hint(_: usize) -> (usize, Option<usize>) {
crate::size_hint::and_all(&[])
}

}

arbitrary_array! { 32, (T, a) (T, b) (T, c) (T, d) (T, e) (T, f) (T, g) (T, h)
Expand All @@ -647,7 +639,6 @@ impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for Vec<A> {
fn size_hint(depth: usize) -> (usize, Option<usize>) {
crate::size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
}

}

impl<'a, K: Arbitrary<'a> + Ord, V: Arbitrary<'a>> Arbitrary<'a> for BTreeMap<K, V> {
Expand All @@ -663,7 +654,6 @@ impl<'a, K: Arbitrary<'a> + Ord, V: Arbitrary<'a>> Arbitrary<'a> for BTreeMap<K,
fn size_hint(depth: usize) -> (usize, Option<usize>) {
crate::size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
}

}

impl<'a, A: Arbitrary<'a> + Ord> Arbitrary<'a> for BTreeSet<A> {
Expand All @@ -679,7 +669,6 @@ impl<'a, A: Arbitrary<'a> + Ord> Arbitrary<'a> for BTreeSet<A> {
fn size_hint(depth: usize) -> (usize, Option<usize>) {
crate::size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
}

}

impl<'a, A: Arbitrary<'a> + Ord> Arbitrary<'a> for BinaryHeap<A> {
Expand All @@ -695,10 +684,11 @@ impl<'a, A: Arbitrary<'a> + Ord> Arbitrary<'a> for BinaryHeap<A> {
fn size_hint(depth: usize) -> (usize, Option<usize>) {
crate::size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
}

}

impl<'a, K: Arbitrary<'a> + Eq + ::std::hash::Hash, V: Arbitrary<'a>> Arbitrary<'a> for HashMap<K, V> {
impl<'a, K: Arbitrary<'a> + Eq + ::std::hash::Hash, V: Arbitrary<'a>> Arbitrary<'a>
for HashMap<K, V>
{
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
u.arbitrary_iter()?.collect()
}
Expand All @@ -711,7 +701,6 @@ impl<'a, K: Arbitrary<'a> + Eq + ::std::hash::Hash, V: Arbitrary<'a>> Arbitrary<
fn size_hint(depth: usize) -> (usize, Option<usize>) {
crate::size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
}

}

impl<'a, A: Arbitrary<'a> + Eq + ::std::hash::Hash> Arbitrary<'a> for HashSet<A> {
Expand All @@ -727,7 +716,6 @@ impl<'a, A: Arbitrary<'a> + Eq + ::std::hash::Hash> Arbitrary<'a> for HashSet<A>
fn size_hint(depth: usize) -> (usize, Option<usize>) {
crate::size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
}

}

impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for LinkedList<A> {
Expand All @@ -743,7 +731,6 @@ impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for LinkedList<A> {
fn size_hint(depth: usize) -> (usize, Option<usize>) {
crate::size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
}

}

impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for VecDeque<A> {
Expand All @@ -759,7 +746,6 @@ impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for VecDeque<A> {
fn size_hint(depth: usize) -> (usize, Option<usize>) {
crate::size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
}

}

// TODO: change 'static to 'a?
Expand All @@ -778,7 +764,6 @@ where
<<A as ToOwned>::Owned as Arbitrary>::size_hint(depth)
})
}

}

impl<'a> Arbitrary<'a> for String {
Expand Down Expand Up @@ -812,7 +797,6 @@ impl<'a> Arbitrary<'a> for String {
fn size_hint(depth: usize) -> (usize, Option<usize>) {
crate::size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
}

}

impl<'a> Arbitrary<'a> for CString {
Expand All @@ -827,7 +811,6 @@ impl<'a> Arbitrary<'a> for CString {
fn size_hint(depth: usize) -> (usize, Option<usize>) {
<Vec<u8> as Arbitrary>::size_hint(depth)
}

}

impl<'a> Arbitrary<'a> for OsString {
Expand All @@ -839,7 +822,6 @@ impl<'a> Arbitrary<'a> for OsString {
fn size_hint(depth: usize) -> (usize, Option<usize>) {
<String as Arbitrary>::size_hint(depth)
}

}

impl<'a> Arbitrary<'a> for PathBuf {
Expand All @@ -851,7 +833,6 @@ impl<'a> Arbitrary<'a> for PathBuf {
fn size_hint(depth: usize) -> (usize, Option<usize>) {
<OsString as Arbitrary>::size_hint(depth)
}

}

impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for Box<A> {
Expand All @@ -863,7 +844,6 @@ impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for Box<A> {
fn size_hint(depth: usize) -> (usize, Option<usize>) {
crate::size_hint::recursion_guard(depth, |depth| <A as Arbitrary>::size_hint(depth))
}

}

impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for Box<[A]> {
Expand All @@ -875,7 +855,6 @@ impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for Box<[A]> {
fn size_hint(depth: usize) -> (usize, Option<usize>) {
<Vec<A> as Arbitrary>::size_hint(depth)
}

}

impl<'a> Arbitrary<'a> for Box<str> {
Expand All @@ -887,7 +866,6 @@ impl<'a> Arbitrary<'a> for Box<str> {
fn size_hint(depth: usize) -> (usize, Option<usize>) {
<String as Arbitrary>::size_hint(depth)
}

}

// impl Arbitrary for Box<CStr> {
Expand Down Expand Up @@ -923,7 +901,6 @@ impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for Rc<A> {
fn size_hint(depth: usize) -> (usize, Option<usize>) {
crate::size_hint::recursion_guard(depth, |depth| <A as Arbitrary>::size_hint(depth))
}

}

impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for Cell<A> {
Expand Down Expand Up @@ -968,7 +945,6 @@ impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for Mutex<A> {
fn size_hint(depth: usize) -> (usize, Option<usize>) {
<A as Arbitrary<'a>>::size_hint(depth)
}

}

impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for iter::Empty<A> {
Expand Down Expand Up @@ -1002,7 +978,6 @@ impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for ::std::num::Wrapping<A> {
fn size_hint(depth: usize) -> (usize, Option<usize>) {
<A as Arbitrary<'a>>::size_hint(depth)
}

}

#[cfg(test)]
Expand Down Expand Up @@ -1069,7 +1044,10 @@ mod test {

#[test]
fn size_hint_for_tuples() {
assert_eq!((7, Some(7)), <(bool, u16, i32) as Arbitrary<'_>>::size_hint(0));
assert_eq!(
(7, Some(7)),
<(bool, u16, i32) as Arbitrary<'_>>::size_hint(0)
);
assert_eq!(
(1 + mem::size_of::<usize>(), None),
<(u8, Vec<u8>) as Arbitrary>::size_hint(0)
Expand Down

0 comments on commit 7bc17a1

Please sign in to comment.