Skip to content

Commit 40d2506

Browse files
authored
Rollup merge of rust-lang#80681 - ChrisJefferson:logic-error-doc, r=m-ou-se
Clarify what the effects of a 'logic error' are This clarifies what a 'logic error' is (which is a term used to describe what happens if you put things in a hash table or btree and then use something like a refcell to break the internal ordering). This tries to be as vague as possible, as we don't really want to promise what happens, except "bad things, but not UB". This was discussed in rust-lang#80657
2 parents d8843d9 + 78d9192 commit 40d2506

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed

library/alloc/src/collections/binary_heap.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ use super::SpecExtend;
161161
/// It is a logic error for an item to be modified in such a way that the
162162
/// item's ordering relative to any other item, as determined by the `Ord`
163163
/// trait, changes while it is in the heap. This is normally only possible
164-
/// through `Cell`, `RefCell`, global state, I/O, or unsafe code.
164+
/// through `Cell`, `RefCell`, global state, I/O, or unsafe code. The
165+
/// behavior resulting from such a logic error is not specified, but will
166+
/// not result in undefined behavior. This could include panics, incorrect
167+
/// results, aborts, memory leaks, and non-termination.
165168
///
166169
/// # Examples
167170
///

library/alloc/src/collections/btree/map.rs

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
5151
/// It is a logic error for a key to be modified in such a way that the key's ordering relative to
5252
/// any other key, as determined by the [`Ord`] trait, changes while it is in the map. This is
5353
/// normally only possible through [`Cell`], [`RefCell`], global state, I/O, or unsafe code.
54+
/// The behavior resulting from such a logic error is not specified, but will not result in
55+
/// undefined behavior. This could include panics, incorrect results, aborts, memory leaks, and
56+
/// non-termination.
5457
///
5558
/// [`Cell`]: core::cell::Cell
5659
/// [`RefCell`]: core::cell::RefCell

library/alloc/src/collections/btree/set.rs

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ use super::Recover;
2222
/// It is a logic error for an item to be modified in such a way that the item's ordering relative
2323
/// to any other item, as determined by the [`Ord`] trait, changes while it is in the set. This is
2424
/// normally only possible through [`Cell`], [`RefCell`], global state, I/O, or unsafe code.
25+
/// The behavior resulting from such a logic error is not specified, but will not result in
26+
/// undefined behavior. This could include panics, incorrect results, aborts, memory leaks, and
27+
/// non-termination.
2528
///
2629
/// [`Ord`]: core::cmp::Ord
2730
/// [`Cell`]: core::cell::Cell

library/std/src/collections/hash/map.rs

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ use crate::sys;
5252
/// hash, as determined by the [`Hash`] trait, or its equality, as determined by
5353
/// the [`Eq`] trait, changes while it is in the map. This is normally only
5454
/// possible through [`Cell`], [`RefCell`], global state, I/O, or unsafe code.
55+
/// The behavior resulting from such a logic error is not specified, but will
56+
/// not result in undefined behavior. This could include panics, incorrect results,
57+
/// aborts, memory leaks, and non-termination.
5558
///
5659
/// The hash table implementation is a Rust port of Google's [SwissTable].
5760
/// The original C++ version of SwissTable can be found [here], and this

library/std/src/collections/hash/set.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ use super::map::{map_try_reserve_error, RandomState};
3737
/// item's hash, as determined by the [`Hash`] trait, or its equality, as
3838
/// determined by the [`Eq`] trait, changes while it is in the set. This is
3939
/// normally only possible through [`Cell`], [`RefCell`], global state, I/O, or
40-
/// unsafe code.
40+
/// unsafe code. The behavior resulting from such a logic error is not
41+
/// specified, but will not result in undefined behavior. This could include
42+
/// panics, incorrect results, aborts, memory leaks, and non-termination.
4143
///
4244
/// # Examples
4345
///

0 commit comments

Comments
 (0)