Skip to content

Commit 2c3a8cf

Browse files
authored
Rollup merge of #97611 - azdavis:master, r=Dylan-DPC
Tweak insert docs For `{Hash, BTree}Map::insert`, I always have to take a few extra seconds to think about the slight weirdness about the fact that if we "did not" insert (which "sounds" false), we return true, and if we "did" insert, (which "sounds" true), we return false. This tweaks the doc comments for the `insert` methods of those types (as well as what looks like a rustc internal data structure that I found just by searching the codebase for "If the set did") to first use the "Returns whether _something_" pattern used in e.g. `remove`, where we say that `remove` "returns whether the value was present".
2 parents a7bd0d0 + b02146a commit 2c3a8cf

File tree

3 files changed

+13
-7
lines changed
  • compiler/rustc_data_structures/src/sso
  • library
    • alloc/src/collections/btree
    • std/src/collections/hash

3 files changed

+13
-7
lines changed

compiler/rustc_data_structures/src/sso/set.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,10 @@ impl<T: Eq + Hash> SsoHashSet<T> {
126126

127127
/// Adds a value to the set.
128128
///
129-
/// If the set did not have this value present, `true` is returned.
129+
/// Returns whether the value was newly inserted. That is:
130130
///
131-
/// If the set did have this value present, `false` is returned.
131+
/// - If the set did not previously contain this value, `true` is returned.
132+
/// - If the set already contained this value, `false` is returned.
132133
#[inline]
133134
pub fn insert(&mut self, elem: T) -> bool {
134135
self.map.insert(elem, ()).is_none()

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -770,10 +770,14 @@ impl<T> BTreeSet<T> {
770770

771771
/// Adds a value to the set.
772772
///
773-
/// If the set did not have an equal element present, `true` is returned.
773+
/// Returns whether the value was newly inserted. That is:
774774
///
775-
/// If the set did have an equal element present, `false` is returned, and
776-
/// the entry is not updated. See the [module-level documentation] for more.
775+
/// - If the set did not previously contain an equal value, `true` is
776+
/// returned.
777+
/// - If the set already contained an equal value, `false` is returned, and
778+
/// the entry is not updated.
779+
///
780+
/// See the [module-level documentation] for more.
777781
///
778782
/// [module-level documentation]: index.html#insert-and-complex-keys
779783
///

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -858,9 +858,10 @@ where
858858

859859
/// Adds a value to the set.
860860
///
861-
/// If the set did not have this value present, `true` is returned.
861+
/// Returns whether the value was newly inserted. That is:
862862
///
863-
/// If the set did have this value present, `false` is returned.
863+
/// - If the set did not previously contain this value, `true` is returned.
864+
/// - If the set already contained this value, `false` is returned.
864865
///
865866
/// # Examples
866867
///

0 commit comments

Comments
 (0)