From bd66f57e469b89a0b8ffbe273cac26c02cdf9874 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 28 Mar 2015 10:49:45 -0700 Subject: [PATCH 1/5] libc: Don't use unstable apis Right now the `std::isize::BYTES` typedef is `#[unstable]`, but liblibc is using this, preventing it from compiling on stable Rust. --- src/liblibc/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs index 7174b2d2c29..b7162c4a177 100644 --- a/src/liblibc/lib.rs +++ b/src/liblibc/lib.rs @@ -307,7 +307,10 @@ pub mod types { #[derive(Copy)] pub struct sockaddr_storage { pub ss_family: sa_family_t, pub __ss_align: isize, - pub __ss_pad2: [u8; 128 - 2 * (::core::isize::BYTES as usize)], + #[cfg(target_pointer_width = "32")] + pub __ss_pad2: [u8; 128 - 2 * 4], + #[cfg(target_pointer_width = "64")] + pub __ss_pad2: [u8; 128 - 2 * 8], } #[repr(C)] #[derive(Copy)] pub struct sockaddr_in { From f6c234fb45327c3e96b4fe8902dd7416e0f61dde Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Sat, 28 Mar 2015 16:06:37 -0400 Subject: [PATCH 2/5] Document properties for Eq + Hash Fixes #23320 --- src/libcore/hash/mod.rs | 10 ++++++++++ src/libstd/collections/hash/map.rs | 9 ++++++++- src/libstd/collections/hash/set.rs | 11 ++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/libcore/hash/mod.rs b/src/libcore/hash/mod.rs index 2feb2f8b1e3..2375ae89650 100644 --- a/src/libcore/hash/mod.rs +++ b/src/libcore/hash/mod.rs @@ -73,6 +73,16 @@ mod sip; /// /// The `H` type parameter is an abstract hash state that is used by the `Hash` /// to compute the hash. +/// +/// If you are also implementing `Eq`, there is an additional property that +/// is important: +/// +/// ```text +/// k1 == k2 -> hash(k1) == hash(k2) +/// ``` +/// +/// In other words, if two keys are equal, their hashes should also be equal. +/// `HashMap` and `HashSet` both rely on this behavior. #[stable(feature = "rust1", since = "1.0.0")] pub trait Hash { /// Feeds this value into the state given, updating the hasher as necessary. diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 91225891338..30ccb05cdf0 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -214,7 +214,14 @@ fn test_resize_policy() { /// overridden with one of the constructors. /// /// It is required that the keys implement the `Eq` and `Hash` traits, although -/// this can frequently be achieved by using `#[derive(Eq, Hash)]`. +/// this can frequently be achieved by using `#[derive(Eq, Hash)]`. If you +/// implement these yourself, it is important that the following property holds: +/// +/// ```text +/// k1 == k2 -> hash(k1) == hash(k2) +/// ``` +/// +/// In other words, if two keys are equal, their hashes must be equal. /// /// It is a logic error for a key to be modified in such a way that the key's /// hash, as determined by the `Hash` trait, or its equality, as determined by diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 0933b4f662a..9bb969c4042 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -36,7 +36,16 @@ use super::state::HashState; /// An implementation of a hash set using the underlying representation of a /// HashMap where the value is (). As with the `HashMap` type, a `HashSet` -/// requires that the elements implement the `Eq` and `Hash` traits. +/// requires that the elements implement the `Eq` and `Hash` traits. This can +/// frequently be achieved by using `#[derive(Eq, Hash)]`. If you implement +/// these yourself, it is important that the following property holds: +/// +/// ```text +/// k1 == k2 -> hash(k1) == hash(k2) +/// ``` +/// +/// In other words, if two keys are equal, their hashes must be equal. +/// /// /// It is a logic error for an item to be modified in such a way that the /// item's hash, as determined by the `Hash` trait, or its equality, as From 80c188e3c0f9a58f97e9f25733b7ce72faa13131 Mon Sep 17 00:00:00 2001 From: Phil Dawes Date: Sat, 28 Mar 2015 22:18:03 +0000 Subject: [PATCH 3/5] Correct Phil Dawes email address --- AUTHORS.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AUTHORS.txt b/AUTHORS.txt index f7934b2fa70..4109797a55e 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -606,7 +606,7 @@ Peter Schuller Peter Williams Peter Zotov Petter Remen -Phil Dawes +Phil Dawes Phil Ruffwind Philip Munksgaard Philipp Brüschweiler From 256e78a39c99f9cc7304dba61caf02e180d68c38 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Sat, 28 Mar 2015 22:06:42 -0400 Subject: [PATCH 4/5] Fix typo in docstring for slice --- src/libcollections/slice.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index ba1ab75de80..14dcd52fe80 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -50,8 +50,8 @@ //! //! ## Iteration //! -//! The slices implement `IntoIterator`. The iterators of yield references -//! to the slice elements. +//! The slices implement `IntoIterator`. The iterator yields references to the +//! slice elements. //! //! ``` //! let numbers = &[0, 1, 2]; From 58c7d6f3e1dc3c09d7362d5dffbecc8d37ad483a Mon Sep 17 00:00:00 2001 From: Huachao Huang Date: Sun, 29 Mar 2015 18:22:01 +0800 Subject: [PATCH 5/5] Fix typo --- src/doc/trpl/documentation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/documentation.md b/src/doc/trpl/documentation.md index 43b49c09ae4..a71d9d8019c 100644 --- a/src/doc/trpl/documentation.md +++ b/src/doc/trpl/documentation.md @@ -517,7 +517,7 @@ can be useful when changing some options, or when writing a macro. ### Re-exports -`rustdoc` will show the documentation for a publc re-export in both places: +`rustdoc` will show the documentation for a public re-export in both places: ```ignore extern crate foo;