Coverage Report

Created: 2025-07-23 06:37

/rust/registry/src/index.crates.io-6f17d22bba15001f/arbitrary-0.4.7/src/lib.rs
Line
Count
Source (jump to first uncovered line)
1
// Copyright © 2019 The Rust Fuzz Project 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
//! The `Arbitrary` trait crate.
10
//!
11
//! This trait provides an [`Arbitrary`](./trait.Arbitrary.html) trait to
12
//! produce well-typed, structured values, from raw, byte buffers. It is
13
//! generally intended to be used with fuzzers like AFL or libFuzzer. See the
14
//! [`Arbitrary`](./trait.Arbitrary.html) trait's documentation for details on
15
//! automatically deriving, implementing, and/or using the trait.
16
17
#![deny(bad_style)]
18
#![deny(missing_docs)]
19
#![deny(future_incompatible)]
20
#![deny(nonstandard_style)]
21
#![deny(rust_2018_compatibility)]
22
#![deny(rust_2018_idioms)]
23
#![deny(unused)]
24
25
#[cfg(feature = "derive_arbitrary")]
26
pub use derive_arbitrary::*;
27
28
mod error;
29
pub use error::*;
30
31
pub mod unstructured;
32
#[doc(inline)]
33
pub use unstructured::Unstructured;
34
35
pub mod size_hint;
36
37
use core::cell::{Cell, RefCell, UnsafeCell};
38
use core::iter;
39
use core::mem;
40
use core::ops::{Range, RangeBounds, RangeFrom, RangeInclusive, RangeTo, RangeToInclusive};
41
use core::str;
42
use core::time::Duration;
43
use std::borrow::{Cow, ToOwned};
44
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
45
use std::ffi::{CString, OsString};
46
use std::path::PathBuf;
47
use std::rc::Rc;
48
use std::sync::atomic::{AtomicBool, AtomicIsize, AtomicUsize, Ordering};
49
use std::sync::{Arc, Mutex};
50
51
0
fn empty<T: 'static>() -> Box<dyn Iterator<Item = T>> {
52
0
    Box::new(iter::empty())
53
0
}
Unexecuted instantiation: arbitrary::empty::<alloc::vec::Vec<char>>
Unexecuted instantiation: arbitrary::empty::<alloc::vec::Vec<u8>>
Unexecuted instantiation: arbitrary::empty::<core::sync::atomic::AtomicBool>
Unexecuted instantiation: arbitrary::empty::<std::ffi::os_str::OsString>
Unexecuted instantiation: arbitrary::empty::<i8>
Unexecuted instantiation: arbitrary::empty::<bool>
Unexecuted instantiation: arbitrary::empty::<f64>
Unexecuted instantiation: arbitrary::empty::<f32>
Unexecuted instantiation: arbitrary::empty::<u8>
Unexecuted instantiation: arbitrary::empty::<isize>
Unexecuted instantiation: arbitrary::empty::<usize>
Unexecuted instantiation: arbitrary::empty::<i32>
Unexecuted instantiation: arbitrary::empty::<u32>
Unexecuted instantiation: arbitrary::empty::<i128>
Unexecuted instantiation: arbitrary::empty::<u128>
Unexecuted instantiation: arbitrary::empty::<i16>
Unexecuted instantiation: arbitrary::empty::<u16>
Unexecuted instantiation: arbitrary::empty::<i64>
Unexecuted instantiation: arbitrary::empty::<u64>
54
55
0
fn once<T: 'static>(val: T) -> Box<dyn Iterator<Item = T>> {
56
0
    Box::new(iter::once(val))
57
0
}
Unexecuted instantiation: arbitrary::once::<core::sync::atomic::AtomicBool>
Unexecuted instantiation: arbitrary::once::<std::ffi::os_str::OsString>
Unexecuted instantiation: arbitrary::once::<bool>
Unexecuted instantiation: arbitrary::once::<f64>
Unexecuted instantiation: arbitrary::once::<f32>
58
59
/// Generate arbitrary structured values from raw, unstructured data.
60
///
61
/// The `Arbitrary` trait allows you to generate valid structured values, like
62
/// `HashMap`s, or ASTs, or `MyTomlConfig`, or any other data structure from
63
/// raw, unstructured bytes provided by a fuzzer. It also features built-in
64
/// shrinking, so that if you find a test case that triggers a bug, you can find
65
/// the smallest, most easiest-to-understand test case that still triggers that
66
/// bug.
67
///
68
/// # Deriving `Arbitrary`
69
///
70
/// Automatically deriving the `Arbitrary` trait is the recommended way to
71
/// implement `Arbitrary` for your types.
72
///
73
/// Using the custom derive requires that you enable the `"derive"` cargo
74
/// feature in your `Cargo.toml`:
75
///
76
/// ```toml
77
/// [dependencies]
78
/// arbitrary = { version = "0.4", features = ["derive"] }
79
/// ```
80
///
81
/// Then, you add the `#[derive(Arbitrary)]` annotation to your `struct` or
82
/// `enum` type definition:
83
///
84
/// ```
85
/// # #[cfg(feature = "derive")] mod foo {
86
/// use arbitrary::Arbitrary;
87
/// use std::collections::HashSet;
88
///
89
/// #[derive(Arbitrary)]
90
/// pub struct AddressBook {
91
///     friends: HashSet<Friend>,
92
/// }
93
///
94
/// #[derive(Arbitrary, Hash, Eq, PartialEq)]
95
/// pub enum Friend {
96
///     Buddy { name: String },
97
///     Pal { age: usize },
98
/// }
99
/// # }
100
/// ```
101
///
102
/// Every member of the `struct` or `enum` must also implement `Arbitrary`.
103
///
104
/// # Implementing `Arbitrary` By Hand
105
///
106
/// Implementing `Arbitrary` mostly involves nested calls to other `Arbitrary`
107
/// arbitrary implementations for each of your `struct` or `enum`'s members. But
108
/// sometimes you need some amount of raw data, or you need to generate a
109
/// variably-sized collection type, or you something of that sort. The
110
/// [`Unstructured`][crate::Unstructured] type helps you with these tasks.
111
///
112
/// ```
113
/// # #[cfg(feature = "derive")] mod foo {
114
/// # pub struct MyCollection<T> { _t: std::marker::PhantomData<T> }
115
/// # impl<T> MyCollection<T> {
116
/// #     pub fn new() -> Self { MyCollection { _t: std::marker::PhantomData } }
117
/// #     pub fn insert(&mut self, element: T) {}
118
/// # }
119
/// use arbitrary::{Arbitrary, Result, Unstructured};
120
///
121
/// impl<T> Arbitrary for MyCollection<T>
122
/// where
123
///     T: Arbitrary,
124
/// {
125
///     fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
126
///         // Get an iterator of arbitrary `T`s.
127
///         let iter = u.arbitrary_iter::<T>()?;
128
///
129
///         // And then create a collection!
130
///         let mut my_collection = MyCollection::new();
131
///         for elem_result in iter {
132
///             let elem = elem_result?;
133
///             my_collection.insert(elem);
134
///         }
135
///
136
///         Ok(my_collection)
137
///     }
138
/// }
139
/// # }
140
/// ```
141
pub trait Arbitrary: Sized + 'static {
142
    /// Generate an arbitrary value of `Self` from the given unstructured data.
143
    ///
144
    /// Calling `Arbitrary::arbitrary` requires that you have some raw data,
145
    /// perhaps given to you by a fuzzer like AFL or libFuzzer. You wrap this
146
    /// raw data in an `Unstructured`, and then you can call `<MyType as
147
    /// Arbitrary>::arbitrary` to construct an arbitrary instance of `MyType`
148
    /// from that unstuctured data.
149
    ///
150
    /// Implementation may return an error if there is not enough data to
151
    /// construct a full instance of `Self`. This is generally OK: it is better
152
    /// to exit early and get the fuzzer to provide more input data, than it is
153
    /// to generate default values in place of the missing data, which would
154
    /// bias the distribution of generated values, and ultimately make fuzzing
155
    /// less efficient.
156
    ///
157
    /// ```
158
    /// # #[cfg(feature = "derive")] fn foo() {
159
    /// use arbitrary::{Arbitrary, Unstructured};
160
    ///
161
    /// #[derive(Arbitrary)]
162
    /// pub struct MyType {
163
    ///     // ...
164
    /// }
165
    ///
166
    /// // Get the raw data from the fuzzer or wherever else.
167
    /// # let get_raw_data_from_fuzzer = || &[];
168
    /// let raw_data: &[u8] = get_raw_data_from_fuzzer();
169
    ///
170
    /// // Wrap that raw data in an `Unstructured`.
171
    /// let mut unstructured = Unstructured::new(raw_data);
172
    ///
173
    /// // Generate an arbitrary instance of `MyType` and do stuff with it.
174
    /// if let Ok(value) = MyType::arbitrary(&mut unstructured) {
175
    /// #   let do_stuff = |_| {};
176
    ///     do_stuff(value);
177
    /// }
178
    /// # }
179
    /// ```
180
    ///
181
    /// See also the documentation for [`Unstructured`][crate::Unstructured].
182
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self>;
183
184
    /// Generate an arbitrary value of `Self` from the entirety of the given unstructured data.
185
    ///
186
    /// This is similar to Arbitrary::arbitrary, however it assumes that it is the
187
    /// last consumer of the given data, and is thus able to consume it all if it needs.
188
    /// See also the documentation for [`Unstructured`][crate::Unstructured].
189
0
    fn arbitrary_take_rest(mut u: Unstructured<'_>) -> Result<Self> {
190
0
        Self::arbitrary(&mut u)
191
0
    }
192
193
    /// Get a size hint for how many bytes out of an `Unstructured` this type
194
    /// needs to construct itself.
195
    ///
196
    /// This is useful for determining how many elements we should insert when
197
    /// creating an arbitrary collection.
198
    ///
199
    /// The return value is similar to
200
    /// [`Iterator::size_hint`][iterator-size-hint]: it returns a tuple where
201
    /// the first element is a lower bound on the number of bytes required, and
202
    /// the second element is an optional upper bound.
203
    ///
204
    /// The default implementation return `(0, None)` which is correct for any
205
    /// type, but not ultimately that useful. Using `#[derive(Arbitrary)]` will
206
    /// create a better implementation. If you are writing an `Arbitrary`
207
    /// implementation by hand, and your type can be part of a dynamically sized
208
    /// collection (such as `Vec`), you are strongly encouraged to override this
209
    /// default with a better implementation. The
210
    /// [`size_hint`][crate::size_hint] module will help with this task.
211
    ///
212
    /// ## The `depth` Parameter
213
    ///
214
    /// If you 100% know that the type you are implementing `Arbitrary` for is
215
    /// not a recursive type, or your implementation is not transitively calling
216
    /// any other `size_hint` methods, you can ignore the `depth` parameter.
217
    /// Note that if you are implementing `Arbitrary` for a generic type, you
218
    /// cannot guarantee the lack of type recrusion!
219
    ///
220
    /// Otherwise, you need to use
221
    /// [`arbitrary::size_hint::recursion_guard(depth)`][crate::size_hint::recursion_guard]
222
    /// to prevent potential infinite recursion when calculating size hints for
223
    /// potentially recursive types:
224
    ///
225
    /// ```
226
    /// use arbitrary::{Arbitrary, Unstructured, size_hint};
227
    ///
228
    /// // This can potentially be a recursive type if `L` or `R` contain
229
    /// // something like `Box<Option<MyEither<L, R>>>`!
230
    /// enum MyEither<L, R> {
231
    ///     Left(L),
232
    ///     Right(R),
233
    /// }
234
    ///
235
    /// impl<L, R> Arbitrary for MyEither<L, R>
236
    /// where
237
    ///     L: Arbitrary,
238
    ///     R: Arbitrary,
239
    /// {
240
    ///     fn arbitrary(u: &mut Unstructured) -> arbitrary::Result<Self> {
241
    ///         // ...
242
    /// #       unimplemented!()
243
    ///     }
244
    ///
245
    ///     fn size_hint(depth: usize) -> (usize, Option<usize>) {
246
    ///         // Protect against potential infinite recursion with
247
    ///         // `recursion_guard`.
248
    ///         size_hint::recursion_guard(depth, |depth| {
249
    ///             // If we aren't too deep, then `recursion_guard` calls
250
    ///             // this closure, which implements the natural size hint.
251
    ///             // Don't forget to use the new `depth` in all nested
252
    ///             // `size_hint` calls! We recommend shadowing the
253
    ///             // parameter, like what is done here, so that you can't
254
    ///             // accidentally use the wrong depth.
255
    ///             size_hint::or(
256
    ///                 <L as Arbitrary>::size_hint(depth),
257
    ///                 <R as Arbitrary>::size_hint(depth),
258
    ///             )
259
    ///         })
260
    ///     }
261
    /// }
262
    /// ```
263
    ///
264
    /// [iterator-size-hint]: https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html#method.size_hint
265
    #[inline]
266
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
267
0
        let _ = depth;
268
0
        (0, None)
269
0
    }
270
271
    /// Generate an iterator of derived values which are "smaller" than the
272
    /// original `self` instance.
273
    ///
274
    /// You can use this to help find the smallest test case that reproduces a
275
    /// bug.
276
    ///
277
    /// Using `#[derive(Arbitrary)]` will automatically implement shrinking for
278
    /// your type.
279
    ///
280
    /// However, if you are implementing `Arbirary` by hand and you want support
281
    /// for shrinking your type, you must override the default provided
282
    /// implementation of `shrink`, which just returns an empty iterator. You
283
    /// should try pretty hard to have your `shrink` implementation return a
284
    /// *lazy* iterator: one that computes the next value as it is needed,
285
    /// rather than computing them up front when `shrink` is first called.
286
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
287
0
        empty()
288
0
    }
289
}
290
291
impl Arbitrary for () {
292
0
    fn arbitrary(_: &mut Unstructured<'_>) -> Result<Self> {
293
0
        Ok(())
294
0
    }
295
296
    #[inline]
297
0
    fn size_hint(_depth: usize) -> (usize, Option<usize>) {
298
0
        (0, Some(0))
299
0
    }
300
}
301
302
impl Arbitrary for bool {
303
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
304
0
        Ok(<u8 as Arbitrary>::arbitrary(u)? & 1 == 1)
305
0
    }
306
307
    #[inline]
308
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
309
0
        <u8 as Arbitrary>::size_hint(depth)
310
0
    }
311
312
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
313
0
        Box::new(if *self { once(false) } else { empty() })
314
0
    }
315
}
316
317
macro_rules! impl_arbitrary_for_integers {
318
    ( $( $ty:ty: $unsigned:ty; )* ) => {
319
        $(
320
            impl Arbitrary for $ty {
321
3.68k
                fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
322
3.68k
                    let mut buf = [0; mem::size_of::<$ty>()];
323
3.68k
                    u.fill_buffer(&mut buf)?;
324
3.68k
                    let mut x: $unsigned = 0;
325
3.68k
                    for i in 0..mem::size_of::<$ty>() {
326
3.68k
                        x |= buf[i] as $unsigned << (i * 8);
327
3.68k
                    }
328
3.68k
                    Ok(x as $ty)
329
3.68k
                }
<u8 as arbitrary::Arbitrary>::arbitrary
Line
Count
Source
321
3.68k
                fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
322
3.68k
                    let mut buf = [0; mem::size_of::<$ty>()];
323
3.68k
                    u.fill_buffer(&mut buf)?;
324
3.68k
                    let mut x: $unsigned = 0;
325
3.68k
                    for i in 0..mem::size_of::<$ty>() {
326
3.68k
                        x |= buf[i] as $unsigned << (i * 8);
327
3.68k
                    }
328
3.68k
                    Ok(x as $ty)
329
3.68k
                }
Unexecuted instantiation: <u16 as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <u32 as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <u64 as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <u128 as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <usize as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <i8 as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <i16 as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <i32 as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <i64 as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <i128 as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <isize as arbitrary::Arbitrary>::arbitrary
330
331
                #[inline]
332
15.3k
                fn size_hint(_depth: usize) -> (usize, Option<usize>) {
333
15.3k
                    let n = mem::size_of::<$ty>();
334
15.3k
                    (n, Some(n))
335
15.3k
                }
<usize as arbitrary::Arbitrary>::size_hint
Line
Count
Source
332
5.53k
                fn size_hint(_depth: usize) -> (usize, Option<usize>) {
333
5.53k
                    let n = mem::size_of::<$ty>();
334
5.53k
                    (n, Some(n))
335
5.53k
                }
Unexecuted instantiation: <u8 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <u16 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <u32 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <u64 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <u128 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <usize as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <i8 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <i16 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <i32 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <i64 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <i128 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <isize as arbitrary::Arbitrary>::size_hint
<usize as arbitrary::Arbitrary>::size_hint
Line
Count
Source
332
2.37k
                fn size_hint(_depth: usize) -> (usize, Option<usize>) {
333
2.37k
                    let n = mem::size_of::<$ty>();
334
2.37k
                    (n, Some(n))
335
2.37k
                }
<usize as arbitrary::Arbitrary>::size_hint
Line
Count
Source
332
3.70k
                fn size_hint(_depth: usize) -> (usize, Option<usize>) {
333
3.70k
                    let n = mem::size_of::<$ty>();
334
3.70k
                    (n, Some(n))
335
3.70k
                }
<u8 as arbitrary::Arbitrary>::size_hint
Line
Count
Source
332
3.70k
                fn size_hint(_depth: usize) -> (usize, Option<usize>) {
333
3.70k
                    let n = mem::size_of::<$ty>();
334
3.70k
                    (n, Some(n))
335
3.70k
                }
336
337
0
                fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
338
0
                    let mut x = *self;
339
0
                    if x == 0 {
340
0
                        return empty();
341
0
                    }
342
0
                    Box::new(iter::once(0).chain(std::iter::from_fn(move || {
343
0
                        x = x / 2;
344
0
                        if x == 0 {
345
0
                            None
346
                        } else {
347
0
                            Some(x)
348
                        }
349
0
                    })))
Unexecuted instantiation: <u8 as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <u16 as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <u32 as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <u64 as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <u128 as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <usize as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <i8 as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <i16 as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <i32 as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <i64 as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <i128 as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <isize as arbitrary::Arbitrary>::shrink::{closure#0}
350
0
                }
Unexecuted instantiation: <u8 as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <u16 as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <u32 as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <u64 as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <u128 as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <usize as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <i8 as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <i16 as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <i32 as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <i64 as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <i128 as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <isize as arbitrary::Arbitrary>::shrink
351
            }
352
        )*
353
    }
354
}
355
356
impl_arbitrary_for_integers! {
357
    u8: u8;
358
    u16: u16;
359
    u32: u32;
360
    u64: u64;
361
    u128: u128;
362
    usize: usize;
363
    i8: u8;
364
    i16: u16;
365
    i32: u32;
366
    i64: u64;
367
    i128: u128;
368
    isize: usize;
369
}
370
371
macro_rules! impl_arbitrary_for_floats {
372
    ( $( $ty:ident : $unsigned:ty; )* ) => {
373
        $(
374
            impl Arbitrary for $ty {
375
0
                fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
376
0
                    Ok(Self::from_bits(<$unsigned as Arbitrary>::arbitrary(u)?))
377
0
                }
Unexecuted instantiation: <f32 as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <f64 as arbitrary::Arbitrary>::arbitrary
378
379
                #[inline]
380
0
                fn size_hint(depth: usize) -> (usize, Option<usize>) {
381
0
                    <$unsigned as Arbitrary>::size_hint(depth)
382
0
                }
Unexecuted instantiation: <f32 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <f64 as arbitrary::Arbitrary>::size_hint
383
384
0
                fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
385
0
                    if *self == 0.0 {
386
0
                        empty()
387
0
                    } else if !self.is_finite() {
388
0
                        once(0.0)
389
                    } else {
390
0
                        let mut x = *self;
391
0
                        Box::new(iter::once(0.0).chain(iter::from_fn(move || {
392
0
                            // NB: do not test for zero like we do for integers
393
0
                            // because dividing by two until we reach a fixed
394
0
                            // point is NOT guaranteed to end at zero in
395
0
                            // non-default rounding modes of IEEE-754!
396
0
                            //
397
0
                            // For example, with 64-bit floats and the
398
0
                            // round-to-positive-infinity mode:
399
0
                            //
400
0
                            //     5e-324 / 2.0 == 5e-324
401
0
                            //
402
0
                            // (5e-234 is the smallest postive number that can
403
0
                            // be precisely represented in a 64-bit float.)
404
0
                            let y = x;
405
0
                            x = x / 2.0;
406
0
                            if x == y {
407
0
                                None
408
                            } else {
409
0
                                Some(x)
410
                            }
411
0
                        })))
Unexecuted instantiation: <f32 as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <f64 as arbitrary::Arbitrary>::shrink::{closure#0}
412
                    }
413
0
                }
Unexecuted instantiation: <f32 as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <f64 as arbitrary::Arbitrary>::shrink
414
            }
415
        )*
416
    }
417
}
418
419
impl_arbitrary_for_floats! {
420
    f32: u32;
421
    f64: u64;
422
}
423
424
impl Arbitrary for char {
425
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
426
        use std::char;
427
        const CHAR_END: u32 = 0x0011_000;
428
        // The size of the surrogate blocks
429
        const SURROGATES_START: u32 = 0xD800;
430
0
        let mut c = <u32 as Arbitrary>::arbitrary(u)? % CHAR_END;
431
0
        if let Some(c) = char::from_u32(c) {
432
0
            return Ok(c);
433
        } else {
434
            // We found a surrogate, wrap and try again
435
0
            c -= SURROGATES_START;
436
0
            Ok(char::from_u32(c)
437
0
                .expect("Generated character should be valid! This is a bug in arbitrary-rs"))
438
        }
439
0
    }
440
441
    #[inline]
442
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
443
0
        <u32 as Arbitrary>::size_hint(depth)
444
0
    }
445
446
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
447
0
        let x = *self as u32;
448
0
        Box::new(x.shrink().filter_map(|x| {
449
            use std::convert::TryFrom;
450
0
            char::try_from(x).ok()
451
0
        }))
452
0
    }
453
}
454
455
impl Arbitrary for AtomicBool {
456
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
457
0
        Arbitrary::arbitrary(u).map(Self::new)
458
0
    }
459
460
    #[inline]
461
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
462
0
        <bool as Arbitrary>::size_hint(depth)
463
0
    }
464
465
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
466
0
        if self.load(Ordering::SeqCst) {
467
0
            once(AtomicBool::new(false))
468
        } else {
469
0
            empty()
470
        }
471
0
    }
472
}
473
474
impl Arbitrary for AtomicIsize {
475
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
476
0
        Arbitrary::arbitrary(u).map(Self::new)
477
0
    }
478
479
    #[inline]
480
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
481
0
        <isize as Arbitrary>::size_hint(depth)
482
0
    }
483
484
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
485
0
        let x = self.load(Ordering::SeqCst);
486
0
        Box::new(x.shrink().map(Self::new))
487
0
    }
488
}
489
490
impl Arbitrary for AtomicUsize {
491
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
492
0
        Arbitrary::arbitrary(u).map(Self::new)
493
0
    }
494
495
    #[inline]
496
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
497
0
        <usize as Arbitrary>::size_hint(depth)
498
0
    }
499
500
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
501
0
        let x = self.load(Ordering::SeqCst);
502
0
        Box::new(x.shrink().map(Self::new))
503
0
    }
504
}
505
506
macro_rules! impl_range {
507
    (
508
        $range:ty,
509
        $value_closure:expr,
510
        $value_ty:ty,
511
        $fun:ident($fun_closure:expr),
512
        $size_hint_closure:expr
513
    ) => {
514
        impl<A> Arbitrary for $range
515
        where
516
            A: Arbitrary + Clone + PartialOrd,
517
        {
518
0
            fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
519
0
                let value: $value_ty = Arbitrary::arbitrary(u)?;
520
0
                Ok($fun(value, $fun_closure))
521
0
            }
Unexecuted instantiation: <core::ops::range::Range<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::ops::range::RangeFrom<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::ops::range::RangeInclusive<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::ops::range::RangeTo<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::ops::range::RangeToInclusive<_> as arbitrary::Arbitrary>::arbitrary
522
523
            #[inline]
524
0
            fn size_hint(depth: usize) -> (usize, Option<usize>) {
525
0
                $size_hint_closure(depth)
526
0
            }
Unexecuted instantiation: <core::ops::range::Range<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::ops::range::RangeFrom<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::ops::range::RangeInclusive<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::ops::range::RangeTo<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::ops::range::RangeToInclusive<_> as arbitrary::Arbitrary>::size_hint
527
528
0
            fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
529
0
                let value: $value_ty = $value_closure(self);
530
0
                Box::new(value.shrink().map(|v| $fun(v, $fun_closure)))
Unexecuted instantiation: <core::ops::range::Range<_> as arbitrary::Arbitrary>::shrink::{closure#1}
Unexecuted instantiation: <core::ops::range::RangeFrom<_> as arbitrary::Arbitrary>::shrink::{closure#1}
Unexecuted instantiation: <core::ops::range::RangeInclusive<_> as arbitrary::Arbitrary>::shrink::{closure#1}
Unexecuted instantiation: <core::ops::range::RangeTo<_> as arbitrary::Arbitrary>::shrink::{closure#1}
Unexecuted instantiation: <core::ops::range::RangeToInclusive<_> as arbitrary::Arbitrary>::shrink::{closure#1}
531
0
            }
Unexecuted instantiation: <core::ops::range::Range<_> as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <core::ops::range::RangeFrom<_> as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <core::ops::range::RangeInclusive<_> as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <core::ops::range::RangeTo<_> as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <core::ops::range::RangeToInclusive<_> as arbitrary::Arbitrary>::shrink
532
        }
533
    };
534
}
535
536
impl_range!(
537
    Range<A>,
538
0
    |r: &Range<A>| (r.start.clone(), r.end.clone()),
539
    (A, A),
540
0
    bounded_range(|(a, b)| a..b),
Unexecuted instantiation: <core::ops::range::Range<_> as arbitrary::Arbitrary>::arbitrary::{closure#0}
Unexecuted instantiation: <core::ops::range::Range<_> as arbitrary::Arbitrary>::shrink::{closure#1}::{closure#0}
541
0
    |depth| crate::size_hint::and(
542
0
        <A as Arbitrary>::size_hint(depth),
543
0
        <A as Arbitrary>::size_hint(depth)
544
0
    )
545
);
546
impl_range!(
547
    RangeFrom<A>,
548
0
    |r: &RangeFrom<A>| r.start.clone(),
549
    A,
550
0
    unbounded_range(|a| a..),
Unexecuted instantiation: <core::ops::range::RangeFrom<_> as arbitrary::Arbitrary>::arbitrary::{closure#0}
Unexecuted instantiation: <core::ops::range::RangeFrom<_> as arbitrary::Arbitrary>::shrink::{closure#1}::{closure#0}
551
0
    |depth| <A as Arbitrary>::size_hint(depth)
552
);
553
impl_range!(
554
    RangeInclusive<A>,
555
0
    |r: &RangeInclusive<A>| (r.start().clone(), r.end().clone()),
556
    (A, A),
557
0
    bounded_range(|(a, b)| a..=b),
Unexecuted instantiation: <core::ops::range::RangeInclusive<_> as arbitrary::Arbitrary>::arbitrary::{closure#0}
Unexecuted instantiation: <core::ops::range::RangeInclusive<_> as arbitrary::Arbitrary>::shrink::{closure#1}::{closure#0}
558
0
    |depth| crate::size_hint::and(
559
0
        <A as Arbitrary>::size_hint(depth),
560
0
        <A as Arbitrary>::size_hint(depth)
561
0
    )
562
);
563
impl_range!(
564
    RangeTo<A>,
565
0
    |r: &RangeTo<A>| r.end.clone(),
566
    A,
567
0
    unbounded_range(|b| ..b),
Unexecuted instantiation: <core::ops::range::RangeTo<_> as arbitrary::Arbitrary>::arbitrary::{closure#0}
Unexecuted instantiation: <core::ops::range::RangeTo<_> as arbitrary::Arbitrary>::shrink::{closure#1}::{closure#0}
568
0
    |depth| <A as Arbitrary>::size_hint(depth)
569
);
570
impl_range!(
571
    RangeToInclusive<A>,
572
0
    |r: &RangeToInclusive<A>| r.end.clone(),
573
    A,
574
0
    unbounded_range(|b| ..=b),
Unexecuted instantiation: <core::ops::range::RangeToInclusive<_> as arbitrary::Arbitrary>::arbitrary::{closure#0}
Unexecuted instantiation: <core::ops::range::RangeToInclusive<_> as arbitrary::Arbitrary>::shrink::{closure#1}::{closure#0}
575
0
    |depth| <A as Arbitrary>::size_hint(depth)
576
);
577
578
0
fn bounded_range<CB, I, R>(bounds: (I, I), cb: CB) -> R
579
0
where
580
0
    CB: Fn((I, I)) -> R,
581
0
    I: PartialOrd,
582
0
    R: RangeBounds<I>,
583
0
{
584
0
    let (mut start, mut end) = bounds;
585
0
    if start > end {
586
0
        mem::swap(&mut start, &mut end);
587
0
    }
588
0
    cb((start, end))
589
0
}
590
591
0
fn unbounded_range<CB, I, R>(bound: I, cb: CB) -> R
592
0
where
593
0
    CB: Fn(I) -> R,
594
0
    R: RangeBounds<I>,
595
0
{
596
0
    cb(bound)
597
0
}
598
599
impl Arbitrary for Duration {
600
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
601
0
        Ok(Self::new(
602
0
            <u64 as Arbitrary>::arbitrary(u)?,
603
0
            u.int_in_range(0..=999_999_999)?,
604
        ))
605
0
    }
606
607
    #[inline]
608
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
609
0
        crate::size_hint::and(
610
0
            <u64 as Arbitrary>::size_hint(depth),
611
0
            <u32 as Arbitrary>::size_hint(depth),
612
0
        )
613
0
    }
614
615
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
616
0
        Box::new(
617
0
            (self.as_secs(), self.subsec_nanos())
618
0
                .shrink()
619
0
                .map(|(secs, nanos)| Duration::new(secs, nanos % 1_000_000_000)),
620
0
        )
621
0
    }
622
}
623
624
impl<A: Arbitrary> Arbitrary for Option<A> {
625
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
626
0
        Ok(if <bool as Arbitrary>::arbitrary(u)? {
627
0
            Some(Arbitrary::arbitrary(u)?)
628
        } else {
629
0
            None
630
        })
631
0
    }
632
633
    #[inline]
634
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
635
0
        crate::size_hint::and(
636
0
            <bool as Arbitrary>::size_hint(depth),
637
0
            crate::size_hint::or((0, Some(0)), <A as Arbitrary>::size_hint(depth)),
638
0
        )
639
0
    }
640
641
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
642
0
        if let Some(ref a) = *self {
643
0
            Box::new(iter::once(None).chain(a.shrink().map(Some)))
644
        } else {
645
0
            empty()
646
        }
647
0
    }
648
}
649
650
impl<A: Arbitrary, B: Arbitrary> Arbitrary for std::result::Result<A, B> {
651
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
652
0
        Ok(if <bool as Arbitrary>::arbitrary(u)? {
653
0
            Ok(<A as Arbitrary>::arbitrary(u)?)
654
        } else {
655
0
            Err(<B as Arbitrary>::arbitrary(u)?)
656
        })
657
0
    }
658
659
    #[inline]
660
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
661
0
        crate::size_hint::and(
662
0
            <bool as Arbitrary>::size_hint(depth),
663
0
            crate::size_hint::or(
664
0
                <A as Arbitrary>::size_hint(depth),
665
0
                <B as Arbitrary>::size_hint(depth),
666
0
            ),
667
0
        )
668
0
    }
669
670
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
671
0
        match *self {
672
0
            Ok(ref a) => Box::new(a.shrink().map(Ok)),
673
0
            Err(ref b) => Box::new(b.shrink().map(Err)),
674
        }
675
0
    }
676
}
677
678
macro_rules! arbitrary_tuple {
679
    () => {};
680
    ($last: ident $($xs: ident)*) => {
681
        arbitrary_tuple!($($xs)*);
682
683
        impl<$($xs: Arbitrary,)* $last: Arbitrary> Arbitrary for ($($xs,)* $last,) {
684
0
            fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
685
0
                Ok(($($xs::arbitrary(u)?,)* Arbitrary::arbitrary(u)?,))
686
0
            }
Unexecuted instantiation: <(_,) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _, _, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary
687
688
            #[allow(unused_mut, non_snake_case)]
689
3.68k
            fn arbitrary_take_rest(mut u: Unstructured<'_>) -> Result<Self> {
690
3.68k
                $(let $xs = $xs::arbitrary(&mut u)?;)*
691
3.68k
                let $last = $last::arbitrary_take_rest(u)?;
692
3.66k
                Ok(($($xs,)* $last,))
693
3.68k
            }
Unexecuted instantiation: <(_,) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::arbitrary_take_rest
<(u8, alloc::string::String) as arbitrary::Arbitrary>::arbitrary_take_rest
Line
Count
Source
689
3.68k
            fn arbitrary_take_rest(mut u: Unstructured<'_>) -> Result<Self> {
690
3.68k
                $(let $xs = $xs::arbitrary(&mut u)?;)*
691
3.68k
                let $last = $last::arbitrary_take_rest(u)?;
692
3.66k
                Ok(($($xs,)* $last,))
693
3.68k
            }
694
695
            #[inline]
696
3.70k
            fn size_hint(depth: usize) -> (usize, Option<usize>) {
697
3.70k
                crate::size_hint::and_all(&[
698
3.70k
                    <$last as Arbitrary>::size_hint(depth),
699
3.70k
                    $( <$xs as Arbitrary>::size_hint(depth) ),*
700
3.70k
                ])
701
3.70k
            }
Unexecuted instantiation: <(_,) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _, _, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _, _, _, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _, _, _, _, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::size_hint
<(u8, alloc::string::String) as arbitrary::Arbitrary>::size_hint
Line
Count
Source
696
3.70k
            fn size_hint(depth: usize) -> (usize, Option<usize>) {
697
3.70k
                crate::size_hint::and_all(&[
698
3.70k
                    <$last as Arbitrary>::size_hint(depth),
699
3.70k
                    $( <$xs as Arbitrary>::size_hint(depth) ),*
700
3.70k
                ])
701
3.70k
            }
702
703
            #[allow(non_snake_case)]
704
0
            fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
705
0
                let ( $( $xs, )* $last, ) = self;
706
0
                let ( $( mut $xs, )* mut $last,) = ( $( $xs.shrink(), )* $last.shrink(),);
707
0
                Box::new(iter::from_fn(move || {
708
0
                    Some(( $( $xs.next()? ,)* $last.next()?, ))
709
0
                }))
Unexecuted instantiation: <(u64, u32) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_,) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _, _, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink::{closure#0}
710
0
            }
Unexecuted instantiation: <(u64, u32) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_,) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _, _) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _, _, _) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _, _, _, _) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as arbitrary::Arbitrary>::shrink
711
        }
712
    };
713
}
714
arbitrary_tuple!(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z);
715
716
macro_rules! arbitrary_array {
717
    {$n:expr, ($t:ident, $a:ident) $(($ts:ident, $as:ident))*} => {
718
        arbitrary_array!{($n - 1), $(($ts, $as))*}
719
720
        impl<T: Arbitrary> Arbitrary for [T; $n] {
721
0
            fn arbitrary(u: &mut Unstructured<'_>) -> Result<[T; $n]> {
722
0
                Ok([
723
0
                    Arbitrary::arbitrary(u)?,
724
0
                    $(<$ts as Arbitrary>::arbitrary(u)?),*
725
                ])
726
0
            }
Unexecuted instantiation: <[_; 1] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 2] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 3] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 4] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 5] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 6] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 7] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 8] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 9] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 10] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 11] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 12] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 13] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 14] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 15] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 16] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 17] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 18] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 19] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 20] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 21] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 22] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 23] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 24] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 25] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 26] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 27] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 28] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 29] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 30] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 31] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; 32] as arbitrary::Arbitrary>::arbitrary
727
728
            #[allow(unused_mut)]
729
0
            fn arbitrary_take_rest(mut u: Unstructured<'_>) -> Result<[T; $n]> {
730
0
                $(let $as = $ts::arbitrary(&mut u)?;)*
731
0
                let last = Arbitrary::arbitrary_take_rest(u)?;
732
733
0
                Ok([
734
0
                    $($as,)* last
735
0
                ])
736
0
            }
Unexecuted instantiation: <[_; 1] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 2] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 3] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 4] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 5] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 6] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 7] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 8] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 9] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 10] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 11] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 12] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 13] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 14] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 15] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 16] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 17] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 18] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 19] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 20] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 21] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 22] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 23] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 24] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 25] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 26] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 27] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 28] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 29] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 30] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 31] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; 32] as arbitrary::Arbitrary>::arbitrary_take_rest
737
738
            #[inline]
739
0
            fn size_hint(depth: usize) -> (usize, Option<usize>) {
740
0
                crate::size_hint::and_all(&[
741
0
                    <$t as Arbitrary>::size_hint(depth),
742
0
                    $( <$ts as Arbitrary>::size_hint(depth) ),*
743
0
                ])
744
0
            }
Unexecuted instantiation: <[_; 1] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 2] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 3] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 4] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 5] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 6] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 7] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 8] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 9] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 10] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 11] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 12] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 13] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 14] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 15] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 16] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 17] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 18] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 19] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 20] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 21] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 22] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 23] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 24] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 25] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 26] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 27] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 28] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 29] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 30] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 31] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; 32] as arbitrary::Arbitrary>::size_hint
745
746
            #[allow(unused_mut)] // For the `[T; 1]` case.
747
0
            fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
748
0
                let mut i = 0;
749
0
                let mut shrinkers = [
750
0
                    self[i].shrink(),
751
0
                    $({
752
0
                        i += 1;
753
0
                        let t: &$ts = &self[i];
754
0
                        t.shrink()
755
0
                    }),*
756
0
                ];
757
0
                Box::new(iter::from_fn(move || {
758
0
                    let mut i = 0;
759
0
                    Some([
760
0
                        shrinkers[i].next()?,
761
                        $({
762
0
                            i += 1;
763
0
                            let t: $ts = shrinkers[i].next()?;
764
0
                            t
765
                        }),*
766
                    ])
767
0
                }))
Unexecuted instantiation: <[_; 1] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 2] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 3] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 4] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 5] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 6] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 7] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 8] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 9] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 10] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 11] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 12] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 13] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 14] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 15] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 16] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 17] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 18] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 19] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 20] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 21] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 22] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 23] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 24] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 25] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 26] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 27] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 28] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 29] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 30] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 31] as arbitrary::Arbitrary>::shrink::{closure#0}
Unexecuted instantiation: <[_; 32] as arbitrary::Arbitrary>::shrink::{closure#0}
768
0
            }
Unexecuted instantiation: <[_; 1] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 2] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 3] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 4] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 5] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 6] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 7] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 8] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 9] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 10] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 11] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 12] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 13] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 14] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 15] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 16] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 17] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 18] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 19] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 20] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 21] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 22] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 23] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 24] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 25] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 26] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 27] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 28] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 29] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 30] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 31] as arbitrary::Arbitrary>::shrink
Unexecuted instantiation: <[_; 32] as arbitrary::Arbitrary>::shrink
769
        }
770
    };
771
    ($n: expr,) => {};
772
}
773
774
impl<T: Arbitrary> Arbitrary for [T; 0] {
775
0
    fn arbitrary(_: &mut Unstructured<'_>) -> Result<[T; 0]> {
776
0
        Ok([])
777
0
    }
778
779
0
    fn arbitrary_take_rest(_: Unstructured<'_>) -> Result<[T; 0]> {
780
0
        Ok([])
781
0
    }
782
783
    #[inline]
784
0
    fn size_hint(_: usize) -> (usize, Option<usize>) {
785
0
        crate::size_hint::and_all(&[])
786
0
    }
787
788
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
789
0
        Box::new(iter::from_fn(|| None))
790
0
    }
791
}
792
793
arbitrary_array! { 32, (T, a) (T, b) (T, c) (T, d) (T, e) (T, f) (T, g) (T, h)
794
(T, i) (T, j) (T, k) (T, l) (T, m) (T, n) (T, o) (T, p)
795
(T, q) (T, r) (T, s) (T, u) (T, v) (T, w) (T, x) (T, y)
796
(T, z) (T, aa) (T, ab) (T, ac) (T, ad) (T, ae) (T, af)
797
(T, ag) }
798
799
0
fn shrink_collection<'a, T, A: Arbitrary>(
800
0
    entries: impl Iterator<Item = T>,
801
0
    f: impl Fn(&T) -> Box<dyn Iterator<Item = A>>,
802
0
) -> Box<dyn Iterator<Item = Vec<A>>> {
803
0
    let entries: Vec<_> = entries.collect();
804
0
    if entries.is_empty() {
805
0
        return empty();
806
0
    }
807
0
808
0
    let mut shrinkers: Vec<Vec<_>> = vec![];
809
0
    let mut i = entries.len();
810
    loop {
811
0
        shrinkers.push(entries.iter().take(i).map(&f).collect());
812
0
        i = i / 2;
813
0
        if i == 0 {
814
0
            break;
815
0
        }
816
    }
817
0
    Box::new(iter::once(vec![]).chain(iter::from_fn(move || loop {
818
0
        let mut shrinker = shrinkers.pop()?;
819
0
        let x: Option<Vec<A>> = shrinker.iter_mut().map(|s| s.next()).collect();
Unexecuted instantiation: arbitrary::shrink_collection::<&u8, u8, core::slice::iter::Iter<u8>, <alloc::ffi::c_str::CString as arbitrary::Arbitrary>::shrink::{closure#0}>::{closure#0}::{closure#0}
Unexecuted instantiation: arbitrary::shrink_collection::<char, char, core::str::iter::Chars, <alloc::string::String as arbitrary::Arbitrary>::shrink::{closure#0}>::{closure#0}::{closure#0}
Unexecuted instantiation: arbitrary::shrink_collection::<char, char, core::str::iter::Chars, <alloc::boxed::Box<str> as arbitrary::Arbitrary>::shrink::{closure#0}>::{closure#0}::{closure#0}
820
0
        if x.is_none() {
821
0
            continue;
822
0
        }
823
0
        shrinkers.push(shrinker);
824
0
        return x;
825
0
    })))
Unexecuted instantiation: arbitrary::shrink_collection::<&u8, u8, core::slice::iter::Iter<u8>, <alloc::ffi::c_str::CString as arbitrary::Arbitrary>::shrink::{closure#0}>::{closure#0}
Unexecuted instantiation: arbitrary::shrink_collection::<char, char, core::str::iter::Chars, <alloc::string::String as arbitrary::Arbitrary>::shrink::{closure#0}>::{closure#0}
Unexecuted instantiation: arbitrary::shrink_collection::<char, char, core::str::iter::Chars, <alloc::boxed::Box<str> as arbitrary::Arbitrary>::shrink::{closure#0}>::{closure#0}
826
0
}
Unexecuted instantiation: arbitrary::shrink_collection::<&u8, u8, core::slice::iter::Iter<u8>, <alloc::ffi::c_str::CString as arbitrary::Arbitrary>::shrink::{closure#0}>
Unexecuted instantiation: arbitrary::shrink_collection::<char, char, core::str::iter::Chars, <alloc::string::String as arbitrary::Arbitrary>::shrink::{closure#0}>
Unexecuted instantiation: arbitrary::shrink_collection::<char, char, core::str::iter::Chars, <alloc::boxed::Box<str> as arbitrary::Arbitrary>::shrink::{closure#0}>
827
828
impl<A: Arbitrary> Arbitrary for Vec<A> {
829
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
830
0
        u.arbitrary_iter()?.collect()
831
0
    }
832
833
0
    fn arbitrary_take_rest(u: Unstructured<'_>) -> Result<Self> {
834
0
        u.arbitrary_take_rest_iter()?.collect()
835
0
    }
836
837
    #[inline]
838
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
839
0
        crate::size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
840
0
    }
841
842
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
843
0
        shrink_collection(self.iter(), |x| x.shrink())
844
0
    }
845
}
846
847
impl<K: Arbitrary + Ord, V: Arbitrary> Arbitrary for BTreeMap<K, V> {
848
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
849
0
        u.arbitrary_iter()?.collect()
850
0
    }
851
852
0
    fn arbitrary_take_rest(u: Unstructured<'_>) -> Result<Self> {
853
0
        u.arbitrary_take_rest_iter()?.collect()
854
0
    }
855
856
    #[inline]
857
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
858
0
        crate::size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
859
0
    }
860
861
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
862
0
        let collections =
863
0
            shrink_collection(self.iter(), |(k, v)| Box::new(k.shrink().zip(v.shrink())));
864
0
        Box::new(collections.map(|entries| entries.into_iter().collect()))
865
0
    }
866
}
867
868
impl<A: Arbitrary + Ord> Arbitrary for BTreeSet<A> {
869
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
870
0
        u.arbitrary_iter()?.collect()
871
0
    }
872
873
0
    fn arbitrary_take_rest(u: Unstructured<'_>) -> Result<Self> {
874
0
        u.arbitrary_take_rest_iter()?.collect()
875
0
    }
876
877
    #[inline]
878
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
879
0
        crate::size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
880
0
    }
881
882
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
883
0
        let collections = shrink_collection(self.iter(), |v| v.shrink());
884
0
        Box::new(collections.map(|entries| entries.into_iter().collect()))
885
0
    }
886
}
887
888
impl<A: Arbitrary + Ord> Arbitrary for BinaryHeap<A> {
889
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
890
0
        u.arbitrary_iter()?.collect()
891
0
    }
892
893
0
    fn arbitrary_take_rest(u: Unstructured<'_>) -> Result<Self> {
894
0
        u.arbitrary_take_rest_iter()?.collect()
895
0
    }
896
897
    #[inline]
898
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
899
0
        crate::size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
900
0
    }
901
902
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
903
0
        let collections = shrink_collection(self.iter(), |v| v.shrink());
904
0
        Box::new(collections.map(|entries| entries.into_iter().collect()))
905
0
    }
906
}
907
908
impl<K: Arbitrary + Eq + ::std::hash::Hash, V: Arbitrary> Arbitrary for HashMap<K, V> {
909
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
910
0
        u.arbitrary_iter()?.collect()
911
0
    }
912
913
0
    fn arbitrary_take_rest(u: Unstructured<'_>) -> Result<Self> {
914
0
        u.arbitrary_take_rest_iter()?.collect()
915
0
    }
916
917
    #[inline]
918
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
919
0
        crate::size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
920
0
    }
921
922
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
923
0
        let collections =
924
0
            shrink_collection(self.iter(), |(k, v)| Box::new(k.shrink().zip(v.shrink())));
925
0
        Box::new(collections.map(|entries| entries.into_iter().collect()))
926
0
    }
927
}
928
929
impl<A: Arbitrary + Eq + ::std::hash::Hash> Arbitrary for HashSet<A> {
930
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
931
0
        u.arbitrary_iter()?.collect()
932
0
    }
933
934
0
    fn arbitrary_take_rest(u: Unstructured<'_>) -> Result<Self> {
935
0
        u.arbitrary_take_rest_iter()?.collect()
936
0
    }
937
938
    #[inline]
939
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
940
0
        crate::size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
941
0
    }
942
943
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
944
0
        let collections = shrink_collection(self.iter(), |v| v.shrink());
945
0
        Box::new(collections.map(|entries| entries.into_iter().collect()))
946
0
    }
947
}
948
949
impl<A: Arbitrary> Arbitrary for LinkedList<A> {
950
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
951
0
        u.arbitrary_iter()?.collect()
952
0
    }
953
954
0
    fn arbitrary_take_rest(u: Unstructured<'_>) -> Result<Self> {
955
0
        u.arbitrary_take_rest_iter()?.collect()
956
0
    }
957
958
    #[inline]
959
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
960
0
        crate::size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
961
0
    }
962
963
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
964
0
        let collections = shrink_collection(self.iter(), |v| v.shrink());
965
0
        Box::new(collections.map(|entries| entries.into_iter().collect()))
966
0
    }
967
}
968
969
impl<A: Arbitrary> Arbitrary for VecDeque<A> {
970
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
971
0
        u.arbitrary_iter()?.collect()
972
0
    }
973
974
0
    fn arbitrary_take_rest(u: Unstructured<'_>) -> Result<Self> {
975
0
        u.arbitrary_take_rest_iter()?.collect()
976
0
    }
977
978
    #[inline]
979
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
980
0
        crate::size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
981
0
    }
982
983
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
984
0
        let collections = shrink_collection(self.iter(), |v| v.shrink());
985
0
        Box::new(collections.map(|entries| entries.into_iter().collect()))
986
0
    }
987
}
988
989
impl<A> Arbitrary for Cow<'static, A>
990
where
991
    A: ToOwned + ?Sized,
992
    <A as ToOwned>::Owned: Arbitrary,
993
{
994
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
995
0
        Arbitrary::arbitrary(u).map(Cow::Owned)
996
0
    }
997
998
    #[inline]
999
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1000
0
        crate::size_hint::recursion_guard(depth, |depth| {
1001
0
            <<A as ToOwned>::Owned as Arbitrary>::size_hint(depth)
1002
0
        })
1003
0
    }
1004
1005
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
1006
0
        match *self {
1007
0
            Cow::Owned(ref o) => Box::new(o.shrink().map(Cow::Owned)),
1008
0
            Cow::Borrowed(b) => Box::new(b.to_owned().shrink().map(Cow::Owned)),
1009
        }
1010
0
    }
1011
}
1012
1013
impl Arbitrary for String {
1014
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
1015
0
        let size = u.arbitrary_len::<u8>()?;
1016
0
        match str::from_utf8(&u.peek_bytes(size).unwrap()) {
1017
0
            Ok(s) => {
1018
0
                u.get_bytes(size).unwrap();
1019
0
                Ok(s.into())
1020
            }
1021
0
            Err(e) => {
1022
0
                let i = e.valid_up_to();
1023
0
                let valid = u.get_bytes(i).unwrap();
1024
0
                let s = unsafe {
1025
0
                    debug_assert!(str::from_utf8(valid).is_ok());
1026
0
                    str::from_utf8_unchecked(valid)
1027
0
                };
1028
0
                Ok(s.into())
1029
            }
1030
        }
1031
0
    }
1032
1033
11.5k
    fn arbitrary_take_rest(u: Unstructured<'_>) -> Result<Self> {
1034
11.5k
        let bytes = u.take_rest();
1035
11.5k
        str::from_utf8(bytes)
1036
11.5k
            .map_err(|_| Error::IncorrectFormat)
1037
11.5k
            .map(Into::into)
1038
11.5k
    }
1039
1040
    #[inline]
1041
11.6k
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1042
11.6k
        crate::size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
1043
11.6k
    }
<alloc::string::String as arbitrary::Arbitrary>::size_hint
Line
Count
Source
1041
5.53k
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1042
5.53k
        crate::size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
1043
5.53k
    }
Unexecuted instantiation: <alloc::string::String as arbitrary::Arbitrary>::size_hint
<alloc::string::String as arbitrary::Arbitrary>::size_hint
Line
Count
Source
1041
2.37k
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1042
2.37k
        crate::size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
1043
2.37k
    }
<alloc::string::String as arbitrary::Arbitrary>::size_hint
Line
Count
Source
1041
3.70k
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1042
3.70k
        crate::size_hint::and(<usize as Arbitrary>::size_hint(depth), (0, None))
1043
3.70k
    }
1044
1045
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
1046
0
        let collections = shrink_collection(self.chars(), |ch| ch.shrink());
1047
0
        Box::new(collections.map(|chars| chars.into_iter().collect()))
1048
0
    }
1049
}
1050
1051
impl Arbitrary for CString {
1052
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
1053
0
        <Vec<u8> as Arbitrary>::arbitrary(u).map(|mut x| {
1054
0
            x.retain(|&c| c != 0);
1055
0
            Self::new(x).unwrap()
1056
0
        })
1057
0
    }
1058
1059
    #[inline]
1060
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1061
0
        <Vec<u8> as Arbitrary>::size_hint(depth)
1062
0
    }
1063
1064
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
1065
0
        let collections = shrink_collection(self.as_bytes().iter(), |b| {
1066
0
            Box::new(b.shrink().filter(|&b| b != 0))
1067
0
        });
1068
0
        Box::new(collections.map(|bytes| Self::new(bytes).unwrap()))
1069
0
    }
1070
}
1071
1072
impl Arbitrary for OsString {
1073
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
1074
0
        <String as Arbitrary>::arbitrary(u).map(From::from)
1075
0
    }
1076
1077
    #[inline]
1078
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1079
0
        <String as Arbitrary>::size_hint(depth)
1080
0
    }
1081
1082
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
1083
0
        match self.clone().into_string() {
1084
0
            Err(_) if self.is_empty() => empty(),
1085
0
            Err(_) => once(OsString::from("".to_string())),
1086
0
            Ok(s) => Box::new(s.shrink().map(From::from)),
1087
        }
1088
0
    }
1089
}
1090
1091
impl Arbitrary for PathBuf {
1092
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
1093
0
        <OsString as Arbitrary>::arbitrary(u).map(From::from)
1094
0
    }
1095
1096
    #[inline]
1097
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1098
0
        <OsString as Arbitrary>::size_hint(depth)
1099
0
    }
1100
1101
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
1102
0
        let s = self.clone().into_os_string();
1103
0
        Box::new(s.shrink().map(From::from))
1104
0
    }
1105
}
1106
1107
impl<A: Arbitrary> Arbitrary for Box<A> {
1108
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
1109
0
        Arbitrary::arbitrary(u).map(Self::new)
1110
0
    }
1111
1112
    #[inline]
1113
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1114
0
        crate::size_hint::recursion_guard(depth, |depth| <A as Arbitrary>::size_hint(depth))
1115
0
    }
1116
1117
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
1118
0
        Box::new((&**self).shrink().map(Self::new))
1119
0
    }
1120
}
1121
1122
impl<A: Arbitrary> Arbitrary for Box<[A]> {
1123
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
1124
0
        <Vec<A> as Arbitrary>::arbitrary(u).map(|x| x.into_boxed_slice())
1125
0
    }
1126
1127
    #[inline]
1128
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1129
0
        <Vec<A> as Arbitrary>::size_hint(depth)
1130
0
    }
1131
1132
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
1133
0
        Box::new(shrink_collection(self.iter(), |x| x.shrink()).map(|v| v.into_boxed_slice()))
1134
0
    }
1135
}
1136
1137
impl Arbitrary for Box<str> {
1138
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
1139
0
        <String as Arbitrary>::arbitrary(u).map(|x| x.into_boxed_str())
1140
0
    }
1141
1142
    #[inline]
1143
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1144
0
        <String as Arbitrary>::size_hint(depth)
1145
0
    }
1146
1147
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
1148
0
        let collections = shrink_collection(self.chars(), |ch| ch.shrink());
1149
0
        Box::new(collections.map(|chars| chars.into_iter().collect::<String>().into_boxed_str()))
1150
0
    }
1151
}
1152
1153
// impl Arbitrary for Box<CStr> {
1154
//     fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
1155
//         <CString as Arbitrary>::arbitrary(u).map(|x| x.into_boxed_c_str())
1156
//     }
1157
// }
1158
1159
// impl Arbitrary for Box<OsStr> {
1160
//     fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
1161
//         <OsString as Arbitrary>::arbitrary(u).map(|x| x.into_boxed_osstr())
1162
//
1163
//     }
1164
// }
1165
1166
impl<A: Arbitrary> Arbitrary for Arc<A> {
1167
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
1168
0
        Arbitrary::arbitrary(u).map(Self::new)
1169
0
    }
1170
1171
    #[inline]
1172
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1173
0
        crate::size_hint::recursion_guard(depth, |depth| <A as Arbitrary>::size_hint(depth))
1174
0
    }
1175
1176
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
1177
0
        Box::new((&**self).shrink().map(Self::new))
1178
0
    }
1179
}
1180
1181
impl<A: Arbitrary> Arbitrary for Rc<A> {
1182
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
1183
0
        Arbitrary::arbitrary(u).map(Self::new)
1184
0
    }
1185
1186
    #[inline]
1187
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1188
0
        crate::size_hint::recursion_guard(depth, |depth| <A as Arbitrary>::size_hint(depth))
1189
0
    }
1190
1191
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
1192
0
        Box::new((&**self).shrink().map(Self::new))
1193
0
    }
1194
}
1195
1196
impl<A: Arbitrary> Arbitrary for Cell<A> {
1197
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
1198
0
        Arbitrary::arbitrary(u).map(Self::new)
1199
0
    }
1200
1201
    #[inline]
1202
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1203
0
        <A as Arbitrary>::size_hint(depth)
1204
0
    }
1205
1206
    // Note: can't implement `shrink` without either more trait bounds on `A`
1207
    // (copy or default) or `Cell::update`:
1208
    // https://github.com/rust-lang/rust/issues/50186
1209
}
1210
1211
impl<A: Arbitrary> Arbitrary for RefCell<A> {
1212
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
1213
0
        Arbitrary::arbitrary(u).map(Self::new)
1214
0
    }
1215
1216
    #[inline]
1217
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1218
0
        <A as Arbitrary>::size_hint(depth)
1219
0
    }
1220
1221
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
1222
0
        let x = self.borrow();
1223
0
        Box::new(x.shrink().map(Self::new))
1224
0
    }
1225
}
1226
1227
impl<A: Arbitrary> Arbitrary for UnsafeCell<A> {
1228
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
1229
0
        Arbitrary::arbitrary(u).map(Self::new)
1230
0
    }
1231
1232
    #[inline]
1233
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1234
0
        <A as Arbitrary>::size_hint(depth)
1235
0
    }
1236
1237
    // We can't non-trivially (i.e. not an empty iterator) implement `shrink` in
1238
    // a safe way, since we don't have a safe way to get the inner value.
1239
}
1240
1241
impl<A: Arbitrary> Arbitrary for Mutex<A> {
1242
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
1243
0
        Arbitrary::arbitrary(u).map(Self::new)
1244
0
    }
1245
1246
    #[inline]
1247
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1248
0
        <A as Arbitrary>::size_hint(depth)
1249
0
    }
1250
1251
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
1252
0
        match self.lock() {
1253
0
            Err(_) => empty(),
1254
0
            Ok(g) => Box::new(g.shrink().map(Self::new)),
1255
        }
1256
0
    }
1257
}
1258
1259
impl<A: Arbitrary> Arbitrary for iter::Empty<A> {
1260
0
    fn arbitrary(_: &mut Unstructured<'_>) -> Result<Self> {
1261
0
        Ok(iter::empty())
1262
0
    }
1263
1264
    #[inline]
1265
0
    fn size_hint(_depth: usize) -> (usize, Option<usize>) {
1266
0
        (0, Some(0))
1267
0
    }
1268
1269
    // Nothing to shrink here.
1270
}
1271
1272
impl<A: Arbitrary> Arbitrary for ::std::marker::PhantomData<A> {
1273
0
    fn arbitrary(_: &mut Unstructured<'_>) -> Result<Self> {
1274
0
        Ok(::std::marker::PhantomData)
1275
0
    }
1276
1277
    #[inline]
1278
0
    fn size_hint(_depth: usize) -> (usize, Option<usize>) {
1279
0
        (0, Some(0))
1280
0
    }
1281
1282
    // Nothing to shrink here.
1283
}
1284
1285
impl<A: Arbitrary> Arbitrary for ::std::num::Wrapping<A> {
1286
0
    fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
1287
0
        Arbitrary::arbitrary(u).map(::std::num::Wrapping)
1288
0
    }
1289
1290
    #[inline]
1291
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1292
0
        <A as Arbitrary>::size_hint(depth)
1293
0
    }
1294
1295
0
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
1296
0
        let ref x = self.0;
1297
0
        Box::new(x.shrink().map(::std::num::Wrapping))
1298
0
    }
1299
}
1300
1301
#[cfg(test)]
1302
mod test {
1303
    use super::*;
1304
1305
    #[test]
1306
    fn finite_buffer_fill_buffer() {
1307
        let x = [1, 2, 3, 4];
1308
        let mut rb = Unstructured::new(&x);
1309
        let mut z = [0; 2];
1310
        rb.fill_buffer(&mut z).unwrap();
1311
        assert_eq!(z, [1, 2]);
1312
        rb.fill_buffer(&mut z).unwrap();
1313
        assert_eq!(z, [3, 4]);
1314
        rb.fill_buffer(&mut z).unwrap();
1315
        assert_eq!(z, [0, 0]);
1316
    }
1317
1318
    #[test]
1319
    fn arbitrary_for_integers() {
1320
        let x = [1, 2, 3, 4];
1321
        let mut buf = Unstructured::new(&x);
1322
        let expected = 1 | (2 << 8) | (3 << 16) | (4 << 24);
1323
        let actual = i32::arbitrary(&mut buf).unwrap();
1324
        assert_eq!(expected, actual);
1325
    }
1326
1327
    #[test]
1328
    fn arbitrary_collection() {
1329
        let x = [
1330
            1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8,
1331
        ];
1332
        assert_eq!(
1333
            Vec::<u8>::arbitrary(&mut Unstructured::new(&x)).unwrap(),
1334
            &[2, 4, 6, 8, 1]
1335
        );
1336
        assert_eq!(
1337
            Vec::<u32>::arbitrary(&mut Unstructured::new(&x)).unwrap(),
1338
            &[84148994]
1339
        );
1340
        assert_eq!(
1341
            String::arbitrary(&mut Unstructured::new(&x)).unwrap(),
1342
            "\x01\x02\x03\x04\x05\x06\x07\x08"
1343
        );
1344
    }
1345
1346
    #[test]
1347
    fn arbitrary_take_rest() {
1348
        let x = [1, 2, 3, 4];
1349
        assert_eq!(
1350
            Vec::<u8>::arbitrary_take_rest(Unstructured::new(&x)).unwrap(),
1351
            &[1, 2, 3, 4]
1352
        );
1353
        assert_eq!(
1354
            Vec::<u32>::arbitrary_take_rest(Unstructured::new(&x)).unwrap(),
1355
            &[0x4030201]
1356
        );
1357
        assert_eq!(
1358
            String::arbitrary_take_rest(Unstructured::new(&x)).unwrap(),
1359
            "\x01\x02\x03\x04"
1360
        );
1361
    }
1362
1363
    #[test]
1364
    fn shrink_tuple() {
1365
        let tup = (10, 20, 30);
1366
        assert_eq!(
1367
            tup.shrink().collect::<Vec<_>>(),
1368
            [(0, 0, 0), (5, 10, 15), (2, 5, 7), (1, 2, 3)]
1369
        );
1370
    }
1371
1372
    #[test]
1373
    fn shrink_array() {
1374
        let tup = [10, 20, 30];
1375
        assert_eq!(
1376
            tup.shrink().collect::<Vec<_>>(),
1377
            [[0, 0, 0], [5, 10, 15], [2, 5, 7], [1, 2, 3]]
1378
        );
1379
    }
1380
1381
    #[test]
1382
    fn shrink_vec() {
1383
        let v = vec![4, 4, 4, 4];
1384
        assert_eq!(
1385
            v.shrink().collect::<Vec<_>>(),
1386
            [
1387
                vec![],
1388
                vec![0],
1389
                vec![2],
1390
                vec![1],
1391
                vec![0, 0],
1392
                vec![2, 2],
1393
                vec![1, 1],
1394
                vec![0, 0, 0, 0],
1395
                vec![2, 2, 2, 2],
1396
                vec![1, 1, 1, 1]
1397
            ]
1398
        );
1399
    }
1400
1401
    #[test]
1402
    fn shrink_string() {
1403
        let s = "aaaa".to_string();
1404
        assert_eq!(
1405
            s.shrink().collect::<Vec<_>>(),
1406
            [
1407
                "",
1408
                "\u{0}",
1409
                "0",
1410
                "\u{18}",
1411
                "\u{c}",
1412
                "\u{6}",
1413
                "\u{3}",
1414
                "\u{1}",
1415
                "\u{0}\u{0}",
1416
                "00",
1417
                "\u{18}\u{18}",
1418
                "\u{c}\u{c}",
1419
                "\u{6}\u{6}",
1420
                "\u{3}\u{3}",
1421
                "\u{1}\u{1}",
1422
                "\u{0}\u{0}\u{0}\u{0}",
1423
                "0000",
1424
                "\u{18}\u{18}\u{18}\u{18}",
1425
                "\u{c}\u{c}\u{c}\u{c}",
1426
                "\u{6}\u{6}\u{6}\u{6}",
1427
                "\u{3}\u{3}\u{3}\u{3}",
1428
                "\u{1}\u{1}\u{1}\u{1}"
1429
            ]
1430
            .iter()
1431
            .map(|s| s.to_string())
1432
            .collect::<Vec<_>>(),
1433
        );
1434
    }
1435
1436
    #[test]
1437
    fn shrink_cstring() {
1438
        let s = CString::new(b"aaaa".to_vec()).unwrap();
1439
        assert_eq!(
1440
            s.shrink().collect::<Vec<_>>(),
1441
            [
1442
                &[][..],
1443
                &[b'0'][..],
1444
                &[0x18][..],
1445
                &[0x0c][..],
1446
                &[0x06][..],
1447
                &[0x03][..],
1448
                &[0x01][..],
1449
                &[b'0', b'0'][..],
1450
                &[0x18, 0x18][..],
1451
                &[0x0c, 0x0c][..],
1452
                &[0x06, 0x06][..],
1453
                &[0x03, 0x03][..],
1454
                &[0x01, 0x01][..],
1455
                &[b'0', b'0', b'0', b'0'][..],
1456
                &[0x18, 0x18, 0x18, 0x18][..],
1457
                &[0x0c, 0x0c, 0x0c, 0x0c][..],
1458
                &[0x06, 0x06, 0x06, 0x06][..],
1459
                &[0x03, 0x03, 0x03, 0x03][..],
1460
                &[0x01, 0x01, 0x01, 0x01][..],
1461
            ]
1462
            .iter()
1463
            .map(|s| CString::new(s.to_vec()).unwrap())
1464
            .collect::<Vec<_>>(),
1465
        );
1466
    }
1467
1468
    #[test]
1469
    fn size_hint_for_tuples() {
1470
        assert_eq!((7, Some(7)), <(bool, u16, i32) as Arbitrary>::size_hint(0));
1471
        assert_eq!(
1472
            (1 + mem::size_of::<usize>(), None),
1473
            <(u8, Vec<u8>) as Arbitrary>::size_hint(0)
1474
        );
1475
    }
1476
}