소스 검색

Make sequences wrap around to avoid overflows

Instead of aborting with an `attempt to add with overflow` error, wrap the sequence around so that it goes back to 0 once it has reached the maximum value for the integer type.  Fixes #437.
Adam Nielsen 4 년 전
부모
커밋
036f1f7cec
1개의 변경된 파일1개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      core/src/util/mod.rs

+ 1 - 1
core/src/util/mod.rs

@@ -38,7 +38,7 @@ pub trait Seq {
 macro_rules! impl_seq {
     ($($ty:ty)*) => { $(
         impl Seq for $ty {
-            fn next(&self) -> Self { *self + 1 }
+            fn next(&self) -> Self { (*self).wrapping_add(1) }
         }
     )* }
 }