]> git.lizzy.rs Git - rust.git/commit - src/tools/rust-analyzer
Rollup merge of #82683 - jturner314:int-div-rem-doc-panic, r=nikomatsakis
authorDylan DPC <dylan.dpc@gmail.com>
Mon, 22 Mar 2021 14:21:24 +0000 (15:21 +0100)
committerGitHub <noreply@github.com>
Mon, 22 Mar 2021 14:21:24 +0000 (15:21 +0100)
commit83faac9da458d8f451611b4587e0c807d1db4af5
treee7cc15d9c3dd824df5c18da9ed8eb3edeebe94c3
parent7bf8f82f72599528c82ad4c29dd9408645725f6a
parentb45855032b3aad0ea0a48894f56cb9bb8fa361f2
Rollup merge of #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?