Skip to content

Commit f4c3bc5

Browse files
authored
Merge pull request #919 from ojeda/logic-errors
Add "Logic errors" as behavior not considered unsafe
2 parents f8c39fe + a747328 commit f4c3bc5

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)