Skip to content

Commit 1c04856

Browse files
committed
Auto merge of #87598 - ccqpein:master, r=yaahc
Add doctests for HashMap's into_values and into_keys methods Fixes #87591
2 parents 4996735 + 6eefee1 commit 1c04856

File tree

1 file changed

+10
-2
lines changed
  • library/std/src/collections/hash

1 file changed

+10
-2
lines changed

Diff for: library/std/src/collections/hash/map.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,11 @@ where
969969
/// map.insert("b", 2);
970970
/// map.insert("c", 3);
971971
///
972-
/// let vec: Vec<&str> = map.into_keys().collect();
972+
/// let mut vec: Vec<&str> = map.into_keys().collect();
973+
/// // The `IntoKeys` iterator produces keys in arbitrary order, so the
974+
/// // keys must be sorted to test them against a sorted array.
975+
/// vec.sort_unstable();
976+
/// assert_eq!(vec, ["a", "b", "c"]);
973977
/// ```
974978
#[inline]
975979
#[stable(feature = "map_into_keys_values", since = "1.54.0")]
@@ -991,7 +995,11 @@ where
991995
/// map.insert("b", 2);
992996
/// map.insert("c", 3);
993997
///
994-
/// let vec: Vec<i32> = map.into_values().collect();
998+
/// let mut vec: Vec<i32> = map.into_values().collect();
999+
/// // The `IntoValues` iterator produces values in arbitrary order, so
1000+
/// // the values must be sorted to test them against a sorted array.
1001+
/// vec.sort_unstable();
1002+
/// assert_eq!(vec, [1, 2, 3]);
9951003
/// ```
9961004
#[inline]
9971005
#[stable(feature = "map_into_keys_values", since = "1.54.0")]

0 commit comments

Comments
 (0)