diff options
| author | bors <bors@rust-lang.org> | 2021-06-16 22:48:31 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-06-16 22:48:31 +0000 |
| commit | 444a85ac38d6dcd361c66c4db097efd0fd9b9472 (patch) | |
| tree | fa217f11406001f674d75850358ce50706e27ce6 /library/core/src/array | |
| parent | a85f584aebd9b08314bf30b9adc17b4a752143e5 (diff) | |
| parent | 27d5426bcfd430a0f1ca6b42cdfe6b92e16266e9 (diff) | |
| download | rust-444a85ac38d6dcd361c66c4db097efd0fd9b9472.tar.gz rust-444a85ac38d6dcd361c66c4db097efd0fd9b9472.zip | |
Auto merge of #86379 - JohnTitor:rollup-mkz9x36, r=JohnTitor
Rollup of 10 pull requests Successful merges: - #85870 (Allow whitespace in dump_mir filter) - #86104 (Fix span calculation in format strings) - #86140 (Mention the `Borrow` guarantee on the `Hash` implementations for Arrays and `Vec`) - #86141 (Link reference in `dyn` keyword documentation) - #86260 (Open trait implementations' toggles by default.) - #86339 (Mention #79078 on compatibility notes of 1.52) - #86341 (Stop returning a value from `report_assert_as_lint`) - #86353 (Remove `projection_ty_from_predicates`) - #86361 (Add missing backslashes to prevent unwanted newlines in rustdoc HTML) - #86372 (Typo correction: s/is/its) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/core/src/array')
| -rw-r--r-- | library/core/src/array/mod.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index 37af3557fdd..f44e22b3dbd 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -139,6 +139,23 @@ impl<'a, T, const N: usize> TryFrom<&'a mut [T]> for &'a mut [T; N] { } } +/// The hash of an array is the same as that of the corresponding slice, +/// as required by the `Borrow` implementation. +/// +/// ``` +/// use std::hash::{BuildHasher, Hash, Hasher}; +/// +/// fn hash_of(x: impl Hash, b: &impl BuildHasher) -> u64 { +/// let mut h = b.build_hasher(); +/// x.hash(&mut h); +/// h.finish() +/// } +/// +/// let b = std::collections::hash_map::RandomState::new(); +/// let a: [u8; 3] = [0xa8, 0x3c, 0x09]; +/// let s: &[u8] = &[0xa8, 0x3c, 0x09]; +/// assert_eq!(hash_of(a, &b), hash_of(s, &b)); +/// ``` #[stable(feature = "rust1", since = "1.0.0")] impl<T: Hash, const N: usize> Hash for [T; N] { fn hash<H: hash::Hasher>(&self, state: &mut H) { |
