From 036f1f7cec2664310dda7140af1861ab0da1ee8d Mon Sep 17 00:00:00 2001 From: Adam Nielsen Date: Sun, 23 Feb 2020 11:27:38 +1000 Subject: [PATCH] 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. --- core/src/util/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/util/mod.rs b/core/src/util/mod.rs index 5c1e50f5..800e04e1 100644 --- a/core/src/util/mod.rs +++ b/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) } } )* } }