Skip to content

Commit

Permalink
Merge pull request rust-fuzz#46 from c410-f3r/array
Browse files Browse the repository at this point in the history
Impl Arbitrary for [T; 0]
  • Loading branch information
Manishearth committed May 30, 2020
2 parents 1c339b7 + 4478a72 commit 7392124
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,25 @@ macro_rules! arbitrary_array {
($n: expr,) => {};
}

impl<T: Arbitrary> Arbitrary for [T; 0] {
fn arbitrary(_: &mut Unstructured<'_>) -> Result<[T; 0]> {
Ok([])
}

fn arbitrary_take_rest(_: Unstructured<'_>) -> Result<[T; 0]> {
Ok([])
}

#[inline]
fn size_hint(_: usize) -> (usize, Option<usize>) {
crate::size_hint::and_all(&[])
}

fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
Box::new(iter::from_fn(|| None))
}
}

arbitrary_array! { 32, (T, a) (T, b) (T, c) (T, d) (T, e) (T, f) (T, g) (T, h)
(T, i) (T, j) (T, k) (T, l) (T, m) (T, n) (T, o) (T, p)
(T, q) (T, r) (T, s) (T, u) (T, v) (T, w) (T, x) (T, y)
Expand Down

0 comments on commit 7392124

Please sign in to comment.