1010/// reads carry no inter-iteration data dependency — the autovectorizer treats each
1111/// lane independently.
1212pub trait IndexedSource {
13- /// The per-lane item type. Must be `Copy` so the kernels can pass it through
14- /// the closure by value without extra moves.
15- type Item : Copy ;
13+ /// The per-lane item type passed through the kernel by value.
14+ type Item ;
1615 /// Logical lane count.
1716 fn len ( & self ) -> usize ;
1817 /// Returns true when there are no lanes.
@@ -55,10 +54,10 @@ impl<T: Copy> IndexedSource for &mut [T] {
5554
5655/// Pair of two [`IndexedSource`]s of equal length. Yields `(A::Item, B::Item)` per lane.
5756///
58- /// Use this to drive a binary kernel from two columns. Length equality is enforced
59- /// at construction.
57+ /// Use this to drive a binary kernel from two columns. Length equality is enforced at
58+ /// construction, and the private fields prevent callers from bypassing that check .
6059#[ derive( Clone , Copy ) ]
61- pub struct LaneZip < A , B > ( pub A , pub B ) ;
60+ pub struct LaneZip < A , B > ( A , B ) ;
6261
6362impl < A : IndexedSource , B : IndexedSource > LaneZip < A , B > {
6463 /// Build a `LaneZip` from two equal-length sources.
@@ -80,7 +79,6 @@ impl<A: IndexedSource, B: IndexedSource> IndexedSource for LaneZip<A, B> {
8079 type Item = ( A :: Item , B :: Item ) ;
8180 #[ inline]
8281 fn len ( & self ) -> usize {
83- debug_assert_eq ! ( self . 0 . len( ) , self . 1 . len( ) ) ;
8482 self . 0 . len ( )
8583 }
8684 #[ inline]
@@ -89,3 +87,14 @@ impl<A: IndexedSource, B: IndexedSource> IndexedSource for LaneZip<A, B> {
8987 unsafe { ( self . 0 . get_unchecked ( i) , self . 1 . get_unchecked ( i) ) }
9088 }
9189}
90+
91+ #[ cfg( test) ]
92+ mod tests {
93+ use super :: LaneZip ;
94+
95+ #[ test]
96+ #[ should_panic( expected = "LaneZip operands must have the same length" ) ]
97+ fn rejects_mismatched_lengths ( ) {
98+ _ = LaneZip :: new ( & [ 1_u8 ] [ ..] , & [ 2_u8 , 3 ] [ ..] ) ;
99+ }
100+ }
0 commit comments