Add support for arbritrary arrays#55
Merged
fitzgen merged 2 commits intorust-fuzz:masterfrom Mar 29, 2021
Merged
Conversation
Member
|
I would prefer not to have nightly-only features in this crate. |
Contributor
Author
|
@fitzgen You might have a better insight but I am betting on 1.49 that is going to be released on 2020-12-31 |
Member
|
I don't have any insider insight here, but I'd prefer revisiting after it merges to stable. Happy to leave this PR open until then. |
Contributor
Author
|
The time has come. |
fitzgen
reviewed
Mar 29, 2021
src/lib.rs
Outdated
| { | ||
| let mut array: mem::MaybeUninit<[T; N]> = mem::MaybeUninit::uninit(); | ||
| let mut guard: ArrayGuard<T, N> = ArrayGuard { | ||
| dst: array.as_mut_ptr() as _, |
Member
There was a problem hiding this comment.
What is the as cast doing here? Converting from *mut [T; N] to *mut T? If so, can we lift that to multiple lets that show the types, like this:
let dst: *mut [T; N] = array.as_mut_ptr();
let dst: *mut T = dst as _;
// ...| fn arbitrary_take_rest(mut u: Unstructured<'a>) -> Result<[T; $n]> { | ||
| $(let $as = $ts::arbitrary(&mut u)?;)* | ||
| let last = Arbitrary::arbitrary_take_rest(u)?; | ||
| struct ArrayGuard<T, const N: usize> { |
Member
There was a problem hiding this comment.
Could you add a little documentation for what role this guard plays? That will help future readers of this code.
src/lib.rs
Outdated
| { | ||
| let mut array: mem::MaybeUninit<[T; N]> = mem::MaybeUninit::uninit(); | ||
| let mut guard: ArrayGuard<T, N> = ArrayGuard { | ||
| dst: array.as_mut_ptr() as _, |
Contributor
Author
|
Done. Thanks for the review |
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
T: Defaultwould remove allunsafes but it isn't currently possible for[T; N]and this bound limitation isn't desirable for stuff that don't implementDefault.If rust-lang/rust#75644 is going to be accepted, then the auxiliary functions won't be necessary in the near future.