Skip to content

Commit 0d7c32c

Browse files
authored
[pointer] Replace project with cast_unsized_unchecked (#2405)
gherrit-pr-id: Id0bf66cfb1c6359fe0dffe40c9a44dbaca7ebc12
1 parent dccbbcd commit 0d7c32c

File tree

4 files changed

+42
-74
lines changed

4 files changed

+42
-74
lines changed

src/pointer/ptr.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,38 +1164,6 @@ mod _casts {
11641164
mod _project {
11651165
use super::*;
11661166

1167-
impl<'a, T, I> Ptr<'a, T, I>
1168-
where
1169-
T: 'a + ?Sized,
1170-
I: Invariants<Validity = Initialized>,
1171-
{
1172-
/// Projects a field from `self`.
1173-
///
1174-
/// # Safety
1175-
///
1176-
/// `project` has the same safety preconditions as
1177-
/// `cast_unsized_unchecked`.
1178-
#[doc(hidden)]
1179-
#[inline]
1180-
pub unsafe fn project<U: 'a + ?Sized>(
1181-
self,
1182-
projector: impl FnOnce(*mut T) -> *mut U,
1183-
) -> Ptr<'a, U, (I::Aliasing, Unaligned, Initialized)> {
1184-
// TODO(#1122): If `cast_unsized` were able to reason that, when
1185-
// casting from an `Initialized` pointer, the result is another
1186-
// `Initialized` pointer, we could remove this method entirely.
1187-
1188-
// SAFETY: This method has the same safety preconditions as
1189-
// `cast_unsized_unchecked`.
1190-
let ptr = unsafe { self.cast_unsized_unchecked(projector) };
1191-
1192-
// SAFETY: If all of the bytes of `self` are initialized (as
1193-
// promised by `I: Invariants<Validity = Initialized>`), then any
1194-
// subset of those bytes are also all initialized.
1195-
unsafe { ptr.assume_validity::<Initialized>() }
1196-
}
1197-
}
1198-
11991167
impl<'a, T, I> Ptr<'a, [T], I>
12001168
where
12011169
T: 'a,

zerocopy-derive/src/enum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ pub(crate) fn derive_is_bit_valid(
361361
// subfield pointer just points to a smaller portion of the
362362
// overall struct.
363363
let variants = unsafe {
364-
raw_enum.project(|p: *mut ___ZerocopyRawEnum #ty_generics| {
364+
raw_enum.cast_unsized_unchecked(|p: *mut ___ZerocopyRawEnum #ty_generics| {
365365
core_reexport::ptr::addr_of_mut!((*p).variants)
366366
})
367367
};

zerocopy-derive/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ fn derive_try_from_bytes_struct(
665665
let project = |slf: *mut Self|
666666
::zerocopy::util::macro_util::core_reexport::ptr::addr_of_mut!((*slf).#field_names);
667667

668-
candidate.reborrow().project(project)
668+
candidate.reborrow().cast_unsized_unchecked(project)
669669
};
670670

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

726-
candidate.reborrow().project(project)
726+
candidate.reborrow().cast_unsized_unchecked(project)
727727
};
728728

729729
<#field_tys as ::zerocopy::TryFromBytes>::is_bit_valid(field_candidate)

0 commit comments

Comments
 (0)