Skip to content

Commit 70e5ef4

Browse files
authored
Use #[marker] on nightly in CI (#1925)
We eventually hope to make use of `#[marker]` traits once they're stable. This permits us to test to make sure the feature is as we expect and that our intended usage works. gherrit-pr-id: I3a111bf5647fdcc9805cbadf36f729ac69b28509
1 parent f04c344 commit 70e5ef4

File tree

6 files changed

+34
-34
lines changed

6 files changed

+34
-34
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@
307307
#![cfg_attr(doc_cfg, feature(doc_cfg))]
308308
#![cfg_attr(
309309
__ZEROCOPY_INTERNAL_USE_ONLY_NIGHTLY_FEATURES_IN_TESTS,
310-
feature(layout_for_ptr, strict_provenance, coverage_attribute)
310+
feature(layout_for_ptr, strict_provenance, coverage_attribute, marker_trait_attr)
311311
)]
312312

313313
// This is a hack to allow zerocopy-derive derives to work in this crate. They

src/pointer/invariant.rs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -210,27 +210,27 @@ impl Validity for Valid {
210210
///
211211
/// As a consequence, if `T: Read<A, R>`, then any `Ptr<T, (A, ...)>` is
212212
/// permitted to perform unsynchronized reads from its referent.
213-
pub trait Read<A: Aliasing, R: ReadReason> {}
213+
#[cfg_attr(__ZEROCOPY_INTERNAL_USE_ONLY_NIGHTLY_FEATURES_IN_TESTS, marker)]
214+
pub unsafe trait Read<A: Aliasing, R> {}
214215

215-
impl<A: Reference, T: ?Sized + crate::Immutable> Read<A, BecauseImmutable> for T {}
216-
impl<T: ?Sized> Read<Exclusive, BecauseExclusive> for T {}
217-
218-
/// Used to disambiguate [`Read`] impls.
219-
pub trait ReadReason: Sealed {}
220-
221-
/// Unsynchronized reads are permitted because only one live [`Ptr`](crate::Ptr)
222-
/// or reference may exist to the referent bytes at a time.
223-
#[derive(Copy, Clone, Debug)]
224-
#[doc(hidden)]
225-
pub enum BecauseExclusive {}
226-
impl ReadReason for BecauseExclusive {}
227-
228-
/// Unsynchronized reads are permitted because no live [`Ptr`](crate::Ptr)s or
229-
/// references permit interior mutation.
230-
#[derive(Copy, Clone, Debug)]
231-
#[doc(hidden)]
232-
pub enum BecauseImmutable {}
233-
impl ReadReason for BecauseImmutable {}
216+
define_because!(
217+
/// Unsynchronized reads are permitted because only one live
218+
/// [`Ptr`](crate::Ptr) or reference may exist to the referent bytes at a
219+
/// time.
220+
#[doc(hidden)]
221+
pub BecauseExclusive
222+
);
223+
// SAFETY: The aliasing parameter is `Exclusive`.
224+
unsafe impl<T: ?Sized> Read<Exclusive, BecauseExclusive> for T {}
225+
226+
define_because!(
227+
/// Unsynchronized reads are permitted because no live [`Ptr`](crate::Ptr)s
228+
/// or references permit interior mutation.
229+
#[doc(hidden)]
230+
pub BecauseImmutable
231+
);
232+
// SAFETY: `T: Immutable`.
233+
unsafe impl<A: Reference, T: ?Sized + crate::Immutable> Read<A, BecauseImmutable> for T {}
234234

235235
use sealed::Sealed;
236236
mod sealed {
@@ -251,9 +251,6 @@ mod sealed {
251251
impl Sealed for Valid {}
252252

253253
impl<A: Sealed, AA: Sealed, V: Sealed> Sealed for (A, AA, V) {}
254-
255-
impl Sealed for BecauseImmutable {}
256-
impl Sealed for BecauseExclusive {}
257254
}
258255

259256
pub use mapping::*;

src/pointer/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub mod invariant;
1414
mod ptr;
1515

1616
#[doc(hidden)]
17-
pub use invariant::{BecauseExclusive, BecauseImmutable, Read, ReadReason};
17+
pub use invariant::{BecauseExclusive, BecauseImmutable, Read};
1818
#[doc(hidden)]
1919
pub use ptr::Ptr;
2020

@@ -48,7 +48,6 @@ where
4848
pub fn read_unaligned<R>(self) -> T
4949
where
5050
T: Copy,
51-
R: invariant::ReadReason,
5251
T: invariant::Read<Aliasing, R>,
5352
{
5453
// SAFETY: By invariant on `MaybeAligned`, `raw` contains

src/pointer/ptr.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,6 @@ mod _transitions {
658658
T: TryFromBytes + Read<I::Aliasing, R>,
659659
I::Aliasing: Reference,
660660
I: Invariants<Validity = Initialized>,
661-
R: crate::pointer::ReadReason,
662661
{
663662
// This call may panic. If that happens, it doesn't cause any soundness
664663
// issues, as we have not generated any invalid state which we need to
@@ -805,8 +804,6 @@ mod _casts {
805804
where
806805
T: Read<I::Aliasing, R>,
807806
U: 'a + ?Sized + Read<I::Aliasing, S>,
808-
R: ReadReason,
809-
S: ReadReason,
810807
F: FnOnce(*mut T) -> *mut U,
811808
{
812809
// SAFETY: Because `T` and `U` both implement `Read<I::Aliasing, _>`,
@@ -829,7 +826,6 @@ mod _casts {
829826
#[allow(clippy::wrong_self_convention)]
830827
pub(crate) fn as_bytes<R>(self) -> Ptr<'a, [u8], (I::Aliasing, Aligned, Valid)>
831828
where
832-
R: ReadReason,
833829
T: Read<I::Aliasing, R>,
834830
I::Aliasing: Reference,
835831
{
@@ -919,7 +915,6 @@ mod _casts {
919915
CastError<Self, U>,
920916
>
921917
where
922-
R: ReadReason,
923918
I::Aliasing: Reference,
924919
U: 'a + ?Sized + KnownLayout + Read<I::Aliasing, R>,
925920
{
@@ -983,7 +978,6 @@ mod _casts {
983978
where
984979
I::Aliasing: Reference,
985980
U: 'a + ?Sized + KnownLayout + Read<I::Aliasing, R>,
986-
R: ReadReason,
987981
{
988982
match self.try_cast_into(CastType::Prefix, meta) {
989983
Ok((slf, remainder)) => {

src/util/macro_util.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use core::mem::{self, ManuallyDrop};
2525
use core::ptr::{self, NonNull};
2626

2727
use crate::{
28-
pointer::invariant::{self, BecauseExclusive, BecauseImmutable, Invariants, ReadReason},
28+
pointer::invariant::{self, BecauseExclusive, BecauseImmutable, Invariants},
2929
Immutable, IntoBytes, Ptr, TryFromBytes, Unalign, ValidityError,
3030
};
3131

@@ -528,7 +528,6 @@ where
528528
Dst: TryFromBytes + invariant::Read<I::Aliasing, R>,
529529
I: Invariants<Validity = invariant::Valid>,
530530
I::Aliasing: invariant::Reference,
531-
R: ReadReason,
532531
{
533532
static_assert!(Src, Dst => mem::size_of::<Dst>() == mem::size_of::<Src>());
534533

src/util/macros.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,3 +655,14 @@ macro_rules! static_assert_dst_is_not_zst {
655655
}, "cannot call this method on a dynamically-sized type whose trailing slice element is zero-sized");
656656
}}
657657
}
658+
659+
macro_rules! define_because {
660+
($(#[$attr:meta])* $vis:vis $name:ident) => {
661+
#[cfg(__ZEROCOPY_INTERNAL_USE_ONLY_NIGHTLY_FEATURES_IN_TESTS)]
662+
$(#[$attr])*
663+
$vis type $name = ();
664+
#[cfg(not(__ZEROCOPY_INTERNAL_USE_ONLY_NIGHTLY_FEATURES_IN_TESTS))]
665+
$(#[$attr])*
666+
$vis enum $name {}
667+
};
668+
}

0 commit comments

Comments
 (0)