Update ReadDir::next in std::sys::pal::unix::fs to use &raw const (*p).field instead of p.byte_offset().cast()#134678
Merged
Merged
Conversation
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.
Since rust-lang/reference#1387 and #117572,
&raw mut (*p).field/addr_of!((*p).field)is defined to have the same inbounds preconditions asptr::offset/ptr::byte_offset. I.e.&raw const (*p).fielddoes not require thatp: *const Tpoint to a fullsize_of::<T>()bytes of memory, only thatp.byte_add(offset_of!(T, field))is defined.The old comment "[...] we don't even get to use
&raw const (*entry_ptr).d_namebecause that operation requires the full extent of *entry_ptr to be in bounds of the same allocation, which is not necessarily the case here [...]" is now outdated, and the code can be simplified to use&raw const (*entry_ptr).field.There should be no behavior differences from this PR.
The
: *const dirent64on line 716 and theconst _: usize = mem::offset_of!(dirent64, $field);and comment on lines 749-751 are just sanity checks and should not affect semantics.Since the
offset_ptr!macro is only called three times, and all with the same local variable entry_ptr, I just used the local variable directly in the macro instead of taking it as an input, and renamed the macro toentry_field_ptr!.The whole macro could also be removed and replaced with just using
&raw const (*entry_ptr).fieldin the three places, but the comments on the macro seemed worthwhile to keep.