Skip to content

Commit a747328

Browse files
committed
Add "Logic errors" as behavior not considered unsafe
In rust-lang/rust#80657 and rust-lang/rust#80681 it is discussed how to clarify/define what a "logic error" is and what are their consequences. The reference should mention them as well. Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 22c804a commit a747328

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/behavior-not-considered-unsafe.md

+17
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,21 @@ semantics.
3636
See [RFC 560] for error conditions, rationale, and more details about
3737
integer overflow.
3838

39+
##### Logic errors
40+
41+
Safe code may impose extra logical constraints that can be checked
42+
at neither compile-time nor runtime. If a program breaks such
43+
a constraint, the behavior may be unspecified but will not result in
44+
undefined behavior. This could include panics, incorrect results,
45+
aborts, and non-termination. The behavior may also differ between
46+
runs, builds, or kinds of build.
47+
48+
For example, implementing both `Hash` and `Eq` requires that values
49+
considered equal have equal hashes. Another example are data structures
50+
like `BinaryHeap`, `BTreeMap`, `BTreeSet`, `HashMap` and `HashSet`
51+
which describe constraints on the modification of their keys while
52+
they are in the data structure. Violating such constraints is not
53+
considered unsafe, yet the program is considered erroneous and
54+
its behavior unpredictable.
55+
3956
[RFC 560]: https://github.com/rust-lang/rfcs/blob/master/text/0560-integer-overflow.md

0 commit comments

Comments
 (0)