]> git.lizzy.rs Git - rust.git/commitdiff
Add a comment explaining the two checks
authorOliver S̶c̶h̶n̶e̶i̶d̶e̶r Scherer <github35764891676564198441@oli-obk.de>
Mon, 29 Oct 2018 20:31:22 +0000 (21:31 +0100)
committerGitHub <noreply@github.com>
Mon, 29 Oct 2018 20:31:22 +0000 (21:31 +0100)
src/librustc_mir/interpret/validity.rs

index 982f3dab1080d68c09691f02de8d566565a1fdb7..9d86e737dd5b6aa8acd953ce895f6f055beb1896 100644 (file)
@@ -303,6 +303,7 @@ fn validate_scalar_layout(
         let (lo, hi) = layout.valid_range.clone().into_inner();
         let max_hi = u128::max_value() >> (128 - size.bits()); // as big as the size fits
         assert!(hi <= max_hi);
+        // We could also write `(hi + 1) % (max_hi + 1) == lo` but `max_hi + 1` overflows for `u128`
         if (lo == 0 && hi == max_hi) || (hi + 1 == lo) {
             // Nothing to check
             return Ok(());