From 781e43962f78dd879a0876b680e630c28426ef36 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Wed, 6 Jan 2021 08:02:20 +0100 Subject: [PATCH] Add "Logic errors" as behavior not considered unsafe In https://github.com/rust-lang/rust/issues/80657 and https://github.com/rust-lang/rust/pull/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 --- src/behavior-not-considered-unsafe.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/behavior-not-considered-unsafe.md b/src/behavior-not-considered-unsafe.md index 20f3cad5f..4128d7f23 100644 --- a/src/behavior-not-considered-unsafe.md +++ b/src/behavior-not-considered-unsafe.md @@ -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