Skip to content

Commit 5b86c44

Browse files
committed
Bump to 1.4.0
1 parent 1cc0e46 commit 5b86c44

File tree

4 files changed

+57
-26
lines changed

4 files changed

+57
-26
lines changed

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,30 @@ Released YYYY-MM-DD.
2828

2929
--------------------------------------------------------------------------------
3030

31+
## 1.4.0
32+
33+
Released 2024-10-30.
34+
35+
### Added
36+
37+
* Added an `Arbitrary` implementation for `PhantomPinned`.
38+
* Added the `Unstructured::choose_iter` helper method.
39+
* Added `#[arbitrary(skip)]` for `enum` variants in the derive macro.
40+
* Added the `Arbitrary::try_size_hint` trait method.
41+
42+
### Changed
43+
44+
* Implement `Arbitrary` for `PhantomData<A>` even when `A` does not implement
45+
`Arbitrary` and when `A` is `?Sized`.
46+
* Make `usize`'s underlying encoding independent of machine word size so that
47+
corpora are more portable.
48+
49+
### Fixed
50+
51+
* Make `derive(Arbitrary)` work for local definitions of `struct Option`.
52+
53+
--------------------------------------------------------------------------------
54+
3155
## 1.3.2
3256

3357
Released 2023-10-30.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "arbitrary"
3-
version = "1.3.2" # Make sure this matches the derive crate version (not including the patch version)
3+
version = "1.4.0" # Make sure this matches the derive crate version (not including the patch version)
44
authors = [
55
"The Rust-Fuzz Project Developers",
66
"Nick Fitzgerald <[email protected]>",
@@ -20,7 +20,7 @@ documentation = "https://docs.rs/arbitrary/"
2020
rust-version = "1.63.0"
2121

2222
[dependencies]
23-
derive_arbitrary = { version = "1.3.2", path = "./derive", optional = true }
23+
derive_arbitrary = { version = "1.4.0", path = "./derive", optional = true }
2424

2525
[features]
2626
# Turn this feature on to enable support for `#[derive(Arbitrary)]`.

derive/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "derive_arbitrary"
3-
version = "1.3.2" # Make sure it matches the version of the arbitrary crate itself (not including the patch version)
3+
version = "1.4.0" # Make sure it matches the version of the arbitrary crate itself (not including the patch version)
44
authors = [
55
"The Rust-Fuzz Project Developers",
66
"Nick Fitzgerald <[email protected]>",
@@ -24,4 +24,4 @@ quote = "1.0"
2424
syn = { version = "2", features = ['derive', 'parsing', 'extra-traits'] }
2525

2626
[lib]
27-
proc_macro = true
27+
proc-macro = true

src/lib.rs

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -223,21 +223,22 @@ pub trait Arbitrary<'a>: Sized {
223223
/// This is useful for determining how many elements we should insert when
224224
/// creating an arbitrary collection.
225225
///
226-
/// The return value is similar to
227-
/// [`Iterator::size_hint`]: it returns a tuple where
228-
/// the first element is a lower bound on the number of bytes required, and
229-
/// the second element is an optional upper bound.
226+
/// The return value is similar to [`Iterator::size_hint`]: it returns a
227+
/// tuple where the first element is a lower bound on the number of bytes
228+
/// required, and the second element is an optional upper bound.
230229
///
231230
/// The default implementation return `(0, None)` which is correct for any
232231
/// type, but not ultimately that useful. Using `#[derive(Arbitrary)]` will
233232
/// create a better implementation. If you are writing an `Arbitrary`
234233
/// implementation by hand, and your type can be part of a dynamically sized
235234
/// collection (such as `Vec`), you are strongly encouraged to override this
236-
/// default with a better implementation, and also override [`try_size_hint`]
235+
/// default with a better implementation, and also override
236+
/// [`try_size_hint`].
237237
///
238238
/// ## How to implement this
239239
///
240-
/// If the size hint calculation is a trivial constant and does not recurse into any other `size_hint` call, you should implement it in `size_hint`:
240+
/// If the size hint calculation is a trivial constant and does not recurse
241+
/// into any other `size_hint` call, you should implement it in `size_hint`:
241242
///
242243
/// ```
243244
/// use arbitrary::{size_hint, Arbitrary, Result, Unstructured};
@@ -272,7 +273,8 @@ pub trait Arbitrary<'a>: Sized {
272273
///
273274
/// impl<'a, A: Arbitrary<'a>, B: Arbitrary<'a>> Arbitrary<'a> for SomeStruct<A, B> {
274275
/// fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
275-
/// todo!()
276+
/// // ...
277+
/// # todo!()
276278
/// }
277279
///
278280
/// fn size_hint(depth: usize) -> (usize, Option<usize>) {
@@ -323,20 +325,22 @@ pub trait Arbitrary<'a>: Sized {
323325
/// Get a size hint for how many bytes out of an `Unstructured` this type
324326
/// needs to construct itself.
325327
///
326-
/// Unlike [`size_hint`], this function keeps the information
327-
/// that the recursion limit was reached. This is required to "short circuit" the calculation
328-
/// and avoid exponential blowup with recursive structures.
328+
/// Unlike [`size_hint`], this function keeps the information that the
329+
/// recursion limit was reached. This is required to "short circuit" the
330+
/// calculation and avoid exponential blowup with recursive structures.
329331
///
330-
/// If you are implementing [`size_hint`] for a struct that could be recursive, you should implement `try_size_hint` and call the `try_size_hint` when recursing
332+
/// If you are implementing [`size_hint`] for a struct that could be
333+
/// recursive, you should implement `try_size_hint` and call the
334+
/// `try_size_hint` when recursing
331335
///
332336
///
333-
/// The return value is similar to
334-
/// [`Iterator::size_hint`][iterator-size-hint]: it returns a tuple where
335-
/// the first element is a lower bound on the number of bytes required, and
336-
/// the second element is an optional upper bound.
337+
/// The return value is similar to [`core::iter::Iterator::size_hint`]: it
338+
/// returns a tuple where the first element is a lower bound on the number
339+
/// of bytes required, and the second element is an optional upper bound.
337340
///
338-
/// The default implementation return the value of [`size_hint`] which is correct for any
339-
/// type, but might lead to exponential blowup when dealing with recursive types.
341+
/// The default implementation returns the value of [`size_hint`] which is
342+
/// correct for any type, but might lead to exponential blowup when dealing
343+
/// with recursive types.
340344
///
341345
/// ## Invariant
342346
///
@@ -353,11 +357,15 @@ pub trait Arbitrary<'a>: Sized {
353357
///
354358
/// If you 100% know that the type you are implementing `Arbitrary` for is
355359
/// not a recursive type, or your implementation is not transitively calling
356-
/// any other `size_hint` methods, you just implement [`size_hint`], and the
360+
/// any other `size_hint` methods, you may implement [`size_hint`], and the
357361
/// default `try_size_hint` implementation will use it.
362+
///
358363
/// Note that if you are implementing `Arbitrary` for a generic type, you
359364
/// cannot guarantee the lack of type recursion!
360365
///
366+
/// Otherwise, when there is possible type recursion, you should implement
367+
/// `try_size_hint` instead.
368+
///
361369
/// ## The `depth` parameter
362370
///
363371
/// When implementing `try_size_hint`, you need to use
@@ -386,9 +394,10 @@ pub trait Arbitrary<'a>: Sized {
386394
/// }
387395
///
388396
/// fn size_hint(depth: usize) -> (usize, Option<usize>) {
389-
/// // Return the value of try_size_hint
397+
/// // Return the value of `try_size_hint`
390398
/// //
391-
/// // If the recursion fails, return the default, always valid `(0, None)`
399+
/// // If the recursion fails, return the default `(0, None)` range,
400+
/// // which is always valid.
392401
/// Self::try_size_hint(depth).unwrap_or_default()
393402
/// }
394403
///
@@ -410,8 +419,6 @@ pub trait Arbitrary<'a>: Sized {
410419
/// }
411420
/// }
412421
/// ```
413-
/// [iterator-size-hint]: https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html#method.size_hint
414-
/// [`size_hint`]: Arbitrary::size_hint
415422
#[inline]
416423
fn try_size_hint(depth: usize) -> Result<(usize, Option<usize>), MaxRecursionReached> {
417424
Ok(Self::size_hint(depth))

0 commit comments

Comments
 (0)