@@ -16,26 +16,36 @@ use crate::simd::{LaneCount, Simd, SimdElement, SupportedLaneCount};
16
16
use core:: cmp:: Ordering ;
17
17
use core:: fmt;
18
18
19
- /// Marker trait for types that may be used as SIMD mask elements.
20
- pub unsafe trait MaskElement : SimdElement {
21
- #[ doc( hidden) ]
22
- fn valid < const LANES : usize > ( values : Simd < Self , LANES > ) -> bool
23
- where
24
- LaneCount < LANES > : SupportedLaneCount ;
19
+ mod sealed {
20
+ use super :: * ;
21
+
22
+ /// Not only does this seal the `MaskElement` trait, but these functions prevent other traits
23
+ /// from bleeding into the parent bounds.
24
+ ///
25
+ /// For example, `eq` could be provided by requiring `MaskElement: PartialEq`, but that would
26
+ /// prevent us from ever removing that bound, or from implementing `MaskElement` on
27
+ /// non-`PartialEq` types in the future.
28
+ pub trait Sealed {
29
+ fn valid < const LANES : usize > ( values : Simd < Self , LANES > ) -> bool
30
+ where
31
+ LaneCount < LANES > : SupportedLaneCount ,
32
+ Self : SimdElement ;
25
33
26
- #[ doc( hidden) ]
27
- fn eq ( self , other : Self ) -> bool ;
34
+ fn eq ( self , other : Self ) -> bool ;
28
35
29
- #[ doc( hidden) ]
30
- const TRUE : Self ;
36
+ const TRUE : Self ;
31
37
32
- # [ doc ( hidden ) ]
33
- const FALSE : Self ;
38
+ const FALSE : Self ;
39
+ }
34
40
}
41
+ use sealed:: Sealed ;
42
+
43
+ /// Marker trait for types that may be used as SIMD mask elements.
44
+ pub unsafe trait MaskElement : SimdElement + Sealed { }
35
45
36
46
macro_rules! impl_element {
37
47
{ $ty: ty } => {
38
- unsafe impl MaskElement for $ty {
48
+ impl Sealed for $ty {
39
49
fn valid<const LANES : usize >( value: Simd <Self , LANES >) -> bool
40
50
where
41
51
LaneCount <LANES >: SupportedLaneCount ,
@@ -48,6 +58,8 @@ macro_rules! impl_element {
48
58
const TRUE : Self = -1 ;
49
59
const FALSE : Self = 0 ;
50
60
}
61
+
62
+ unsafe impl MaskElement for $ty { }
51
63
}
52
64
}
53
65
0 commit comments