Skip to content

Commit

Permalink
Add "Logic errors" as behavior not considered unsafe
Browse files Browse the repository at this point in the history
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 <ojeda@kernel.org>
  • Loading branch information
ojeda authored and wsh committed Jan 17, 2021
1 parent ac05998 commit 781e439
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/behavior-not-considered-unsafe.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,21 @@ semantics.
See [RFC 560] for error conditions, rationale, and more details about
integer overflow.

##### Logic errors

Safe code may impose extra logical constraints that can be checked
at neither compile-time nor runtime. If a program breaks such
a constraint, the behavior may be unspecified but will not result in
undefined behavior. This could include panics, incorrect results,
aborts, and non-termination. The behavior may also differ between
runs, builds, or kinds of build.

For example, implementing both `Hash` and `Eq` requires that values
considered equal have equal hashes. Another example are data structures
like `BinaryHeap`, `BTreeMap`, `BTreeSet`, `HashMap` and `HashSet`
which describe constraints on the modification of their keys while
they are in the data structure. Violating such constraints is not
considered unsafe, yet the program is considered erroneous and
its behavior unpredictable.

[RFC 560]: https://github.com/rust-lang/rfcs/blob/master/text/0560-integer-overflow.md

0 comments on commit 781e439

Please sign in to comment.