diff --git a/crates/core_simd/src/masks.rs b/crates/core_simd/src/masks.rs index 1b1677330fb6..d460da0d04f8 100644 --- a/crates/core_simd/src/masks.rs +++ b/crates/core_simd/src/masks.rs @@ -16,26 +16,36 @@ use crate::simd::{LaneCount, Simd, SimdElement, SupportedLaneCount}; use core::cmp::Ordering; use core::fmt; -/// Marker trait for types that may be used as SIMD mask elements. -pub unsafe trait MaskElement: SimdElement { - #[doc(hidden)] - fn valid(values: Simd) -> bool - where - LaneCount: SupportedLaneCount; +mod sealed { + use super::*; - #[doc(hidden)] - fn eq(self, other: Self) -> bool; + /// Not only does this seal the `MaskElement` trait, but these functions prevent other traits + /// from bleeding into the parent bounds. + /// + /// For example, `eq` could be provided by requiring `MaskElement: PartialEq`, but that would + /// prevent us from ever removing that bound, or from implementing `MaskElement` on + /// non-`PartialEq` types in the future. + pub trait Sealed { + fn valid(values: Simd) -> bool + where + LaneCount: SupportedLaneCount, + Self: SimdElement; - #[doc(hidden)] - const TRUE: Self; + fn eq(self, other: Self) -> bool; - #[doc(hidden)] - const FALSE: Self; + const TRUE: Self; + + const FALSE: Self; + } } +use sealed::Sealed; + +/// Marker trait for types that may be used as SIMD mask elements. +pub unsafe trait MaskElement: SimdElement + Sealed {} macro_rules! impl_element { { $ty:ty } => { - unsafe impl MaskElement for $ty { + impl Sealed for $ty { fn valid(value: Simd) -> bool where LaneCount: SupportedLaneCount, @@ -48,6 +58,8 @@ macro_rules! impl_element { const TRUE: Self = -1; const FALSE: Self = 0; } + + unsafe impl MaskElement for $ty {} } }