Skip to content

Commit 3e9d7e8

Browse files
authored
Add a comment explaining the two checks
1 parent 3ad154f commit 3e9d7e8

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/librustc_mir/interpret/validity.rs

+1
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
303303
let (lo, hi) = layout.valid_range.clone().into_inner();
304304
let max_hi = u128::max_value() >> (128 - size.bits()); // as big as the size fits
305305
assert!(hi <= max_hi);
306+
// We could also write `(hi + 1) % (max_hi + 1) == lo` but `max_hi + 1` overflows for `u128`
306307
if (lo == 0 && hi == max_hi) || (hi + 1 == lo) {
307308
// Nothing to check
308309
return Ok(());

0 commit comments

Comments
 (0)