Skip to content

Commit 478bffb

Browse files
committed
Miri/CTFE: properly treat overflow in (signed) division/rem as UB
1 parent f701e0d commit 478bffb

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

core/tests/num/wrapping.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,13 @@ fn wrapping_int_api() {
308308
}
309309
}
310310
}
311+
312+
#[test]
313+
fn wrapping_const() {
314+
// Specifically the wrapping behavior of division and remainder is subtle,
315+
// see https://github.com/rust-lang/rust/pull/94512.
316+
const _: () = {
317+
assert!(i32::MIN.wrapping_div(-1) == i32::MIN);
318+
assert!(i32::MIN.wrapping_rem(-1) == 0);
319+
};
320+
}

0 commit comments

Comments
 (0)