Skip to content

Commit 4ae7710

Browse files
Rollup merge of #77072 - sharnoff:hash-docs, r=LukasKalbertodt
Minor `hash_map` doc adjustments + item attribute orderings This PR is really a couple visual changes glued together: 1. Some of the doc comments for items in `std::collections::hash_map` referenced the names of types without escaping their formatting (e.g. using "VacantEntry" instead of "`VacantEntry`") - the ones I could find were changed to the latter 2. The vast majority of pre-item attributes seem to place doc comments as the first attribute (instead of things like `#[feature(...)]`), so the few that had the other order were changed. 3. Also ordering related: the general trend seems to be that `#[feature]` attributes follow `#[inline]`, so I swapped the two lines in places where that ordering was reversed. This is primarily a change based on stylistic continuity and aesthetics - I'm not sure how important that actually is / should be. I figured this would be pretty uncontroversial, but some of these might have been intentional for reasons I don't know about - if so, I'd be happy to remove the relevant changes. Of these, the final set of changes is probably the most unnecessary, so it also might be better to leave those out (in favor of reducing code churn).
2 parents 0d37dca + 8a011b5 commit 4ae7710

File tree

1 file changed

+20
-20
lines changed
  • library/std/src/collections/hash

1 file changed

+20
-20
lines changed

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

+20-20
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,8 @@ impl<K, V, S> HashMap<K, V, S> {
554554
/// a.clear();
555555
/// assert!(a.is_empty());
556556
/// ```
557-
#[stable(feature = "rust1", since = "1.0.0")]
558557
#[inline]
558+
#[stable(feature = "rust1", since = "1.0.0")]
559559
pub fn clear(&mut self) {
560560
self.base.clear();
561561
}
@@ -746,8 +746,8 @@ where
746746
/// assert_eq!(map.get_key_value(&1), Some((&1, &"a")));
747747
/// assert_eq!(map.get_key_value(&2), None);
748748
/// ```
749-
#[stable(feature = "map_get_key_value", since = "1.40.0")]
750749
#[inline]
750+
#[stable(feature = "map_get_key_value", since = "1.40.0")]
751751
pub fn get_key_value<Q: ?Sized>(&self, k: &Q) -> Option<(&K, &V)>
752752
where
753753
K: Borrow<Q>,
@@ -772,8 +772,8 @@ where
772772
/// assert_eq!(map.contains_key(&1), true);
773773
/// assert_eq!(map.contains_key(&2), false);
774774
/// ```
775-
#[stable(feature = "rust1", since = "1.0.0")]
776775
#[inline]
776+
#[stable(feature = "rust1", since = "1.0.0")]
777777
pub fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool
778778
where
779779
K: Borrow<Q>,
@@ -800,8 +800,8 @@ where
800800
/// }
801801
/// assert_eq!(map[&1], "b");
802802
/// ```
803-
#[stable(feature = "rust1", since = "1.0.0")]
804803
#[inline]
804+
#[stable(feature = "rust1", since = "1.0.0")]
805805
pub fn get_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut V>
806806
where
807807
K: Borrow<Q>,
@@ -834,8 +834,8 @@ where
834834
/// assert_eq!(map.insert(37, "c"), Some("b"));
835835
/// assert_eq!(map[&37], "c");
836836
/// ```
837-
#[stable(feature = "rust1", since = "1.0.0")]
838837
#[inline]
838+
#[stable(feature = "rust1", since = "1.0.0")]
839839
pub fn insert(&mut self, k: K, v: V) -> Option<V> {
840840
self.base.insert(k, v)
841841
}
@@ -857,8 +857,8 @@ where
857857
/// assert_eq!(map.remove(&1), Some("a"));
858858
/// assert_eq!(map.remove(&1), None);
859859
/// ```
860-
#[stable(feature = "rust1", since = "1.0.0")]
861860
#[inline]
861+
#[stable(feature = "rust1", since = "1.0.0")]
862862
pub fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<V>
863863
where
864864
K: Borrow<Q>,
@@ -886,8 +886,8 @@ where
886886
/// assert_eq!(map.remove(&1), None);
887887
/// # }
888888
/// ```
889-
#[stable(feature = "hash_map_remove_entry", since = "1.27.0")]
890889
#[inline]
890+
#[stable(feature = "hash_map_remove_entry", since = "1.27.0")]
891891
pub fn remove_entry<Q: ?Sized>(&mut self, k: &Q) -> Option<(K, V)>
892892
where
893893
K: Borrow<Q>,
@@ -909,8 +909,8 @@ where
909909
/// map.retain(|&k, _| k % 2 == 0);
910910
/// assert_eq!(map.len(), 4);
911911
/// ```
912-
#[stable(feature = "retain_hash_collection", since = "1.18.0")]
913912
#[inline]
913+
#[stable(feature = "retain_hash_collection", since = "1.18.0")]
914914
pub fn retain<F>(&mut self, f: F)
915915
where
916916
F: FnMut(&K, &mut V) -> bool,
@@ -1647,7 +1647,7 @@ impl<'a, K, V, S> RawOccupiedEntryMut<'a, K, V, S> {
16471647
self.base.get()
16481648
}
16491649

1650-
/// Converts the OccupiedEntry into a mutable reference to the value in the entry
1650+
/// Converts the `OccupiedEntry` into a mutable reference to the value in the entry
16511651
/// with a lifetime bound to the map itself.
16521652
#[inline]
16531653
#[unstable(feature = "hash_raw_entry", issue = "56167")]
@@ -1676,7 +1676,7 @@ impl<'a, K, V, S> RawOccupiedEntryMut<'a, K, V, S> {
16761676
self.base.get_key_value_mut()
16771677
}
16781678

1679-
/// Converts the OccupiedEntry into a mutable reference to the key and value in the entry
1679+
/// Converts the `OccupiedEntry` into a mutable reference to the key and value in the entry
16801680
/// with a lifetime bound to the map itself.
16811681
#[inline]
16821682
#[unstable(feature = "hash_raw_entry", issue = "56167")]
@@ -1714,7 +1714,7 @@ impl<'a, K, V, S> RawOccupiedEntryMut<'a, K, V, S> {
17141714
}
17151715

17161716
impl<'a, K, V, S> RawVacantEntryMut<'a, K, V, S> {
1717-
/// Sets the value of the entry with the VacantEntry's key,
1717+
/// Sets the value of the entry with the `VacantEntry`'s key,
17181718
/// and returns a mutable reference to it.
17191719
#[inline]
17201720
#[unstable(feature = "hash_raw_entry", issue = "56167")]
@@ -2173,7 +2173,6 @@ where
21732173
}
21742174

21752175
impl<'a, K, V> Entry<'a, K, V> {
2176-
#[stable(feature = "rust1", since = "1.0.0")]
21772176
/// Ensures a value is in the entry by inserting the default if empty, and returns
21782177
/// a mutable reference to the value in the entry.
21792178
///
@@ -2191,14 +2190,14 @@ impl<'a, K, V> Entry<'a, K, V> {
21912190
/// assert_eq!(map["poneyland"], 6);
21922191
/// ```
21932192
#[inline]
2193+
#[stable(feature = "rust1", since = "1.0.0")]
21942194
pub fn or_insert(self, default: V) -> &'a mut V {
21952195
match self {
21962196
Occupied(entry) => entry.into_mut(),
21972197
Vacant(entry) => entry.insert(default),
21982198
}
21992199
}
22002200

2201-
#[stable(feature = "rust1", since = "1.0.0")]
22022201
/// Ensures a value is in the entry by inserting the result of the default function if empty,
22032202
/// and returns a mutable reference to the value in the entry.
22042203
///
@@ -2215,14 +2214,14 @@ impl<'a, K, V> Entry<'a, K, V> {
22152214
/// assert_eq!(map["poneyland"], "hoho".to_string());
22162215
/// ```
22172216
#[inline]
2217+
#[stable(feature = "rust1", since = "1.0.0")]
22182218
pub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V {
22192219
match self {
22202220
Occupied(entry) => entry.into_mut(),
22212221
Vacant(entry) => entry.insert(default()),
22222222
}
22232223
}
22242224

2225-
#[unstable(feature = "or_insert_with_key", issue = "71024")]
22262225
/// Ensures a value is in the entry by inserting, if empty, the result of the default function,
22272226
/// which takes the key as its argument, and returns a mutable reference to the value in the
22282227
/// entry.
@@ -2240,6 +2239,7 @@ impl<'a, K, V> Entry<'a, K, V> {
22402239
/// assert_eq!(map["poneyland"], 9);
22412240
/// ```
22422241
#[inline]
2242+
#[unstable(feature = "or_insert_with_key", issue = "71024")]
22432243
pub fn or_insert_with_key<F: FnOnce(&K) -> V>(self, default: F) -> &'a mut V {
22442244
match self {
22452245
Occupied(entry) => entry.into_mut(),
@@ -2304,7 +2304,7 @@ impl<'a, K, V> Entry<'a, K, V> {
23042304
}
23052305
}
23062306

2307-
/// Sets the value of the entry, and returns an OccupiedEntry.
2307+
/// Sets the value of the entry, and returns an `OccupiedEntry`.
23082308
///
23092309
/// # Examples
23102310
///
@@ -2331,7 +2331,6 @@ impl<'a, K, V> Entry<'a, K, V> {
23312331
}
23322332

23332333
impl<'a, K, V: Default> Entry<'a, K, V> {
2334-
#[stable(feature = "entry_or_default", since = "1.28.0")]
23352334
/// Ensures a value is in the entry by inserting the default value if empty,
23362335
/// and returns a mutable reference to the value in the entry.
23372336
///
@@ -2348,6 +2347,7 @@ impl<'a, K, V: Default> Entry<'a, K, V> {
23482347
/// # }
23492348
/// ```
23502349
#[inline]
2350+
#[stable(feature = "entry_or_default", since = "1.28.0")]
23512351
pub fn or_default(self) -> &'a mut V {
23522352
match self {
23532353
Occupied(entry) => entry.into_mut(),
@@ -2452,7 +2452,7 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
24522452
self.base.get_mut()
24532453
}
24542454

2455-
/// Converts the OccupiedEntry into a mutable reference to the value in the entry
2455+
/// Converts the `OccupiedEntry` into a mutable reference to the value in the entry
24562456
/// with a lifetime bound to the map itself.
24572457
///
24582458
/// If you need multiple references to the `OccupiedEntry`, see [`get_mut`].
@@ -2624,7 +2624,7 @@ impl<'a, K: 'a, V: 'a> VacantEntry<'a, K, V> {
26242624
self.base.into_key()
26252625
}
26262626

2627-
/// Sets the value of the entry with the VacantEntry's key,
2627+
/// Sets the value of the entry with the `VacantEntry`'s key,
26282628
/// and returns a mutable reference to it.
26292629
///
26302630
/// # Examples
@@ -2646,8 +2646,8 @@ impl<'a, K: 'a, V: 'a> VacantEntry<'a, K, V> {
26462646
self.base.insert(value)
26472647
}
26482648

2649-
/// Sets the value of the entry with the VacantEntry's key,
2650-
/// and returns an OccupiedEntry.
2649+
/// Sets the value of the entry with the `VacantEntry`'s key,
2650+
/// and returns an `OccupiedEntry`.
26512651
///
26522652
/// # Examples
26532653
///

0 commit comments

Comments
 (0)