Coverage Report

Created: 2023-04-25 07:07

/rust/registry/src/index.crates.io-6f17d22bba15001f/arbitrary-1.3.0/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::array;
38
use core::cell::{Cell, RefCell, UnsafeCell};
39
use core::iter;
40
use core::mem;
41
use core::num::{NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize};
42
use core::num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize};
43
use core::ops::{Range, RangeBounds, RangeFrom, RangeInclusive, RangeTo, RangeToInclusive};
44
use core::str;
45
use core::time::Duration;
46
use std::borrow::{Cow, ToOwned};
47
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
48
use std::ffi::{CString, OsString};
49
use std::hash::BuildHasher;
50
use std::net::{Ipv4Addr, Ipv6Addr};
51
use std::ops::Bound;
52
use std::path::PathBuf;
53
use std::rc::Rc;
54
use std::sync::atomic::{AtomicBool, AtomicIsize, AtomicUsize};
55
use std::sync::{Arc, Mutex};
56
57
/// Generate arbitrary structured values from raw, unstructured data.
58
///
59
/// The `Arbitrary` trait allows you to generate valid structured values, like
60
/// `HashMap`s, or ASTs, or `MyTomlConfig`, or any other data structure from
61
/// raw, unstructured bytes provided by a fuzzer.
62
///
63
/// # Deriving `Arbitrary`
64
///
65
/// Automatically deriving the `Arbitrary` trait is the recommended way to
66
/// implement `Arbitrary` for your types.
67
///
68
/// Using the custom derive requires that you enable the `"derive"` cargo
69
/// feature in your `Cargo.toml`:
70
///
71
/// ```toml
72
/// [dependencies]
73
/// arbitrary = { version = "1", features = ["derive"] }
74
/// ```
75
///
76
/// Then, you add the `#[derive(Arbitrary)]` annotation to your `struct` or
77
/// `enum` type definition:
78
///
79
/// ```
80
/// # #[cfg(feature = "derive")] mod foo {
81
/// use arbitrary::Arbitrary;
82
/// use std::collections::HashSet;
83
///
84
/// #[derive(Arbitrary)]
85
/// pub struct AddressBook {
86
///     friends: HashSet<Friend>,
87
/// }
88
///
89
/// #[derive(Arbitrary, Hash, Eq, PartialEq)]
90
/// pub enum Friend {
91
///     Buddy { name: String },
92
///     Pal { age: usize },
93
/// }
94
/// # }
95
/// ```
96
///
97
/// Every member of the `struct` or `enum` must also implement `Arbitrary`.
98
///
99
/// # Implementing `Arbitrary` By Hand
100
///
101
/// Implementing `Arbitrary` mostly involves nested calls to other `Arbitrary`
102
/// arbitrary implementations for each of your `struct` or `enum`'s members. But
103
/// sometimes you need some amount of raw data, or you need to generate a
104
/// variably-sized collection type, or something of that sort. The
105
/// [`Unstructured`][crate::Unstructured] type helps you with these tasks.
106
///
107
/// ```
108
/// # #[cfg(feature = "derive")] mod foo {
109
/// # pub struct MyCollection<T> { _t: std::marker::PhantomData<T> }
110
/// # impl<T> MyCollection<T> {
111
/// #     pub fn new() -> Self { MyCollection { _t: std::marker::PhantomData } }
112
/// #     pub fn insert(&mut self, element: T) {}
113
/// # }
114
/// use arbitrary::{Arbitrary, Result, Unstructured};
115
///
116
/// impl<'a, T> Arbitrary<'a> for MyCollection<T>
117
/// where
118
///     T: Arbitrary<'a>,
119
/// {
120
///     fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
121
///         // Get an iterator of arbitrary `T`s.
122
///         let iter = u.arbitrary_iter::<T>()?;
123
///
124
///         // And then create a collection!
125
///         let mut my_collection = MyCollection::new();
126
///         for elem_result in iter {
127
///             let elem = elem_result?;
128
///             my_collection.insert(elem);
129
///         }
130
///
131
///         Ok(my_collection)
132
///     }
133
/// }
134
/// # }
135
/// ```
136
pub trait Arbitrary<'a>: Sized {
137
    /// Generate an arbitrary value of `Self` from the given unstructured data.
138
    ///
139
    /// Calling `Arbitrary::arbitrary` requires that you have some raw data,
140
    /// perhaps given to you by a fuzzer like AFL or libFuzzer. You wrap this
141
    /// raw data in an `Unstructured`, and then you can call `<MyType as
142
    /// Arbitrary>::arbitrary` to construct an arbitrary instance of `MyType`
143
    /// from that unstructured data.
144
    ///
145
    /// Implementations may return an error if there is not enough data to
146
    /// construct a full instance of `Self`, or they may fill out the rest of
147
    /// `Self` with dummy values. Using dummy values when the underlying data is
148
    /// exhausted can help avoid accidentally "defeating" some of the fuzzer's
149
    /// mutations to the underlying byte stream that might otherwise lead to
150
    /// interesting runtime behavior or new code coverage if only we had just a
151
    /// few more bytes. However, it also requires that implementations for
152
    /// recursive types (e.g. `struct Foo(Option<Box<Foo>>)`) avoid infinite
153
    /// recursion when the underlying data is exhausted.
154
    ///
155
    /// ```
156
    /// # #[cfg(feature = "derive")] fn foo() {
157
    /// use arbitrary::{Arbitrary, Unstructured};
158
    ///
159
    /// #[derive(Arbitrary)]
160
    /// pub struct MyType {
161
    ///     // ...
162
    /// }
163
    ///
164
    /// // Get the raw data from the fuzzer or wherever else.
165
    /// # let get_raw_data_from_fuzzer = || &[];
166
    /// let raw_data: &[u8] = get_raw_data_from_fuzzer();
167
    ///
168
    /// // Wrap that raw data in an `Unstructured`.
169
    /// let mut unstructured = Unstructured::new(raw_data);
170
    ///
171
    /// // Generate an arbitrary instance of `MyType` and do stuff with it.
172
    /// if let Ok(value) = MyType::arbitrary(&mut unstructured) {
173
    /// #   let do_stuff = |_| {};
174
    ///     do_stuff(value);
175
    /// }
176
    /// # }
177
    /// ```
178
    ///
179
    /// See also the documentation for [`Unstructured`][crate::Unstructured].
180
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>;
181
182
    /// Generate an arbitrary value of `Self` from the entirety of the given
183
    /// unstructured data.
184
    ///
185
    /// This is similar to Arbitrary::arbitrary, however it assumes that it is
186
    /// the last consumer of the given data, and is thus able to consume it all
187
    /// if it needs.  See also the documentation for
188
    /// [`Unstructured`][crate::Unstructured].
189
9.59k
    fn arbitrary_take_rest(mut u: Unstructured<'a>) -> Result<Self> {
190
9.59k
        Self::arbitrary(&mut u)
191
9.59k
    }
Unexecuted instantiation: <_ as arbitrary::Arbitrary>::arbitrary_take_rest
<u8 as arbitrary::Arbitrary>::arbitrary_take_rest
Line
Count
Source
189
43
    fn arbitrary_take_rest(mut u: Unstructured<'a>) -> Result<Self> {
190
43
        Self::arbitrary(&mut u)
191
43
    }
<ion_checker::TestCase as arbitrary::Arbitrary>::arbitrary_take_rest
Line
Count
Source
189
9.54k
    fn arbitrary_take_rest(mut u: Unstructured<'a>) -> Result<Self> {
190
9.54k
        Self::arbitrary(&mut u)
191
9.54k
    }
Unexecuted instantiation: <_ as arbitrary::Arbitrary>::arbitrary_take_rest
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
    /// ## Invariant
213
    ///
214
    /// It must be possible to construct every possible output using only inputs
215
    /// of lengths bounded by these parameters. This applies to both
216
    /// [`Arbitrary::arbitrary`] and [`Arbitrary::arbitrary_take_rest`].
217
    ///
218
    /// This is trivially true for `(0, None)`. To restrict this further, it
219
    /// must be proven that all inputs that are now excluded produced redundant
220
    /// outputs which are still possible to produce using the reduced input
221
    /// space.
222
    ///
223
    /// ## The `depth` Parameter
224
    ///
225
    /// If you 100% know that the type you are implementing `Arbitrary` for is
226
    /// not a recursive type, or your implementation is not transitively calling
227
    /// any other `size_hint` methods, you can ignore the `depth` parameter.
228
    /// Note that if you are implementing `Arbitrary` for a generic type, you
229
    /// cannot guarantee the lack of type recursion!
230
    ///
231
    /// Otherwise, you need to use
232
    /// [`arbitrary::size_hint::recursion_guard(depth)`][crate::size_hint::recursion_guard]
233
    /// to prevent potential infinite recursion when calculating size hints for
234
    /// potentially recursive types:
235
    ///
236
    /// ```
237
    /// use arbitrary::{Arbitrary, Unstructured, size_hint};
238
    ///
239
    /// // This can potentially be a recursive type if `L` or `R` contain
240
    /// // something like `Box<Option<MyEither<L, R>>>`!
241
    /// enum MyEither<L, R> {
242
    ///     Left(L),
243
    ///     Right(R),
244
    /// }
245
    ///
246
    /// impl<'a, L, R> Arbitrary<'a> for MyEither<L, R>
247
    /// where
248
    ///     L: Arbitrary<'a>,
249
    ///     R: Arbitrary<'a>,
250
    /// {
251
    ///     fn arbitrary(u: &mut Unstructured) -> arbitrary::Result<Self> {
252
    ///         // ...
253
    /// #       unimplemented!()
254
    ///     }
255
    ///
256
    ///     fn size_hint(depth: usize) -> (usize, Option<usize>) {
257
    ///         // Protect against potential infinite recursion with
258
    ///         // `recursion_guard`.
259
    ///         size_hint::recursion_guard(depth, |depth| {
260
    ///             // If we aren't too deep, then `recursion_guard` calls
261
    ///             // this closure, which implements the natural size hint.
262
    ///             // Don't forget to use the new `depth` in all nested
263
    ///             // `size_hint` calls! We recommend shadowing the
264
    ///             // parameter, like what is done here, so that you can't
265
    ///             // accidentally use the wrong depth.
266
    ///             size_hint::or(
267
    ///                 <L as Arbitrary>::size_hint(depth),
268
    ///                 <R as Arbitrary>::size_hint(depth),
269
    ///             )
270
    ///         })
271
    ///     }
272
    /// }
273
    /// ```
274
    ///
275
    /// [iterator-size-hint]: https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html#method.size_hint
276
    #[inline]
277
9.54k
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
278
9.54k
        let _ = depth;
279
9.54k
        (0, None)
280
9.54k
    }
Unexecuted instantiation: <_ as arbitrary::Arbitrary>::size_hint
<ion_checker::TestCase as arbitrary::Arbitrary>::size_hint
Line
Count
Source
277
9.54k
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
278
9.54k
        let _ = depth;
279
9.54k
        (0, None)
280
9.54k
    }
Unexecuted instantiation: <_ as arbitrary::Arbitrary>::size_hint
281
}
282
283
impl<'a> Arbitrary<'a> for () {
284
0
    fn arbitrary(_: &mut Unstructured<'a>) -> Result<Self> {
285
0
        Ok(())
286
0
    }
Unexecuted instantiation: <() as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <() as arbitrary::Arbitrary>::arbitrary
287
288
    #[inline]
289
0
    fn size_hint(_depth: usize) -> (usize, Option<usize>) {
290
0
        (0, Some(0))
291
0
    }
Unexecuted instantiation: <() as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <() as arbitrary::Arbitrary>::size_hint
292
}
293
294
impl<'a> Arbitrary<'a> for bool {
295
144M
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
296
144M
        Ok(<u8 as Arbitrary<'a>>::arbitrary(u)? & 1 == 1)
297
144M
    }
<bool as arbitrary::Arbitrary>::arbitrary
Line
Count
Source
295
113M
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
296
113M
        Ok(<u8 as Arbitrary<'a>>::arbitrary(u)? & 1 == 1)
297
113M
    }
<bool as arbitrary::Arbitrary>::arbitrary
Line
Count
Source
295
30.9M
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
296
30.9M
        Ok(<u8 as Arbitrary<'a>>::arbitrary(u)? & 1 == 1)
297
30.9M
    }
298
299
    #[inline]
300
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
301
0
        <u8 as Arbitrary<'a>>::size_hint(depth)
302
0
    }
Unexecuted instantiation: <bool as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <bool as arbitrary::Arbitrary>::size_hint
303
}
304
305
macro_rules! impl_arbitrary_for_integers {
306
    ( $( $ty:ty: $unsigned:ty; )* ) => {
307
        $(
308
            impl<'a> Arbitrary<'a> for $ty {
309
239M
                fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
310
239M
                    let mut buf = [0; mem::size_of::<$ty>()];
311
239M
                    u.fill_buffer(&mut buf)?;
312
239M
                    let mut x: $unsigned = 0;
313
335M
                    for i in 0..mem::size_of::<$ty>() {
314
335M
                        x |= buf[i] as $unsigned << (i * 8);
315
335M
                    }
316
239M
                    Ok(x as $ty)
317
239M
                }
Unexecuted instantiation: <u128 as arbitrary::Arbitrary>::arbitrary
<u64 as arbitrary::Arbitrary>::arbitrary
Line
Count
Source
309
2.24M
                fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
310
2.24M
                    let mut buf = [0; mem::size_of::<$ty>()];
311
2.24M
                    u.fill_buffer(&mut buf)?;
312
2.24M
                    let mut x: $unsigned = 0;
313
17.9M
                    for i in 0..mem::size_of::<$ty>() {
314
17.9M
                        x |= buf[i] as $unsigned << (i * 8);
315
17.9M
                    }
316
2.24M
                    Ok(x as $ty)
317
2.24M
                }
<u16 as arbitrary::Arbitrary>::arbitrary
Line
Count
Source
309
1.72M
                fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
310
1.72M
                    let mut buf = [0; mem::size_of::<$ty>()];
311
1.72M
                    u.fill_buffer(&mut buf)?;
312
1.72M
                    let mut x: $unsigned = 0;
313
3.45M
                    for i in 0..mem::size_of::<$ty>() {
314
3.45M
                        x |= buf[i] as $unsigned << (i * 8);
315
3.45M
                    }
316
1.72M
                    Ok(x as $ty)
317
1.72M
                }
Unexecuted instantiation: <isize as arbitrary::Arbitrary>::arbitrary
<i64 as arbitrary::Arbitrary>::arbitrary
Line
Count
Source
309
1.81M
                fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
310
1.81M
                    let mut buf = [0; mem::size_of::<$ty>()];
311
1.81M
                    u.fill_buffer(&mut buf)?;
312
1.81M
                    let mut x: $unsigned = 0;
313
14.5M
                    for i in 0..mem::size_of::<$ty>() {
314
14.5M
                        x |= buf[i] as $unsigned << (i * 8);
315
14.5M
                    }
316
1.81M
                    Ok(x as $ty)
317
1.81M
                }
Unexecuted instantiation: <i16 as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <usize as arbitrary::Arbitrary>::arbitrary
<u32 as arbitrary::Arbitrary>::arbitrary
Line
Count
Source
309
7.30M
                fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
310
7.30M
                    let mut buf = [0; mem::size_of::<$ty>()];
311
7.30M
                    u.fill_buffer(&mut buf)?;
312
7.30M
                    let mut x: $unsigned = 0;
313
29.2M
                    for i in 0..mem::size_of::<$ty>() {
314
29.2M
                        x |= buf[i] as $unsigned << (i * 8);
315
29.2M
                    }
316
7.30M
                    Ok(x as $ty)
317
7.30M
                }
<u8 as arbitrary::Arbitrary>::arbitrary
Line
Count
Source
309
190M
                fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
310
190M
                    let mut buf = [0; mem::size_of::<$ty>()];
311
190M
                    u.fill_buffer(&mut buf)?;
312
190M
                    let mut x: $unsigned = 0;
313
190M
                    for i in 0..mem::size_of::<$ty>() {
314
190M
                        x |= buf[i] as $unsigned << (i * 8);
315
190M
                    }
316
190M
                    Ok(x as $ty)
317
190M
                }
<i128 as arbitrary::Arbitrary>::arbitrary
Line
Count
Source
309
2.46M
                fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
310
2.46M
                    let mut buf = [0; mem::size_of::<$ty>()];
311
2.46M
                    u.fill_buffer(&mut buf)?;
312
2.46M
                    let mut x: $unsigned = 0;
313
39.3M
                    for i in 0..mem::size_of::<$ty>() {
314
39.3M
                        x |= buf[i] as $unsigned << (i * 8);
315
39.3M
                    }
316
2.46M
                    Ok(x as $ty)
317
2.46M
                }
<i32 as arbitrary::Arbitrary>::arbitrary
Line
Count
Source
309
2.27M
                fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
310
2.27M
                    let mut buf = [0; mem::size_of::<$ty>()];
311
2.27M
                    u.fill_buffer(&mut buf)?;
312
2.27M
                    let mut x: $unsigned = 0;
313
9.08M
                    for i in 0..mem::size_of::<$ty>() {
314
9.08M
                        x |= buf[i] as $unsigned << (i * 8);
315
9.08M
                    }
316
2.27M
                    Ok(x as $ty)
317
2.27M
                }
Unexecuted instantiation: <i8 as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <u64 as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <usize as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <i64 as arbitrary::Arbitrary>::arbitrary
<u8 as arbitrary::Arbitrary>::arbitrary
Line
Count
Source
309
30.9M
                fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
310
30.9M
                    let mut buf = [0; mem::size_of::<$ty>()];
311
30.9M
                    u.fill_buffer(&mut buf)?;
312
30.9M
                    let mut x: $unsigned = 0;
313
30.9M
                    for i in 0..mem::size_of::<$ty>() {
314
30.9M
                        x |= buf[i] as $unsigned << (i * 8);
315
30.9M
                    }
316
30.9M
                    Ok(x as $ty)
317
30.9M
                }
Unexecuted instantiation: <i128 as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <i32 as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <u128 as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <i8 as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <u32 as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <u16 as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <isize as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <i16 as arbitrary::Arbitrary>::arbitrary
318
319
                #[inline]
320
3.91M
                fn size_hint(_depth: usize) -> (usize, Option<usize>) {
321
3.91M
                    let n = mem::size_of::<$ty>();
322
3.91M
                    (n, Some(n))
323
3.91M
                }
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: <i128 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: <i64 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <isize as arbitrary::Arbitrary>::size_hint
<u8 as arbitrary::Arbitrary>::size_hint
Line
Count
Source
320
3.90M
                fn size_hint(_depth: usize) -> (usize, Option<usize>) {
321
3.90M
                    let n = mem::size_of::<$ty>();
322
3.90M
                    (n, Some(n))
323
3.90M
                }
<u8 as arbitrary::Arbitrary>::size_hint
Line
Count
Source
320
3.29k
                fn size_hint(_depth: usize) -> (usize, Option<usize>) {
321
3.29k
                    let n = mem::size_of::<$ty>();
322
3.29k
                    (n, Some(n))
323
3.29k
                }
Unexecuted instantiation: <usize as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <i16 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <u32 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <i32 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <i64 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <u128 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <i128 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <u16 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <isize as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <i8 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <u64 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <u8 as arbitrary::Arbitrary>::size_hint
324
325
            }
326
        )*
327
    }
328
}
329
330
impl_arbitrary_for_integers! {
331
    u8: u8;
332
    u16: u16;
333
    u32: u32;
334
    u64: u64;
335
    u128: u128;
336
    usize: usize;
337
    i8: u8;
338
    i16: u16;
339
    i32: u32;
340
    i64: u64;
341
    i128: u128;
342
    isize: usize;
343
}
344
345
macro_rules! impl_arbitrary_for_floats {
346
    ( $( $ty:ident : $unsigned:ty; )* ) => {
347
        $(
348
            impl<'a> Arbitrary<'a> for $ty {
349
4.43M
                fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
350
4.43M
                    Ok(Self::from_bits(<$unsigned as Arbitrary<'a>>::arbitrary(u)?))
351
4.43M
                }
<f64 as arbitrary::Arbitrary>::arbitrary
Line
Count
Source
349
2.20M
                fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
350
2.20M
                    Ok(Self::from_bits(<$unsigned as Arbitrary<'a>>::arbitrary(u)?))
351
2.20M
                }
<f32 as arbitrary::Arbitrary>::arbitrary
Line
Count
Source
349
2.23M
                fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
350
2.23M
                    Ok(Self::from_bits(<$unsigned as Arbitrary<'a>>::arbitrary(u)?))
351
2.23M
                }
Unexecuted instantiation: <f32 as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <f64 as arbitrary::Arbitrary>::arbitrary
352
353
                #[inline]
354
0
                fn size_hint(depth: usize) -> (usize, Option<usize>) {
355
0
                    <$unsigned as Arbitrary<'a>>::size_hint(depth)
356
0
                }
Unexecuted instantiation: <f64 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <f32 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <f32 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <f64 as arbitrary::Arbitrary>::size_hint
357
            }
358
        )*
359
    }
360
}
361
362
impl_arbitrary_for_floats! {
363
    f32: u32;
364
    f64: u64;
365
}
366
367
impl<'a> Arbitrary<'a> for char {
368
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
369
        use std::char;
370
        // The highest unicode code point is 0x11_FFFF
371
        const CHAR_END: u32 = 0x11_0000;
372
        // The size of the surrogate blocks
373
        const SURROGATES_START: u32 = 0xD800;
374
0
        let mut c = <u32 as Arbitrary<'a>>::arbitrary(u)? % CHAR_END;
375
0
        if let Some(c) = char::from_u32(c) {
376
0
            Ok(c)
377
        } else {
378
            // We found a surrogate, wrap and try again
379
0
            c -= SURROGATES_START;
380
0
            Ok(char::from_u32(c)
381
0
                .expect("Generated character should be valid! This is a bug in arbitrary-rs"))
382
        }
383
0
    }
Unexecuted instantiation: <char as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <char as arbitrary::Arbitrary>::arbitrary
384
385
    #[inline]
386
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
387
0
        <u32 as Arbitrary<'a>>::size_hint(depth)
388
0
    }
Unexecuted instantiation: <char as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <char as arbitrary::Arbitrary>::size_hint
389
}
390
391
impl<'a> Arbitrary<'a> for AtomicBool {
392
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
393
0
        Arbitrary::arbitrary(u).map(Self::new)
394
0
    }
Unexecuted instantiation: <core::sync::atomic::AtomicBool as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::sync::atomic::AtomicBool as arbitrary::Arbitrary>::arbitrary
395
396
    #[inline]
397
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
398
0
        <bool as Arbitrary<'a>>::size_hint(depth)
399
0
    }
Unexecuted instantiation: <core::sync::atomic::AtomicBool as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::sync::atomic::AtomicBool as arbitrary::Arbitrary>::size_hint
400
}
401
402
impl<'a> Arbitrary<'a> for AtomicIsize {
403
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
404
0
        Arbitrary::arbitrary(u).map(Self::new)
405
0
    }
Unexecuted instantiation: <core::sync::atomic::AtomicIsize as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::sync::atomic::AtomicIsize as arbitrary::Arbitrary>::arbitrary
406
407
    #[inline]
408
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
409
0
        <isize as Arbitrary<'a>>::size_hint(depth)
410
0
    }
Unexecuted instantiation: <core::sync::atomic::AtomicIsize as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::sync::atomic::AtomicIsize as arbitrary::Arbitrary>::size_hint
411
}
412
413
impl<'a> Arbitrary<'a> for AtomicUsize {
414
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
415
0
        Arbitrary::arbitrary(u).map(Self::new)
416
0
    }
Unexecuted instantiation: <core::sync::atomic::AtomicUsize as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::sync::atomic::AtomicUsize as arbitrary::Arbitrary>::arbitrary
417
418
    #[inline]
419
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
420
0
        <usize as Arbitrary<'a>>::size_hint(depth)
421
0
    }
Unexecuted instantiation: <core::sync::atomic::AtomicUsize as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::sync::atomic::AtomicUsize as arbitrary::Arbitrary>::size_hint
422
}
423
424
macro_rules! impl_range {
425
    (
426
        $range:ty,
427
        $value_closure:expr,
428
        $value_ty:ty,
429
        $fun:ident($fun_closure:expr),
430
        $size_hint_closure:expr
431
    ) => {
432
        impl<'a, A> Arbitrary<'a> for $range
433
        where
434
            A: Arbitrary<'a> + Clone + PartialOrd,
435
        {
436
0
            fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
Unexecuted instantiation: <core::ops::range::RangeToInclusive<_> 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::Range<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::ops::range::RangeToInclusive<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::ops::range::RangeInclusive<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::ops::range::RangeFrom<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::ops::range::Range<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::ops::range::RangeTo<_> as arbitrary::Arbitrary>::arbitrary
437
                let value: $value_ty = Arbitrary::arbitrary(u)?;
438
                Ok($fun(value, $fun_closure))
439
            }
440
441
            #[inline]
442
0
            fn size_hint(depth: usize) -> (usize, Option<usize>) {
443
0
                $size_hint_closure(depth)
444
0
            }
Unexecuted instantiation: <core::ops::range::Range<_> 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
Unexecuted instantiation: <core::ops::range::RangeInclusive<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::ops::range::RangeFrom<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::ops::range::RangeFrom<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::ops::range::RangeToInclusive<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::ops::range::RangeTo<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::ops::range::RangeInclusive<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::ops::range::Range<_> as arbitrary::Arbitrary>::size_hint
445
        }
446
    };
447
}
448
449
impl_range!(
450
    Range<A>,
451
    |r: &Range<A>| (r.start.clone(), r.end.clone()),
452
    (A, A),
453
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>::arbitrary::{closure#0}
454
0
    |depth| crate::size_hint::and(
455
0
        <A as Arbitrary>::size_hint(depth),
456
0
        <A as Arbitrary>::size_hint(depth)
457
0
    )
Unexecuted instantiation: <core::ops::range::Range<_> as arbitrary::Arbitrary>::size_hint::{closure#0}
Unexecuted instantiation: <core::ops::range::Range<_> as arbitrary::Arbitrary>::size_hint::{closure#0}
458
);
459
impl_range!(
460
    RangeFrom<A>,
461
    |r: &RangeFrom<A>| r.start.clone(),
462
    A,
463
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>::arbitrary::{closure#0}
464
0
    |depth| <A as Arbitrary>::size_hint(depth)
Unexecuted instantiation: <core::ops::range::RangeFrom<_> as arbitrary::Arbitrary>::size_hint::{closure#0}
Unexecuted instantiation: <core::ops::range::RangeFrom<_> as arbitrary::Arbitrary>::size_hint::{closure#0}
465
);
466
impl_range!(
467
    RangeInclusive<A>,
468
    |r: &RangeInclusive<A>| (r.start().clone(), r.end().clone()),
469
    (A, A),
470
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>::arbitrary::{closure#0}
471
0
    |depth| crate::size_hint::and(
472
0
        <A as Arbitrary>::size_hint(depth),
473
0
        <A as Arbitrary>::size_hint(depth)
474
0
    )
Unexecuted instantiation: <core::ops::range::RangeInclusive<_> as arbitrary::Arbitrary>::size_hint::{closure#0}
Unexecuted instantiation: <core::ops::range::RangeInclusive<_> as arbitrary::Arbitrary>::size_hint::{closure#0}
475
);
476
impl_range!(
477
    RangeTo<A>,
478
    |r: &RangeTo<A>| r.end.clone(),
479
    A,
480
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>::arbitrary::{closure#0}
481
0
    |depth| <A as Arbitrary>::size_hint(depth)
Unexecuted instantiation: <core::ops::range::RangeTo<_> as arbitrary::Arbitrary>::size_hint::{closure#0}
Unexecuted instantiation: <core::ops::range::RangeTo<_> as arbitrary::Arbitrary>::size_hint::{closure#0}
482
);
483
impl_range!(
484
    RangeToInclusive<A>,
485
    |r: &RangeToInclusive<A>| r.end.clone(),
486
    A,
487
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>::arbitrary::{closure#0}
488
0
    |depth| <A as Arbitrary>::size_hint(depth)
Unexecuted instantiation: <core::ops::range::RangeToInclusive<_> as arbitrary::Arbitrary>::size_hint::{closure#0}
Unexecuted instantiation: <core::ops::range::RangeToInclusive<_> as arbitrary::Arbitrary>::size_hint::{closure#0}
489
);
490
491
0
pub(crate) fn bounded_range<CB, I, R>(bounds: (I, I), cb: CB) -> R
492
0
where
493
0
    CB: Fn((I, I)) -> R,
494
0
    I: PartialOrd,
495
0
    R: RangeBounds<I>,
496
0
{
497
0
    let (mut start, mut end) = bounds;
498
0
    if start > end {
499
0
        mem::swap(&mut start, &mut end);
500
0
    }
501
0
    cb((start, end))
502
0
}
Unexecuted instantiation: arbitrary::bounded_range::<_, _, _>
Unexecuted instantiation: arbitrary::bounded_range::<_, _, _>
503
504
0
pub(crate) fn unbounded_range<CB, I, R>(bound: I, cb: CB) -> R
505
0
where
506
0
    CB: Fn(I) -> R,
507
0
    R: RangeBounds<I>,
508
0
{
509
0
    cb(bound)
510
0
}
Unexecuted instantiation: arbitrary::unbounded_range::<_, _, _>
Unexecuted instantiation: arbitrary::unbounded_range::<_, _, _>
511
512
impl<'a> Arbitrary<'a> for Duration {
513
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
514
0
        Ok(Self::new(
515
0
            <u64 as Arbitrary>::arbitrary(u)?,
516
0
            u.int_in_range(0..=999_999_999)?,
517
        ))
518
0
    }
Unexecuted instantiation: <core::time::Duration as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::time::Duration as arbitrary::Arbitrary>::arbitrary
519
520
    #[inline]
521
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
522
0
        crate::size_hint::and(
523
0
            <u64 as Arbitrary>::size_hint(depth),
524
0
            <u32 as Arbitrary>::size_hint(depth),
525
0
        )
526
0
    }
Unexecuted instantiation: <core::time::Duration as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::time::Duration as arbitrary::Arbitrary>::size_hint
527
}
528
529
impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for Option<A> {
530
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
531
0
        Ok(if <bool as Arbitrary<'a>>::arbitrary(u)? {
532
0
            Some(Arbitrary::arbitrary(u)?)
533
        } else {
534
0
            None
535
        })
536
0
    }
Unexecuted instantiation: <core::option::Option<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::option::Option<_> as arbitrary::Arbitrary>::arbitrary
537
538
    #[inline]
539
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
540
0
        crate::size_hint::and(
541
0
            <bool as Arbitrary>::size_hint(depth),
542
0
            crate::size_hint::or((0, Some(0)), <A as Arbitrary>::size_hint(depth)),
543
0
        )
544
0
    }
Unexecuted instantiation: <core::option::Option<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::option::Option<_> as arbitrary::Arbitrary>::size_hint
545
}
546
547
impl<'a, A: Arbitrary<'a>, B: Arbitrary<'a>> Arbitrary<'a> for std::result::Result<A, B> {
548
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
549
0
        Ok(if <bool as Arbitrary<'a>>::arbitrary(u)? {
550
0
            Ok(<A as Arbitrary>::arbitrary(u)?)
551
        } else {
552
0
            Err(<B as Arbitrary>::arbitrary(u)?)
553
        })
554
0
    }
Unexecuted instantiation: <core::result::Result<_, _> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::result::Result<_, _> as arbitrary::Arbitrary>::arbitrary
555
556
    #[inline]
557
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
558
0
        crate::size_hint::and(
559
0
            <bool as Arbitrary>::size_hint(depth),
560
0
            crate::size_hint::or(
561
0
                <A as Arbitrary>::size_hint(depth),
562
0
                <B as Arbitrary>::size_hint(depth),
563
0
            ),
564
0
        )
565
0
    }
Unexecuted instantiation: <core::result::Result<_, _> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::result::Result<_, _> as arbitrary::Arbitrary>::size_hint
566
}
567
568
macro_rules! arbitrary_tuple {
569
    () => {};
570
    ($last: ident $($xs: ident)*) => {
571
        arbitrary_tuple!($($xs)*);
572
573
        impl<'a, $($xs: Arbitrary<'a>,)* $last: Arbitrary<'a>> Arbitrary<'a> for ($($xs,)* $last,) {
574
0
            fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
575
0
                Ok(($($xs::arbitrary(u)?,)* Arbitrary::arbitrary(u)?,))
576
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
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
577
578
            #[allow(unused_mut, non_snake_case)]
579
0
            fn arbitrary_take_rest(mut u: Unstructured<'a>) -> Result<Self> {
580
0
                $(let $xs = $xs::arbitrary(&mut u)?;)*
581
0
                let $last = $last::arbitrary_take_rest(u)?;
582
0
                Ok(($($xs,)* $last,))
583
0
            }
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
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
584
585
            #[inline]
586
0
            fn size_hint(depth: usize) -> (usize, Option<usize>) {
587
0
                crate::size_hint::and_all(&[
588
0
                    <$last as Arbitrary>::size_hint(depth),
589
0
                    $( <$xs as Arbitrary>::size_hint(depth) ),*
590
0
                ])
591
0
            }
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
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
592
        }
593
    };
594
}
595
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);
596
597
// Helper to safely create arrays since the standard library doesn't
598
// provide one yet. Shouldn't be necessary in the future.
599
struct ArrayGuard<T, const N: usize> {
600
    dst: *mut T,
601
    initialized: usize,
602
}
603
604
impl<T, const N: usize> Drop for ArrayGuard<T, N> {
605
0
    fn drop(&mut self) {
606
0
        debug_assert!(self.initialized <= N);
607
0
        let initialized_part = core::ptr::slice_from_raw_parts_mut(self.dst, self.initialized);
608
0
        unsafe {
609
0
            core::ptr::drop_in_place(initialized_part);
610
0
        }
611
0
    }
Unexecuted instantiation: <arbitrary::ArrayGuard<u8, 16> as core::ops::drop::Drop>::drop
Unexecuted instantiation: <arbitrary::ArrayGuard<_, _> as core::ops::drop::Drop>::drop
Unexecuted instantiation: <arbitrary::ArrayGuard<_, _> as core::ops::drop::Drop>::drop
612
}
613
614
406k
fn try_create_array<F, T, const N: usize>(mut cb: F) -> Result<[T; N]>
615
406k
where
616
406k
    F: FnMut(usize) -> Result<T>,
617
406k
{
618
406k
    let mut array: mem::MaybeUninit<[T; N]> = mem::MaybeUninit::uninit();
619
406k
    let array_ptr = array.as_mut_ptr();
620
406k
    let dst = array_ptr as _;
621
406k
    let mut guard: ArrayGuard<T, N> = ArrayGuard {
622
406k
        dst,
623
406k
        initialized: 0,
624
406k
    };
625
    unsafe {
626
6.49M
        for (idx, value_ptr) in (*array.as_mut_ptr()).iter_mut().enumerate() {
627
6.49M
            core::ptr::write(value_ptr, cb(idx)?);
628
6.49M
            guard.initialized += 1;
629
        }
630
406k
        mem::forget(guard);
631
406k
        Ok(array.assume_init())
632
    }
633
406k
}
arbitrary::try_create_array::<<[u8; 16] as arbitrary::Arbitrary>::arbitrary::{closure#0}, u8, 16>
Line
Count
Source
614
406k
fn try_create_array<F, T, const N: usize>(mut cb: F) -> Result<[T; N]>
615
406k
where
616
406k
    F: FnMut(usize) -> Result<T>,
617
406k
{
618
406k
    let mut array: mem::MaybeUninit<[T; N]> = mem::MaybeUninit::uninit();
619
406k
    let array_ptr = array.as_mut_ptr();
620
406k
    let dst = array_ptr as _;
621
406k
    let mut guard: ArrayGuard<T, N> = ArrayGuard {
622
406k
        dst,
623
406k
        initialized: 0,
624
406k
    };
625
    unsafe {
626
6.49M
        for (idx, value_ptr) in (*array.as_mut_ptr()).iter_mut().enumerate() {
627
6.49M
            core::ptr::write(value_ptr, cb(idx)?);
628
6.49M
            guard.initialized += 1;
629
        }
630
406k
        mem::forget(guard);
631
406k
        Ok(array.assume_init())
632
    }
633
406k
}
Unexecuted instantiation: arbitrary::try_create_array::<_, _, _>
Unexecuted instantiation: arbitrary::try_create_array::<_, _, _>
634
635
impl<'a, T, const N: usize> Arbitrary<'a> for [T; N]
636
where
637
    T: Arbitrary<'a>,
638
{
639
    #[inline]
640
406k
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
641
6.49M
        try_create_array(|_| <T as Arbitrary<'a>>::arbitrary(u))
<[u8; 16] as arbitrary::Arbitrary>::arbitrary::{closure#0}
Line
Count
Source
641
6.49M
        try_create_array(|_| <T as Arbitrary<'a>>::arbitrary(u))
Unexecuted instantiation: <[_; _] as arbitrary::Arbitrary>::arbitrary::{closure#0}
Unexecuted instantiation: <[_; _] as arbitrary::Arbitrary>::arbitrary::{closure#0}
642
406k
    }
<[u8; 16] as arbitrary::Arbitrary>::arbitrary
Line
Count
Source
640
406k
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
641
406k
        try_create_array(|_| <T as Arbitrary<'a>>::arbitrary(u))
642
406k
    }
Unexecuted instantiation: <[_; _] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <[_; _] as arbitrary::Arbitrary>::arbitrary
643
644
    #[inline]
645
0
    fn arbitrary_take_rest(mut u: Unstructured<'a>) -> Result<Self> {
646
0
        let mut array = Self::arbitrary(&mut u)?;
647
0
        if let Some(last) = array.last_mut() {
648
0
            *last = Arbitrary::arbitrary_take_rest(u)?;
649
0
        }
650
0
        Ok(array)
651
0
    }
Unexecuted instantiation: <[_; _] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <[_; _] as arbitrary::Arbitrary>::arbitrary_take_rest
652
653
    #[inline]
654
0
    fn size_hint(d: usize) -> (usize, Option<usize>) {
655
0
        crate::size_hint::and_all(&array::from_fn::<_, N, _>(|_| {
656
0
            <T as Arbitrary>::size_hint(d)
657
0
        }))
Unexecuted instantiation: <[_; _] as arbitrary::Arbitrary>::size_hint::{closure#0}
Unexecuted instantiation: <[_; _] as arbitrary::Arbitrary>::size_hint::{closure#0}
658
0
    }
Unexecuted instantiation: <[_; _] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <[_; _] as arbitrary::Arbitrary>::size_hint
659
}
660
661
impl<'a> Arbitrary<'a> for &'a [u8] {
662
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
663
0
        let len = u.arbitrary_len::<u8>()?;
664
0
        u.bytes(len)
665
0
    }
Unexecuted instantiation: <&[u8] as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <&[u8] as arbitrary::Arbitrary>::arbitrary
666
667
0
    fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> {
668
0
        Ok(u.take_rest())
669
0
    }
Unexecuted instantiation: <&[u8] as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <&[u8] as arbitrary::Arbitrary>::arbitrary_take_rest
670
671
    #[inline]
672
0
    fn size_hint(_depth: usize) -> (usize, Option<usize>) {
673
0
        (0, None)
674
0
    }
Unexecuted instantiation: <&[u8] as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <&[u8] as arbitrary::Arbitrary>::size_hint
675
}
676
677
impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for Vec<A> {
678
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
679
41.2M
        u.arbitrary_iter()?.collect()
680
41.2M
    }
<alloc::vec::Vec<u8> as arbitrary::Arbitrary>::arbitrary
Line
Count
Source
679
41.2M
        u.arbitrary_iter()?.collect()
680
41.2M
    }
Unexecuted instantiation: <alloc::vec::Vec<u8> as arbitrary::Arbitrary>::arbitrary
681
682
    fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> {
683
6.59k
        u.arbitrary_take_rest_iter()?.collect()
684
6.59k
    }
Unexecuted instantiation: <alloc::vec::Vec<_> as arbitrary::Arbitrary>::arbitrary_take_rest
<alloc::vec::Vec<alloc::vec::Vec<u8>> as arbitrary::Arbitrary>::arbitrary_take_rest
Line
Count
Source
683
3.29k
        u.arbitrary_take_rest_iter()?.collect()
684
3.29k
    }
<alloc::vec::Vec<u8> as arbitrary::Arbitrary>::arbitrary_take_rest
Line
Count
Source
683
3.29k
        u.arbitrary_take_rest_iter()?.collect()
684
3.29k
    }
Unexecuted instantiation: <alloc::vec::Vec<_> as arbitrary::Arbitrary>::arbitrary_take_rest
685
686
    #[inline]
687
6.59k
    fn size_hint(_depth: usize) -> (usize, Option<usize>) {
688
6.59k
        (0, None)
689
6.59k
    }
Unexecuted instantiation: <alloc::vec::Vec<_> as arbitrary::Arbitrary>::size_hint
<alloc::vec::Vec<alloc::vec::Vec<u8>> as arbitrary::Arbitrary>::size_hint
Line
Count
Source
687
3.29k
    fn size_hint(_depth: usize) -> (usize, Option<usize>) {
688
3.29k
        (0, None)
689
3.29k
    }
<alloc::vec::Vec<u8> as arbitrary::Arbitrary>::size_hint
Line
Count
Source
687
3.29k
    fn size_hint(_depth: usize) -> (usize, Option<usize>) {
688
3.29k
        (0, None)
689
3.29k
    }
Unexecuted instantiation: <alloc::vec::Vec<_> as arbitrary::Arbitrary>::size_hint
690
}
691
692
impl<'a, K: Arbitrary<'a> + Ord, V: Arbitrary<'a>> Arbitrary<'a> for BTreeMap<K, V> {
693
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
694
0
        u.arbitrary_iter()?.collect()
695
0
    }
Unexecuted instantiation: <alloc::collections::btree::map::BTreeMap<_, _> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <alloc::collections::btree::map::BTreeMap<_, _> as arbitrary::Arbitrary>::arbitrary
696
697
    fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> {
698
0
        u.arbitrary_take_rest_iter()?.collect()
699
0
    }
Unexecuted instantiation: <alloc::collections::btree::map::BTreeMap<_, _> as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <alloc::collections::btree::map::BTreeMap<_, _> as arbitrary::Arbitrary>::arbitrary_take_rest
700
701
    #[inline]
702
0
    fn size_hint(_depth: usize) -> (usize, Option<usize>) {
703
0
        (0, None)
704
0
    }
Unexecuted instantiation: <alloc::collections::btree::map::BTreeMap<_, _> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <alloc::collections::btree::map::BTreeMap<_, _> as arbitrary::Arbitrary>::size_hint
705
}
706
707
impl<'a, A: Arbitrary<'a> + Ord> Arbitrary<'a> for BTreeSet<A> {
708
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
709
0
        u.arbitrary_iter()?.collect()
710
0
    }
Unexecuted instantiation: <alloc::collections::btree::set::BTreeSet<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <alloc::collections::btree::set::BTreeSet<_> as arbitrary::Arbitrary>::arbitrary
711
712
    fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> {
713
0
        u.arbitrary_take_rest_iter()?.collect()
714
0
    }
Unexecuted instantiation: <alloc::collections::btree::set::BTreeSet<_> as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <alloc::collections::btree::set::BTreeSet<_> as arbitrary::Arbitrary>::arbitrary_take_rest
715
716
    #[inline]
717
0
    fn size_hint(_depth: usize) -> (usize, Option<usize>) {
718
0
        (0, None)
719
0
    }
Unexecuted instantiation: <alloc::collections::btree::set::BTreeSet<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <alloc::collections::btree::set::BTreeSet<_> as arbitrary::Arbitrary>::size_hint
720
}
721
722
impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for Bound<A> {
723
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
724
0
        match u.int_in_range::<u8>(0..=2)? {
725
0
            0 => Ok(Bound::Included(A::arbitrary(u)?)),
726
0
            1 => Ok(Bound::Excluded(A::arbitrary(u)?)),
727
0
            2 => Ok(Bound::Unbounded),
728
0
            _ => unreachable!(),
729
        }
730
0
    }
Unexecuted instantiation: <core::ops::range::Bound<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::ops::range::Bound<_> as arbitrary::Arbitrary>::arbitrary
731
732
    #[inline]
733
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
734
0
        size_hint::or(
735
0
            size_hint::and((1, Some(1)), A::size_hint(depth)),
736
0
            (1, Some(1)),
737
0
        )
738
0
    }
Unexecuted instantiation: <core::ops::range::Bound<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::ops::range::Bound<_> as arbitrary::Arbitrary>::size_hint
739
}
740
741
impl<'a, A: Arbitrary<'a> + Ord> Arbitrary<'a> for BinaryHeap<A> {
742
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
743
0
        u.arbitrary_iter()?.collect()
744
0
    }
Unexecuted instantiation: <alloc::collections::binary_heap::BinaryHeap<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <alloc::collections::binary_heap::BinaryHeap<_> as arbitrary::Arbitrary>::arbitrary
745
746
    fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> {
747
0
        u.arbitrary_take_rest_iter()?.collect()
748
0
    }
Unexecuted instantiation: <alloc::collections::binary_heap::BinaryHeap<_> as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <alloc::collections::binary_heap::BinaryHeap<_> as arbitrary::Arbitrary>::arbitrary_take_rest
749
750
    #[inline]
751
0
    fn size_hint(_depth: usize) -> (usize, Option<usize>) {
752
0
        (0, None)
753
0
    }
Unexecuted instantiation: <alloc::collections::binary_heap::BinaryHeap<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <alloc::collections::binary_heap::BinaryHeap<_> as arbitrary::Arbitrary>::size_hint
754
}
755
756
impl<'a, K: Arbitrary<'a> + Eq + ::std::hash::Hash, V: Arbitrary<'a>, S: BuildHasher + Default>
757
    Arbitrary<'a> for HashMap<K, V, S>
758
{
759
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
760
0
        u.arbitrary_iter()?.collect()
761
0
    }
Unexecuted instantiation: <std::collections::hash::map::HashMap<_, _, _> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <std::collections::hash::map::HashMap<_, _, _> as arbitrary::Arbitrary>::arbitrary
762
763
    fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> {
764
0
        u.arbitrary_take_rest_iter()?.collect()
765
0
    }
Unexecuted instantiation: <std::collections::hash::map::HashMap<_, _, _> as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <std::collections::hash::map::HashMap<_, _, _> as arbitrary::Arbitrary>::arbitrary_take_rest
766
767
    #[inline]
768
0
    fn size_hint(_depth: usize) -> (usize, Option<usize>) {
769
0
        (0, None)
770
0
    }
Unexecuted instantiation: <std::collections::hash::map::HashMap<_, _, _> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <std::collections::hash::map::HashMap<_, _, _> as arbitrary::Arbitrary>::size_hint
771
}
772
773
impl<'a, A: Arbitrary<'a> + Eq + ::std::hash::Hash, S: BuildHasher + Default> Arbitrary<'a>
774
    for HashSet<A, S>
775
{
776
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
777
0
        u.arbitrary_iter()?.collect()
778
0
    }
Unexecuted instantiation: <std::collections::hash::set::HashSet<_, _> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <std::collections::hash::set::HashSet<_, _> as arbitrary::Arbitrary>::arbitrary
779
780
    fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> {
781
0
        u.arbitrary_take_rest_iter()?.collect()
782
0
    }
Unexecuted instantiation: <std::collections::hash::set::HashSet<_, _> as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <std::collections::hash::set::HashSet<_, _> as arbitrary::Arbitrary>::arbitrary_take_rest
783
784
    #[inline]
785
0
    fn size_hint(_depth: usize) -> (usize, Option<usize>) {
786
0
        (0, None)
787
0
    }
Unexecuted instantiation: <std::collections::hash::set::HashSet<_, _> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <std::collections::hash::set::HashSet<_, _> as arbitrary::Arbitrary>::size_hint
788
}
789
790
impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for LinkedList<A> {
791
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
792
0
        u.arbitrary_iter()?.collect()
793
0
    }
Unexecuted instantiation: <alloc::collections::linked_list::LinkedList<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <alloc::collections::linked_list::LinkedList<_> as arbitrary::Arbitrary>::arbitrary
794
795
    fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> {
796
0
        u.arbitrary_take_rest_iter()?.collect()
797
0
    }
Unexecuted instantiation: <alloc::collections::linked_list::LinkedList<_> as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <alloc::collections::linked_list::LinkedList<_> as arbitrary::Arbitrary>::arbitrary_take_rest
798
799
    #[inline]
800
0
    fn size_hint(_depth: usize) -> (usize, Option<usize>) {
801
0
        (0, None)
802
0
    }
Unexecuted instantiation: <alloc::collections::linked_list::LinkedList<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <alloc::collections::linked_list::LinkedList<_> as arbitrary::Arbitrary>::size_hint
803
}
804
805
impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for VecDeque<A> {
806
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
807
0
        u.arbitrary_iter()?.collect()
808
0
    }
Unexecuted instantiation: <alloc::collections::vec_deque::VecDeque<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <alloc::collections::vec_deque::VecDeque<_> as arbitrary::Arbitrary>::arbitrary
809
810
    fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> {
811
0
        u.arbitrary_take_rest_iter()?.collect()
812
0
    }
Unexecuted instantiation: <alloc::collections::vec_deque::VecDeque<_> as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <alloc::collections::vec_deque::VecDeque<_> as arbitrary::Arbitrary>::arbitrary_take_rest
813
814
    #[inline]
815
0
    fn size_hint(_depth: usize) -> (usize, Option<usize>) {
816
0
        (0, None)
817
0
    }
Unexecuted instantiation: <alloc::collections::vec_deque::VecDeque<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <alloc::collections::vec_deque::VecDeque<_> as arbitrary::Arbitrary>::size_hint
818
}
819
820
impl<'a, A> Arbitrary<'a> for Cow<'a, A>
821
where
822
    A: ToOwned + ?Sized,
823
    <A as ToOwned>::Owned: Arbitrary<'a>,
824
{
825
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
826
0
        Arbitrary::arbitrary(u).map(Cow::Owned)
827
0
    }
Unexecuted instantiation: <alloc::borrow::Cow<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <alloc::borrow::Cow<_> as arbitrary::Arbitrary>::arbitrary
828
829
    #[inline]
830
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
831
0
        crate::size_hint::recursion_guard(depth, |depth| {
832
0
            <<A as ToOwned>::Owned as Arbitrary>::size_hint(depth)
833
0
        })
Unexecuted instantiation: <alloc::borrow::Cow<_> as arbitrary::Arbitrary>::size_hint::{closure#0}
Unexecuted instantiation: <alloc::borrow::Cow<_> as arbitrary::Arbitrary>::size_hint::{closure#0}
834
0
    }
Unexecuted instantiation: <alloc::borrow::Cow<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <alloc::borrow::Cow<_> as arbitrary::Arbitrary>::size_hint
835
}
836
837
impl<'a> Arbitrary<'a> for &'a str {
838
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
839
0
        let size = u.arbitrary_len::<u8>()?;
840
0
        match str::from_utf8(u.peek_bytes(size).unwrap()) {
841
0
            Ok(s) => {
842
0
                u.bytes(size).unwrap();
843
0
                Ok(s)
844
            }
845
0
            Err(e) => {
846
0
                let i = e.valid_up_to();
847
0
                let valid = u.bytes(i).unwrap();
848
0
                let s = unsafe {
849
0
                    debug_assert!(str::from_utf8(valid).is_ok());
850
0
                    str::from_utf8_unchecked(valid)
851
0
                };
852
0
                Ok(s)
853
            }
854
        }
855
0
    }
Unexecuted instantiation: <&str as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <&str as arbitrary::Arbitrary>::arbitrary
856
857
0
    fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> {
858
0
        let bytes = u.take_rest();
859
0
        str::from_utf8(bytes).map_err(|_| Error::IncorrectFormat)
Unexecuted instantiation: <&str as arbitrary::Arbitrary>::arbitrary_take_rest::{closure#0}
Unexecuted instantiation: <&str as arbitrary::Arbitrary>::arbitrary_take_rest::{closure#0}
860
0
    }
Unexecuted instantiation: <&str as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <&str as arbitrary::Arbitrary>::arbitrary_take_rest
861
862
    #[inline]
863
0
    fn size_hint(_depth: usize) -> (usize, Option<usize>) {
864
0
        (0, None)
865
0
    }
Unexecuted instantiation: <&str as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <&str as arbitrary::Arbitrary>::size_hint
866
}
867
868
impl<'a> Arbitrary<'a> for String {
869
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
870
0
        <&str as Arbitrary>::arbitrary(u).map(Into::into)
871
0
    }
Unexecuted instantiation: <alloc::string::String as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <alloc::string::String as arbitrary::Arbitrary>::arbitrary
872
873
0
    fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self> {
874
0
        <&str as Arbitrary>::arbitrary_take_rest(u).map(Into::into)
875
0
    }
Unexecuted instantiation: <alloc::string::String as arbitrary::Arbitrary>::arbitrary_take_rest
Unexecuted instantiation: <alloc::string::String as arbitrary::Arbitrary>::arbitrary_take_rest
876
877
    #[inline]
878
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
879
0
        <&str as Arbitrary>::size_hint(depth)
880
0
    }
Unexecuted instantiation: <alloc::string::String as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <alloc::string::String as arbitrary::Arbitrary>::size_hint
881
}
882
883
impl<'a> Arbitrary<'a> for CString {
884
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
885
0
        <Vec<u8> as Arbitrary>::arbitrary(u).map(|mut x| {
886
0
            x.retain(|&c| c != 0);
Unexecuted instantiation: <alloc::ffi::c_str::CString as arbitrary::Arbitrary>::arbitrary::{closure#0}::{closure#0}
Unexecuted instantiation: <alloc::ffi::c_str::CString as arbitrary::Arbitrary>::arbitrary::{closure#0}::{closure#0}
887
0
            Self::new(x).unwrap()
888
0
        })
Unexecuted instantiation: <alloc::ffi::c_str::CString as arbitrary::Arbitrary>::arbitrary::{closure#0}
Unexecuted instantiation: <alloc::ffi::c_str::CString as arbitrary::Arbitrary>::arbitrary::{closure#0}
889
0
    }
Unexecuted instantiation: <alloc::ffi::c_str::CString as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <alloc::ffi::c_str::CString as arbitrary::Arbitrary>::arbitrary
890
891
    #[inline]
892
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
893
0
        <Vec<u8> as Arbitrary>::size_hint(depth)
894
0
    }
Unexecuted instantiation: <alloc::ffi::c_str::CString as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <alloc::ffi::c_str::CString as arbitrary::Arbitrary>::size_hint
895
}
896
897
impl<'a> Arbitrary<'a> for OsString {
898
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
899
0
        <String as Arbitrary>::arbitrary(u).map(From::from)
900
0
    }
Unexecuted instantiation: <std::ffi::os_str::OsString as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <std::ffi::os_str::OsString as arbitrary::Arbitrary>::arbitrary
901
902
    #[inline]
903
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
904
0
        <String as Arbitrary>::size_hint(depth)
905
0
    }
Unexecuted instantiation: <std::ffi::os_str::OsString as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <std::ffi::os_str::OsString as arbitrary::Arbitrary>::size_hint
906
}
907
908
impl<'a> Arbitrary<'a> for PathBuf {
909
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
910
0
        <OsString as Arbitrary>::arbitrary(u).map(From::from)
911
0
    }
Unexecuted instantiation: <std::path::PathBuf as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <std::path::PathBuf as arbitrary::Arbitrary>::arbitrary
912
913
    #[inline]
914
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
915
0
        <OsString as Arbitrary>::size_hint(depth)
916
0
    }
Unexecuted instantiation: <std::path::PathBuf as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <std::path::PathBuf as arbitrary::Arbitrary>::size_hint
917
}
918
919
impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for Box<A> {
920
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
921
0
        Arbitrary::arbitrary(u).map(Self::new)
922
0
    }
Unexecuted instantiation: <alloc::boxed::Box<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <alloc::boxed::Box<_> as arbitrary::Arbitrary>::arbitrary
923
924
    #[inline]
925
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
926
0
        crate::size_hint::recursion_guard(depth, <A as Arbitrary>::size_hint)
927
0
    }
Unexecuted instantiation: <alloc::boxed::Box<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <alloc::boxed::Box<_> as arbitrary::Arbitrary>::size_hint
928
}
929
930
impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for Box<[A]> {
931
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
932
0
        <Vec<A> as Arbitrary>::arbitrary(u).map(|x| x.into_boxed_slice())
Unexecuted instantiation: <alloc::boxed::Box<[_]> as arbitrary::Arbitrary>::arbitrary::{closure#0}
Unexecuted instantiation: <alloc::boxed::Box<[_]> as arbitrary::Arbitrary>::arbitrary::{closure#0}
933
0
    }
Unexecuted instantiation: <alloc::boxed::Box<[_]> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <alloc::boxed::Box<[_]> as arbitrary::Arbitrary>::arbitrary
934
935
    #[inline]
936
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
937
0
        <Vec<A> as Arbitrary>::size_hint(depth)
938
0
    }
Unexecuted instantiation: <alloc::boxed::Box<[_]> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <alloc::boxed::Box<[_]> as arbitrary::Arbitrary>::size_hint
939
}
940
941
impl<'a> Arbitrary<'a> for Box<str> {
942
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
943
0
        <String as Arbitrary>::arbitrary(u).map(|x| x.into_boxed_str())
Unexecuted instantiation: <alloc::boxed::Box<str> as arbitrary::Arbitrary>::arbitrary::{closure#0}
Unexecuted instantiation: <alloc::boxed::Box<str> as arbitrary::Arbitrary>::arbitrary::{closure#0}
944
0
    }
Unexecuted instantiation: <alloc::boxed::Box<str> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <alloc::boxed::Box<str> as arbitrary::Arbitrary>::arbitrary
945
946
    #[inline]
947
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
948
0
        <String as Arbitrary>::size_hint(depth)
949
0
    }
Unexecuted instantiation: <alloc::boxed::Box<str> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <alloc::boxed::Box<str> as arbitrary::Arbitrary>::size_hint
950
}
951
952
// impl Arbitrary for Box<CStr> {
953
//     fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
954
//         <CString as Arbitrary>::arbitrary(u).map(|x| x.into_boxed_c_str())
955
//     }
956
// }
957
958
// impl Arbitrary for Box<OsStr> {
959
//     fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self> {
960
//         <OsString as Arbitrary>::arbitrary(u).map(|x| x.into_boxed_osstr())
961
//
962
//     }
963
// }
964
965
impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for Arc<A> {
966
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
967
0
        Arbitrary::arbitrary(u).map(Self::new)
968
0
    }
Unexecuted instantiation: <alloc::sync::Arc<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <alloc::sync::Arc<_> as arbitrary::Arbitrary>::arbitrary
969
970
    #[inline]
971
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
972
0
        crate::size_hint::recursion_guard(depth, <A as Arbitrary>::size_hint)
973
0
    }
Unexecuted instantiation: <alloc::sync::Arc<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <alloc::sync::Arc<_> as arbitrary::Arbitrary>::size_hint
974
}
975
976
impl<'a> Arbitrary<'a> for Arc<str> {
977
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
978
0
        <&str as Arbitrary>::arbitrary(u).map(Into::into)
979
0
    }
Unexecuted instantiation: <alloc::sync::Arc<str> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <alloc::sync::Arc<str> as arbitrary::Arbitrary>::arbitrary
980
981
    #[inline]
982
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
983
0
        <&str as Arbitrary>::size_hint(depth)
984
0
    }
Unexecuted instantiation: <alloc::sync::Arc<str> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <alloc::sync::Arc<str> as arbitrary::Arbitrary>::size_hint
985
}
986
987
impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for Rc<A> {
988
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
989
0
        Arbitrary::arbitrary(u).map(Self::new)
990
0
    }
Unexecuted instantiation: <alloc::rc::Rc<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <alloc::rc::Rc<_> as arbitrary::Arbitrary>::arbitrary
991
992
    #[inline]
993
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
994
0
        crate::size_hint::recursion_guard(depth, <A as Arbitrary>::size_hint)
995
0
    }
Unexecuted instantiation: <alloc::rc::Rc<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <alloc::rc::Rc<_> as arbitrary::Arbitrary>::size_hint
996
}
997
998
impl<'a> Arbitrary<'a> for Rc<str> {
999
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
1000
0
        <&str as Arbitrary>::arbitrary(u).map(Into::into)
1001
0
    }
Unexecuted instantiation: <alloc::rc::Rc<str> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <alloc::rc::Rc<str> as arbitrary::Arbitrary>::arbitrary
1002
1003
    #[inline]
1004
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1005
0
        <&str as Arbitrary>::size_hint(depth)
1006
0
    }
Unexecuted instantiation: <alloc::rc::Rc<str> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <alloc::rc::Rc<str> as arbitrary::Arbitrary>::size_hint
1007
}
1008
1009
impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for Cell<A> {
1010
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
1011
0
        Arbitrary::arbitrary(u).map(Self::new)
1012
0
    }
Unexecuted instantiation: <core::cell::Cell<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::cell::Cell<_> as arbitrary::Arbitrary>::arbitrary
1013
1014
    #[inline]
1015
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1016
0
        <A as Arbitrary<'a>>::size_hint(depth)
1017
0
    }
Unexecuted instantiation: <core::cell::Cell<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::cell::Cell<_> as arbitrary::Arbitrary>::size_hint
1018
}
1019
1020
impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for RefCell<A> {
1021
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
1022
0
        Arbitrary::arbitrary(u).map(Self::new)
1023
0
    }
Unexecuted instantiation: <core::cell::RefCell<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::cell::RefCell<_> as arbitrary::Arbitrary>::arbitrary
1024
1025
    #[inline]
1026
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1027
0
        <A as Arbitrary<'a>>::size_hint(depth)
1028
0
    }
Unexecuted instantiation: <core::cell::RefCell<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::cell::RefCell<_> as arbitrary::Arbitrary>::size_hint
1029
}
1030
1031
impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for UnsafeCell<A> {
1032
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
1033
0
        Arbitrary::arbitrary(u).map(Self::new)
1034
0
    }
Unexecuted instantiation: <core::cell::UnsafeCell<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::cell::UnsafeCell<_> as arbitrary::Arbitrary>::arbitrary
1035
1036
    #[inline]
1037
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1038
0
        <A as Arbitrary<'a>>::size_hint(depth)
1039
0
    }
Unexecuted instantiation: <core::cell::UnsafeCell<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::cell::UnsafeCell<_> as arbitrary::Arbitrary>::size_hint
1040
}
1041
1042
impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for Mutex<A> {
1043
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
1044
0
        Arbitrary::arbitrary(u).map(Self::new)
1045
0
    }
Unexecuted instantiation: <std::sync::mutex::Mutex<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <std::sync::mutex::Mutex<_> as arbitrary::Arbitrary>::arbitrary
1046
1047
    #[inline]
1048
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1049
0
        <A as Arbitrary<'a>>::size_hint(depth)
1050
0
    }
Unexecuted instantiation: <std::sync::mutex::Mutex<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <std::sync::mutex::Mutex<_> as arbitrary::Arbitrary>::size_hint
1051
}
1052
1053
impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for iter::Empty<A> {
1054
0
    fn arbitrary(_: &mut Unstructured<'a>) -> Result<Self> {
1055
0
        Ok(iter::empty())
1056
0
    }
Unexecuted instantiation: <core::iter::sources::empty::Empty<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::iter::sources::empty::Empty<_> as arbitrary::Arbitrary>::arbitrary
1057
1058
    #[inline]
1059
0
    fn size_hint(_depth: usize) -> (usize, Option<usize>) {
1060
0
        (0, Some(0))
1061
0
    }
Unexecuted instantiation: <core::iter::sources::empty::Empty<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::iter::sources::empty::Empty<_> as arbitrary::Arbitrary>::size_hint
1062
}
1063
1064
impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for ::std::marker::PhantomData<A> {
1065
0
    fn arbitrary(_: &mut Unstructured<'a>) -> Result<Self> {
1066
0
        Ok(::std::marker::PhantomData)
1067
0
    }
Unexecuted instantiation: <core::marker::PhantomData<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::marker::PhantomData<_> as arbitrary::Arbitrary>::arbitrary
1068
1069
    #[inline]
1070
0
    fn size_hint(_depth: usize) -> (usize, Option<usize>) {
1071
0
        (0, Some(0))
1072
0
    }
Unexecuted instantiation: <core::marker::PhantomData<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::marker::PhantomData<_> as arbitrary::Arbitrary>::size_hint
1073
}
1074
1075
impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for ::std::num::Wrapping<A> {
1076
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
1077
0
        Arbitrary::arbitrary(u).map(::std::num::Wrapping)
1078
0
    }
Unexecuted instantiation: <core::num::wrapping::Wrapping<_> as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::num::wrapping::Wrapping<_> as arbitrary::Arbitrary>::arbitrary
1079
1080
    #[inline]
1081
0
    fn size_hint(depth: usize) -> (usize, Option<usize>) {
1082
0
        <A as Arbitrary<'a>>::size_hint(depth)
1083
0
    }
Unexecuted instantiation: <core::num::wrapping::Wrapping<_> as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::wrapping::Wrapping<_> as arbitrary::Arbitrary>::size_hint
1084
}
1085
1086
macro_rules! implement_nonzero_int {
1087
    ($nonzero:ty, $int:ty) => {
1088
        impl<'a> Arbitrary<'a> for $nonzero {
1089
            fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
1090
                match Self::new(<$int as Arbitrary<'a>>::arbitrary(u)?) {
1091
                    Some(n) => Ok(n),
1092
                    None => Err(Error::IncorrectFormat),
1093
                }
1094
            }
1095
1096
            #[inline]
1097
0
            fn size_hint(depth: usize) -> (usize, Option<usize>) {
1098
0
                <$int as Arbitrary<'a>>::size_hint(depth)
1099
0
            }
Unexecuted instantiation: <core::num::nonzero::NonZeroI16 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::nonzero::NonZeroUsize as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::nonzero::NonZeroI128 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::nonzero::NonZeroU16 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::nonzero::NonZeroU128 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::nonzero::NonZeroI8 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::nonzero::NonZeroI64 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::nonzero::NonZeroU8 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::nonzero::NonZeroU64 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::nonzero::NonZeroI32 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::nonzero::NonZeroIsize as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::nonzero::NonZeroU32 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::nonzero::NonZeroU16 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::nonzero::NonZeroU32 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::nonzero::NonZeroI64 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::nonzero::NonZeroU64 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::nonzero::NonZeroI128 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::nonzero::NonZeroI8 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::nonzero::NonZeroU128 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::nonzero::NonZeroIsize as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::nonzero::NonZeroU8 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::nonzero::NonZeroI16 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::nonzero::NonZeroI32 as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::num::nonzero::NonZeroUsize as arbitrary::Arbitrary>::size_hint
1100
        }
1101
    };
1102
}
1103
1104
implement_nonzero_int! { NonZeroI8, i8 }
1105
implement_nonzero_int! { NonZeroI16, i16 }
1106
implement_nonzero_int! { NonZeroI32, i32 }
1107
implement_nonzero_int! { NonZeroI64, i64 }
1108
implement_nonzero_int! { NonZeroI128, i128 }
1109
implement_nonzero_int! { NonZeroIsize, isize }
1110
implement_nonzero_int! { NonZeroU8, u8 }
1111
implement_nonzero_int! { NonZeroU16, u16 }
1112
implement_nonzero_int! { NonZeroU32, u32 }
1113
implement_nonzero_int! { NonZeroU64, u64 }
1114
implement_nonzero_int! { NonZeroU128, u128 }
1115
implement_nonzero_int! { NonZeroUsize, usize }
1116
1117
impl<'a> Arbitrary<'a> for Ipv4Addr {
1118
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
1119
0
        Ok(Ipv4Addr::from(u32::arbitrary(u)?))
1120
0
    }
Unexecuted instantiation: <core::net::ip_addr::Ipv4Addr as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::net::ip_addr::Ipv4Addr as arbitrary::Arbitrary>::arbitrary
1121
1122
    #[inline]
1123
0
    fn size_hint(_depth: usize) -> (usize, Option<usize>) {
1124
0
        (4, Some(4))
1125
0
    }
Unexecuted instantiation: <core::net::ip_addr::Ipv4Addr as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::net::ip_addr::Ipv4Addr as arbitrary::Arbitrary>::size_hint
1126
}
1127
1128
impl<'a> Arbitrary<'a> for Ipv6Addr {
1129
0
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
1130
0
        Ok(Ipv6Addr::from(u128::arbitrary(u)?))
1131
0
    }
Unexecuted instantiation: <core::net::ip_addr::Ipv6Addr as arbitrary::Arbitrary>::arbitrary
Unexecuted instantiation: <core::net::ip_addr::Ipv6Addr as arbitrary::Arbitrary>::arbitrary
1132
1133
    #[inline]
1134
0
    fn size_hint(_depth: usize) -> (usize, Option<usize>) {
1135
0
        (16, Some(16))
1136
0
    }
Unexecuted instantiation: <core::net::ip_addr::Ipv6Addr as arbitrary::Arbitrary>::size_hint
Unexecuted instantiation: <core::net::ip_addr::Ipv6Addr as arbitrary::Arbitrary>::size_hint
1137
}
1138
1139
#[cfg(test)]
1140
mod test {
1141
    use super::*;
1142
1143
    /// Generates an arbitrary `T`, and checks that the result is consistent with the
1144
    /// `size_hint()` reported by `T`.
1145
    fn checked_arbitrary<'a, T: Arbitrary<'a>>(u: &mut Unstructured<'a>) -> Result<T> {
1146
        let (min, max) = T::size_hint(0);
1147
1148
        let len_before = u.len();
1149
        let result = T::arbitrary(u);
1150
1151
        let consumed = len_before - u.len();
1152
1153
        if let Some(max) = max {
1154
            assert!(
1155
                consumed <= max,
1156
                "incorrect maximum size: indicated {}, actually consumed {}",
1157
                max,
1158
                consumed
1159
            );
1160
        }
1161
1162
        if result.is_ok() {
1163
            assert!(
1164
                consumed >= min,
1165
                "incorrect minimum size: indicated {}, actually consumed {}",
1166
                min,
1167
                consumed
1168
            );
1169
        }
1170
1171
        result
1172
    }
1173
1174
    /// Like `checked_arbitrary()`, but calls `arbitrary_take_rest()` instead of `arbitrary()`.
1175
    fn checked_arbitrary_take_rest<'a, T: Arbitrary<'a>>(u: Unstructured<'a>) -> Result<T> {
1176
        let (min, _) = T::size_hint(0);
1177
1178
        let len_before = u.len();
1179
        let result = T::arbitrary_take_rest(u);
1180
1181
        if result.is_ok() {
1182
            assert!(
1183
                len_before >= min,
1184
                "incorrect minimum size: indicated {}, worked with {}",
1185
                min,
1186
                len_before
1187
            );
1188
        }
1189
1190
        result
1191
    }
1192
1193
    #[test]
1194
    fn finite_buffer_fill_buffer() {
1195
        let x = [1, 2, 3, 4];
1196
        let mut rb = Unstructured::new(&x);
1197
        let mut z = [0; 2];
1198
        rb.fill_buffer(&mut z).unwrap();
1199
        assert_eq!(z, [1, 2]);
1200
        rb.fill_buffer(&mut z).unwrap();
1201
        assert_eq!(z, [3, 4]);
1202
        rb.fill_buffer(&mut z).unwrap();
1203
        assert_eq!(z, [0, 0]);
1204
    }
1205
1206
    #[test]
1207
    fn arbitrary_for_integers() {
1208
        let x = [1, 2, 3, 4];
1209
        let mut buf = Unstructured::new(&x);
1210
        let expected = 1 | (2 << 8) | (3 << 16) | (4 << 24);
1211
        let actual = checked_arbitrary::<i32>(&mut buf).unwrap();
1212
        assert_eq!(expected, actual);
1213
    }
1214
1215
    #[test]
1216
    fn arbitrary_for_bytes() {
1217
        let x = [1, 2, 3, 4, 4];
1218
        let mut buf = Unstructured::new(&x);
1219
        let expected = &[1, 2, 3, 4];
1220
        let actual = checked_arbitrary::<&[u8]>(&mut buf).unwrap();
1221
        assert_eq!(expected, actual);
1222
    }
1223
1224
    #[test]
1225
    fn arbitrary_take_rest_for_bytes() {
1226
        let x = [1, 2, 3, 4];
1227
        let buf = Unstructured::new(&x);
1228
        let expected = &[1, 2, 3, 4];
1229
        let actual = checked_arbitrary_take_rest::<&[u8]>(buf).unwrap();
1230
        assert_eq!(expected, actual);
1231
    }
1232
1233
    #[test]
1234
    fn arbitrary_collection() {
1235
        let x = [
1236
            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, 12,
1237
        ];
1238
        assert_eq!(
1239
            checked_arbitrary::<&[u8]>(&mut Unstructured::new(&x)).unwrap(),
1240
            &[1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3]
1241
        );
1242
        assert_eq!(
1243
            checked_arbitrary::<Vec<u8>>(&mut Unstructured::new(&x)).unwrap(),
1244
            &[2, 4, 6, 8, 1]
1245
        );
1246
        assert_eq!(
1247
            checked_arbitrary::<Vec<u32>>(&mut Unstructured::new(&x)).unwrap(),
1248
            &[84148994]
1249
        );
1250
        assert_eq!(
1251
            checked_arbitrary::<String>(&mut Unstructured::new(&x)).unwrap(),
1252
            "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x01\x02\x03"
1253
        );
1254
    }
1255
1256
    #[test]
1257
    fn arbitrary_take_rest() {
1258
        let x = [1, 2, 3, 4];
1259
        assert_eq!(
1260
            checked_arbitrary_take_rest::<&[u8]>(Unstructured::new(&x)).unwrap(),
1261
            &[1, 2, 3, 4]
1262
        );
1263
        assert_eq!(
1264
            checked_arbitrary_take_rest::<Vec<u8>>(Unstructured::new(&x)).unwrap(),
1265
            &[1, 2, 3, 4]
1266
        );
1267
        assert_eq!(
1268
            checked_arbitrary_take_rest::<Vec<u32>>(Unstructured::new(&x)).unwrap(),
1269
            &[0x4030201]
1270
        );
1271
        assert_eq!(
1272
            checked_arbitrary_take_rest::<String>(Unstructured::new(&x)).unwrap(),
1273
            "\x01\x02\x03\x04"
1274
        );
1275
1276
        assert_eq!(
1277
            checked_arbitrary_take_rest::<&[u8]>(Unstructured::new(&[])).unwrap(),
1278
            &[]
1279
        );
1280
        assert_eq!(
1281
            checked_arbitrary_take_rest::<Vec<u8>>(Unstructured::new(&[])).unwrap(),
1282
            &[]
1283
        );
1284
    }
1285
1286
    #[test]
1287
    fn size_hint_for_tuples() {
1288
        assert_eq!(
1289
            (7, Some(7)),
1290
            <(bool, u16, i32) as Arbitrary<'_>>::size_hint(0)
1291
        );
1292
        assert_eq!((1, None), <(u8, Vec<u8>) as Arbitrary>::size_hint(0));
1293
    }
1294
}
1295
1296
/// Multiple conflicting arbitrary attributes are used on the same field:
1297
/// ```compile_fail
1298
/// #[derive(::arbitrary::Arbitrary)]
1299
/// struct Point {
1300
///     #[arbitrary(value = 2)]
1301
///     #[arbitrary(value = 2)]
1302
///     x: i32,
1303
/// }
1304
/// ```
1305
///
1306
/// An unknown attribute:
1307
/// ```compile_fail
1308
/// #[derive(::arbitrary::Arbitrary)]
1309
/// struct Point {
1310
///     #[arbitrary(unknown_attr)]
1311
///     x: i32,
1312
/// }
1313
/// ```
1314
///
1315
/// An unknown attribute with a value:
1316
/// ```compile_fail
1317
/// #[derive(::arbitrary::Arbitrary)]
1318
/// struct Point {
1319
///     #[arbitrary(unknown_attr = 13)]
1320
///     x: i32,
1321
/// }
1322
/// ```
1323
///
1324
/// `value` without RHS:
1325
/// ```compile_fail
1326
/// #[derive(::arbitrary::Arbitrary)]
1327
/// struct Point {
1328
///     #[arbitrary(value)]
1329
///     x: i32,
1330
/// }
1331
/// ```
1332
///
1333
/// `with` without RHS:
1334
/// ```compile_fail
1335
/// #[derive(::arbitrary::Arbitrary)]
1336
/// struct Point {
1337
///     #[arbitrary(with)]
1338
///     x: i32,
1339
/// }
1340
/// ```
1341
///
1342
/// Multiple conflicting bounds at the container-level:
1343
/// ```compile_fail
1344
/// #[derive(::arbitrary::Arbitrary)]
1345
/// #[arbitrary(bound = "T: Default")]
1346
/// #[arbitrary(bound = "T: Default")]
1347
/// struct Point<T: Default> {
1348
///     #[arbitrary(default)]
1349
///     x: T,
1350
/// }
1351
/// ```
1352
///
1353
/// Multiple conflicting bounds in a single bound attribute:
1354
/// ```compile_fail
1355
/// #[derive(::arbitrary::Arbitrary)]
1356
/// #[arbitrary(bound = "T: Default, T: Default")]
1357
/// struct Point<T: Default> {
1358
///     #[arbitrary(default)]
1359
///     x: T,
1360
/// }
1361
/// ```
1362
///
1363
/// Multiple conflicting bounds in multiple bound attributes:
1364
/// ```compile_fail
1365
/// #[derive(::arbitrary::Arbitrary)]
1366
/// #[arbitrary(bound = "T: Default", bound = "T: Default")]
1367
/// struct Point<T: Default> {
1368
///     #[arbitrary(default)]
1369
///     x: T,
1370
/// }
1371
/// ```
1372
///
1373
/// Too many bounds supplied:
1374
/// ```compile_fail
1375
/// #[derive(::arbitrary::Arbitrary)]
1376
/// #[arbitrary(bound = "T: Default")]
1377
/// struct Point {
1378
///     x: i32,
1379
/// }
1380
/// ```
1381
///
1382
/// Too many bounds supplied across multiple attributes:
1383
/// ```compile_fail
1384
/// #[derive(::arbitrary::Arbitrary)]
1385
/// #[arbitrary(bound = "T: Default")]
1386
/// #[arbitrary(bound = "U: Default")]
1387
/// struct Point<T: Default> {
1388
///     #[arbitrary(default)]
1389
///     x: T,
1390
/// }
1391
/// ```
1392
#[cfg(all(doctest, feature = "derive"))]
1393
pub struct CompileFailTests;