You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/coding-guidelines/expressions.rst
+6-7Lines changed: 6 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,6 @@
6
6
Expressions
7
7
===========
8
8
9
-
10
9
.. guideline:: Avoid as underscore pointer casts
11
10
:id: gui_HDnAZ7EZ4z6G
12
11
:category: required
@@ -96,7 +95,7 @@ Expressions
96
95
`integer type <https://rust-lang.github.io/fls/types-and-traits.html#integer-types>`_
97
96
during a `division expression
98
97
<https://rust-lang.github.io/fls/expressions.html#syntax_divisionexpression>`_ or `remainder expression
99
-
<https://rust-lang.github.io/fls/expressions.html#syntax_remainderexpression>`_ is when the left operand also has integer type.
98
+
<https://rust-lang.github.io/fls/expressions.html#syntax_remainderexpression>`_ when the left operand also has integer type.
100
99
101
100
This rule applies to the following primitive integer types:
102
101
@@ -162,9 +161,10 @@ Expressions
162
161
This compliant solution creates a divisor using :std:`std::num::NonZero`.
163
162
:std:`std::num::NonZero` is a wrapper around primitive integer types that guarantees the contained value is never zero.
164
163
:std:`std::num::NonZero::new` creates a new binding that represents a value that is known not to be zero.
165
-
This in turn ensures that functions operating on its value can safely assume that they are not being given zero as their input.
164
+
This ensures that functions operating on its value can correctly assume that they are not being given zero as their input.
166
165
167
-
Note that the test for arithmetic overflow in this compliant example (which is a possibility for non-zero negative divisors, namely, ``-1``) is unnecessary because ``divisor`` is an unsigned integer type.
166
+
Note that the test for arithmetic overflow that occurs when dividing the minimum representable value by -1 is unnecessary
167
+
in this compliant example because the result of the division expression is an unsigned integer type.
168
168
169
169
.. code-block:: rust
170
170
@@ -191,7 +191,7 @@ Expressions
191
191
Division and remainder expressions on signed integers are also susceptible to arithmetic overflow.
192
192
Overflow is covered in full by the guideline `Ensure that integer operations do not result in arithmetic overflow`.
193
193
194
-
This rule applies to the following primitive integer types:
194
+
This rule applies to the following primitive integer types:
195
195
196
196
* ``i8``
197
197
* ``i16``
@@ -209,7 +209,6 @@ Expressions
209
209
This rule does not apply to evaluation of the :std:`core::ops::Div` trait on types other than `integer
0 commit comments