@@ -105,29 +105,13 @@ macro_rules! array_ref {
105
105
macro_rules! array_refs {
106
106
( $arr: expr, $( $pre: expr ) ,* ; .. ; $( $post: expr ) ,* ) => { {
107
107
{
108
- /// A hokey struct to avoid theoretical overflow, which is only used
109
- /// at compile time, so efficiency of the overflow checks are not of
110
- /// concern.
111
- struct SaturatingUsize ( usize ) ;
112
- impl SaturatingUsize {
113
- // It is only used at compile time, so gets incorrectly
114
- // triggered as "dead code".
115
- #[ allow( dead_code) ]
116
- const fn add( self , rhs: usize ) -> Self {
117
- if let Some ( v) = self . 0 . checked_add( rhs) {
118
- SaturatingUsize ( v)
119
- } else {
120
- SaturatingUsize ( usize :: MAX )
121
- }
122
- }
123
- }
124
-
125
108
use core:: slice;
126
109
#[ inline]
127
110
#[ allow( unused_assignments) ]
128
111
#[ allow( clippy:: eval_order_dependence) ]
129
112
unsafe fn as_arrays<T >( a: & [ T ] ) -> ( $( & [ T ; $pre] , ) * & [ T ] , $( & [ T ; $post] , ) * ) {
130
- const MIN_LEN : usize = SaturatingUsize ( 0 ) $( . add( $pre) ) * $( . add( $post) ) * . 0 ;
113
+ const MIN_LEN : usize = 0usize $( . saturating_add( $pre) ) * $( . saturating_add( $post) ) * ;
114
+ assert!( MIN_LEN < usize :: MAX , "Your arrays are too big, are you trying to hack yourself?!" ) ;
131
115
let var_len = a. len( ) - MIN_LEN ;
132
116
assert!( a. len( ) >= MIN_LEN ) ;
133
117
let mut p = a. as_ptr( ) ;
@@ -218,29 +202,13 @@ macro_rules! array_refs {
218
202
macro_rules! mut_array_refs {
219
203
( $arr: expr, $( $pre: expr ) ,* ; .. ; $( $post: expr ) ,* ) => { {
220
204
{
221
- /// A hokey struct to avoid theoretical overflow, which is only used
222
- /// at compile time, so efficiency of the overflow checks are not of
223
- /// concern.
224
- struct SaturatingUsize ( usize ) ;
225
- impl SaturatingUsize {
226
- // It is only used at compile time, so gets incorrectly
227
- // triggered as "dead code".
228
- #[ allow( dead_code) ]
229
- const fn add( self , rhs: usize ) -> Self {
230
- if let Some ( v) = self . 0 . checked_add( rhs) {
231
- SaturatingUsize ( v)
232
- } else {
233
- SaturatingUsize ( usize :: MAX )
234
- }
235
- }
236
- }
237
-
238
205
use core:: slice;
239
206
#[ inline]
240
207
#[ allow( unused_assignments) ]
241
208
#[ allow( clippy:: eval_order_dependence) ]
242
209
unsafe fn as_arrays<T >( a: & mut [ T ] ) -> ( $( & mut [ T ; $pre] , ) * & mut [ T ] , $( & mut [ T ; $post] , ) * ) {
243
- const MIN_LEN : usize = SaturatingUsize ( 0 ) $( . add( $pre) ) * $( . add( $post) ) * . 0 ;
210
+ const MIN_LEN : usize = 0usize $( . saturating_add( $pre) ) * $( . saturating_add( $post) ) * ;
211
+ assert!( MIN_LEN < usize :: MAX , "Your arrays are too big, are you trying to hack yourself?!" ) ;
244
212
let var_len = a. len( ) - MIN_LEN ;
245
213
assert!( a. len( ) >= MIN_LEN ) ;
246
214
let mut p = a. as_mut_ptr( ) ;
0 commit comments