Commit 9277296
authored
Rollup merge of rust-lang#82683 - jturner314:int-div-rem-doc-panic, r=nikomatsakis
Document panicking cases for integer division and remainder
This PR documents the cases when integer division and remainder operations panic. These operations panic in two cases: division by zero and overflow.
It's surprising that these operations always panic on overflow, unlike most other arithmetic operations, which panic on overflow only when `debug_assertions` is enabled. The panic on overflow for the remainder is also surprising because a return value of `0` would be reasonable in this case. ("Overflow" occurs only for `MIN % -1`.) Since the panics on overflow are somewhat surprising, they should be documented.
I guess it's worth asking: is panic on overflow (even when `debug_assertions` is disabled) the intended behavior? If not, what's the best way forward?1 file changed
+20
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
456 | 456 | | |
457 | 457 | | |
458 | 458 | | |
459 | | - | |
| 459 | + | |
460 | 460 | | |
461 | 461 | | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
462 | 466 | | |
463 | 467 | | |
464 | 468 | | |
| |||
468 | 472 | | |
469 | 473 | | |
470 | 474 | | |
471 | | - | |
| 475 | + | |
472 | 476 | | |
473 | 477 | | |
474 | | - | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
475 | 482 | | |
476 | 483 | | |
477 | 484 | | |
| |||
549 | 556 | | |
550 | 557 | | |
551 | 558 | | |
552 | | - | |
| 559 | + | |
553 | 560 | | |
554 | 561 | | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
555 | 566 | | |
556 | 567 | | |
557 | 568 | | |
| |||
561 | 572 | | |
562 | 573 | | |
563 | 574 | | |
564 | | - | |
| 575 | + | |
565 | 576 | | |
566 | 577 | | |
567 | | - | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
568 | 582 | | |
569 | 583 | | |
570 | 584 | | |
| |||
0 commit comments