Skip to content

Commit 27e85da

Browse files
lcnrnovacrazy
authored andcommitted
reduce needed recursion limit
1 parent 35bedae commit 27e85da

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,13 @@ impl<T: Copy, U: Copy> Copy for GenericArrayImplOdd<T, U> {}
396396
impl<T, U> Sealed for GenericArrayImplEven<T, U> {}
397397
impl<T, U> Sealed for GenericArrayImplOdd<T, U> {}
398398

399-
// 1 << (size_of::<usize>() << 3) == usize::MAX + 1
400-
type MaxArrayLengthP1 = typenum::Shleft<
401-
typenum::U1,
402-
typenum::Shleft<typenum::U<{ mem::size_of::<usize>() }>, typenum::U3>,
403-
>;
399+
// (256 ^ size_of::<usize>()) == usize::MAX + 1
400+
//
401+
// We've previously used `1 << (size_of::<usize>() << 3)` here. However
402+
// typenum's implementation of `N << M` requires a recursion depth of `log_2(N) + 2M`
403+
// causing uses of this type to hit the default recursion limit of `128`.
404+
type MaxArrayLengthP1 =
405+
<typenum::U256 as typenum::Pow<typenum::U<{ mem::size_of::<usize>() }>>>::Output;
404406

405407
/// Helper trait to hide the complex bound under a simpler name
406408
trait IsWithinUsizeBound: typenum::IsLess<MaxArrayLengthP1, Output = typenum::consts::True> {}

0 commit comments

Comments
 (0)