Skip to content

Commit

Permalink
[pointer] Remove Ptr::project method (#2339)
Browse files Browse the repository at this point in the history
Now that #1122 is complete in #1896, `project` is redundant.

gherrit-pr-id: I15d38f2f1fffad82caa70ea6eb18dffcd6504495
  • Loading branch information
joshlf authored Feb 17, 2025
1 parent 28b55b9 commit 9322a2c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 68 deletions.
26 changes: 0 additions & 26 deletions src/pointer/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,32 +1077,6 @@ mod _casts {
mod _project {
use super::*;

impl<'a, T: ?Sized, I> Ptr<'a, Initialized<T>, I>
where
I: Invariants,
{
/// Projects a field from `self`.
///
/// # Safety
///
/// `project` has the same safety preconditions as
/// `cast_unsized_unchecked`.
#[doc(hidden)]
#[inline]
pub unsafe fn project<W: 'a + ?Sized>(
self,
projector: impl FnOnce(*mut T) -> *mut W,
) -> Ptr<'a, Initialized<W>, (I::Aliasing, Unknown)> {
// TODO(#1122): If `cast_unsized` were able to reason that, when
// casting from an `Initialized` pointer, the result is another
// `Initialized` pointer, we could remove this method entirely.

// SAFETY: This method has the same safety preconditions as
// `cast_unsized_unchecked`.
unsafe { self.cast_unsized_unchecked(projector) }
}
}

impl<V, T, I> Ptr<'_, V, I>
where
V: Validity<Inner = [T]>,
Expand Down
2 changes: 1 addition & 1 deletion zerocopy-derive/src/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ pub(crate) fn derive_is_bit_valid(
// subfield pointer just points to a smaller portion of the
// overall struct.
let variants = unsafe {
raw_enum.project(|p: *mut ___ZerocopyRawEnum #ty_generics| {
raw_enum.cast_unsized_unchecked(|p: *mut ___ZerocopyRawEnum #ty_generics| {
core_reexport::ptr::addr_of_mut!((*p).variants)
})
};
Expand Down
4 changes: 2 additions & 2 deletions zerocopy-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ fn derive_try_from_bytes_struct(
let project = |slf: *mut Self|
::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!((*slf).#field_names);

candidate.reborrow().project(project)
candidate.reborrow().cast_unsized_unchecked(project)
};

<#field_tys as ::zerocopy::TryFromBytes>::is_bit_valid(field_candidate)
Expand Down Expand Up @@ -629,7 +629,7 @@ fn derive_try_from_bytes_union(
let project = |slf: *mut Self|
::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!((*slf).#field_names);

candidate.reborrow().project(project)
candidate.reborrow().cast_unsized_unchecked(project)
};

<#field_tys as ::zerocopy::TryFromBytes>::is_bit_valid(field_candidate)
Expand Down
Loading

0 comments on commit 9322a2c

Please sign in to comment.