@@ -175,6 +175,21 @@ pub trait Hash {
175175
176176 /// Feeds a slice of this type into the given [`Hasher`].
177177 ///
178+ /// This method is meant as a convenience, but its implementation is
179+ /// also explicitly left unspecified. It isn't guaranteed to be
180+ /// equivalent to repeated calls of [`hash`] and implementations of
181+ /// [`Hash`] should keep that in mind and call [`hash`] themselves
182+ /// if the slice isn't treated as a whole unit in the [`PartialEq`]
183+ /// implementation.
184+ ///
185+ /// For example, a [`VecDeque`] implementation might naïvely call
186+ /// [`as_slices`] and then [`hash_slice`] on each slice, but this
187+ /// is wrong since the two slices can change with a call to
188+ /// [`make_contiguous`] without affecting the [`PartialEq`]
189+ /// result. Since these slices aren't treated as singular
190+ /// units, and instead part of a larger deque, this method cannot
191+ /// be used.
192+ ///
178193 /// # Examples
179194 ///
180195 /// ```
@@ -186,6 +201,12 @@ pub trait Hash {
186201 /// Hash::hash_slice(&numbers, &mut hasher);
187202 /// println!("Hash is {:x}!", hasher.finish());
188203 /// ```
204+ ///
205+ /// [`VecDeque`]: ../../std/collections/struct.VecDeque.html
206+ /// [`as_slices`]: ../../std/collections/struct.VecDeque.html#method.as_slices
207+ /// [`make_contiguous`]: ../../std/collections/struct.VecDeque.html#method.make_contiguous
208+ /// [`hash`]: Hash::hash
209+ /// [`hash_slice`]: Hash::hash_slice
189210 #[ stable( feature = "hash_slice" , since = "1.3.0" ) ]
190211 fn hash_slice < H : Hasher > ( data : & [ Self ] , state : & mut H )
191212 where
@@ -221,6 +242,11 @@ pub use macros::Hash;
221242/// instance (with [`write`] and [`write_u8`] etc.). Most of the time, `Hasher`
222243/// instances are used in conjunction with the [`Hash`] trait.
223244///
245+ /// This trait makes no assumptions about how the various `write_*` methods are
246+ /// defined and implementations of [`Hash`] should not assume that they work one
247+ /// way or another. You cannot assume, for example, that a [`write_u32`] call is
248+ /// equivalent to four calls of [`write_u8`].
249+ ///
224250/// # Examples
225251///
226252/// ```
@@ -240,6 +266,7 @@ pub use macros::Hash;
240266/// [`finish`]: Hasher::finish
241267/// [`write`]: Hasher::write
242268/// [`write_u8`]: Hasher::write_u8
269+ /// [`write_u32`]: Hasher::write_u32
243270#[ stable( feature = "rust1" , since = "1.0.0" ) ]
244271pub trait Hasher {
245272 /// Returns the hash value for the values written so far.
0 commit comments