Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/coding-guidelines/expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,43 @@ Expressions
}

fn with_base(_: &Base) { ... }

.. guideline:: Do not divide by 0
:id: gui_kMbiWbn8Z6g5
:category: Mandatory
:status: draft
:release: latest
:fls: fls_Q9dhNiICGIfr
:decidability: Undecidable
:scope: System
:tags: numerics

This guideline applies when unsigned integer or two’s complement division is performed. This includes the
evaluation of a remainder expression.

.. rationale::
:id: rat_h84NjY2tLSBW
:status: draft

Integer division by zero results in a panic, which is an abnormal program state and may terminate the process.

.. non_compliant_example::
:id: non_compl_ex_LLs3vY8aGz0F
:status: draft

When the division is performed, the right operand is evaluated to zero and the program panics.

.. code-block:: rust

let x = 0;
let x = 5 / x;

.. compliant_example::
:id: compl_ex_Ri9pP5Ch3kbb
:status: draft

There is no compliant way to perform integer division by zero

.. code-block:: rust

let x = 5 % 5;