Skip to content

Commit 3d268fe

Browse files
committed
std: Change hash to reexport its own Writer
One of the long-term goals of the libstd facade is to move the collections library underneath the standard library. This would imply that libcollections today would invert its dependency with libstd. One of the primary blockers for doing this is the HashMap collection. Of its two major dependencies, hashing and randomness, this commit is the first step in dealing with hashing. When moving the hash module beneath libstd, it must break its primary dependence on the io::Writer trait (used as the hashing state). The proposed strategy for breaking this dependence is taking a similar path as core::fmt, which is to have the hash module define its own "writer trait". This trait would be similar to std::io::Writer, except that it would not return errors and it would have fewer convenience methods. The Hash trait today has its type parameter behind a feature gate (default type parameters), so this pending change will likely break no code which hasn't opted in to the feature gate. The SipState struct will lose its implementation of io::Writer, but it will regain similar methods for dealing with writing data. This change specifically prepares for the hash migration by modifying deriving(Hash) to use the std::hash::Writer bound instead of the std::io::Writer bound. This bound is currently wired to std::io::Writer, but after a snapshot it will have no need to be wired to the io writer trait.
1 parent e546452 commit 3d268fe

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/libstd/hash/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565

6666
use container::Container;
6767
use intrinsics::TypeId;
68-
use io::Writer;
6968
use iter::Iterator;
7069
use option::{Option, Some, None};
7170
use owned::Box;
@@ -78,6 +77,8 @@ use vec::Vec;
7877
/// Reexport the `sip::hash` function as our default hasher.
7978
pub use hash = self::sip::hash;
8079

80+
pub use Writer = io::Writer;
81+
8182
pub mod sip;
8283

8384
/// A trait that represents a hashable type. The `S` type parameter is an

src/libsyntax/ext/deriving/hash.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt,
2727
vec!(box Literal(Path::new_local("__S"))), true),
2828
LifetimeBounds {
2929
lifetimes: Vec::new(),
30-
bounds: vec!(("__S", ast::StaticSize, vec!(Path::new(vec!("std", "io", "Writer"))))),
30+
bounds: vec!(("__S", ast::StaticSize,
31+
vec!(Path::new(vec!("std", "hash", "Writer"))))),
3132
},
3233
Path::new_local("__S"))
3334
} else {

0 commit comments

Comments
 (0)