auto merge of #12522 : erickt/rust/hash, r=alexcrichton
This patch series does a couple things: * replaces manual `Hash` implementations with `#[deriving(Hash)]` * adds `Hash` back to `std::prelude` * minor cleanup of whitespace and variable names.
This commit is contained in:
commit
25d68366b7
14 changed files with 68 additions and 83 deletions
|
@ -98,7 +98,7 @@ fn resize_at(capacity: uint) -> uint {
|
||||||
(capacity * 3) / 4
|
(capacity * 3) / 4
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K:Hash + Eq,V> HashMap<K, V> {
|
impl<K:Hash + Eq, V> HashMap<K, V> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_bucket(&self, h: uint) -> uint {
|
fn to_bucket(&self, h: uint) -> uint {
|
||||||
// A good hash function with entropy spread over all of the
|
// A good hash function with entropy spread over all of the
|
||||||
|
|
|
@ -722,7 +722,7 @@ pub fn is_null(val: ValueRef) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used to identify cached monomorphized functions and vtables
|
// Used to identify cached monomorphized functions and vtables
|
||||||
#[deriving(Eq,Hash)]
|
#[deriving(Eq, Hash)]
|
||||||
pub enum mono_param_id {
|
pub enum mono_param_id {
|
||||||
mono_precise(ty::t, Option<@~[mono_id]>),
|
mono_precise(ty::t, Option<@~[mono_id]>),
|
||||||
mono_any,
|
mono_any,
|
||||||
|
@ -732,7 +732,7 @@ pub enum mono_param_id {
|
||||||
datum::RvalueMode),
|
datum::RvalueMode),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Eq,Hash)]
|
#[deriving(Eq, Hash)]
|
||||||
pub enum MonoDataClass {
|
pub enum MonoDataClass {
|
||||||
MonoBits, // Anything not treated differently from arbitrary integer data
|
MonoBits, // Anything not treated differently from arbitrary integer data
|
||||||
MonoNonNull, // Non-null pointers (used for optional-pointer optimization)
|
MonoNonNull, // Non-null pointers (used for optional-pointer optimization)
|
||||||
|
@ -754,8 +754,7 @@ pub fn mono_data_classify(t: ty::t) -> MonoDataClass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deriving(Eq, Hash)]
|
||||||
#[deriving(Eq,Hash)]
|
|
||||||
pub struct mono_id_ {
|
pub struct mono_id_ {
|
||||||
def: ast::DefId,
|
def: ast::DefId,
|
||||||
params: ~[mono_param_id]
|
params: ~[mono_param_id]
|
||||||
|
|
|
@ -150,7 +150,7 @@ pub struct field_ty {
|
||||||
|
|
||||||
// Contains information needed to resolve types and (in the future) look up
|
// Contains information needed to resolve types and (in the future) look up
|
||||||
// the types of AST nodes.
|
// the types of AST nodes.
|
||||||
#[deriving(Eq,Hash)]
|
#[deriving(Eq, Hash)]
|
||||||
pub struct creader_cache_key {
|
pub struct creader_cache_key {
|
||||||
cnum: CrateNum,
|
cnum: CrateNum,
|
||||||
pos: uint,
|
pos: uint,
|
||||||
|
@ -4926,13 +4926,11 @@ pub fn trait_method_of_method(tcx: ctxt,
|
||||||
/// Creates a hash of the type `t` which will be the same no matter what crate
|
/// Creates a hash of the type `t` which will be the same no matter what crate
|
||||||
/// context it's calculated within. This is used by the `type_id` intrinsic.
|
/// context it's calculated within. This is used by the `type_id` intrinsic.
|
||||||
pub fn hash_crate_independent(tcx: ctxt, t: t, local_hash: ~str) -> u64 {
|
pub fn hash_crate_independent(tcx: ctxt, t: t, local_hash: ~str) -> u64 {
|
||||||
use std::hash::{sip, Hash};
|
let mut state = sip::SipState::new(0, 0);
|
||||||
|
macro_rules! byte( ($b:expr) => { ($b as u8).hash(&mut state) } );
|
||||||
|
macro_rules! hash( ($e:expr) => { $e.hash(&mut state) } );
|
||||||
|
|
||||||
let mut hash = sip::SipState::new(0, 0);
|
let region = |_state: &mut sip::SipState, r: Region| {
|
||||||
macro_rules! byte( ($b:expr) => { ($b as u8).hash(&mut hash) } );
|
|
||||||
macro_rules! hash( ($e:expr) => { $e.hash(&mut hash) } );
|
|
||||||
|
|
||||||
let region = |_hash: &mut sip::SipState, r: Region| {
|
|
||||||
match r {
|
match r {
|
||||||
ReStatic => {}
|
ReStatic => {}
|
||||||
|
|
||||||
|
@ -4946,27 +4944,27 @@ pub fn hash_crate_independent(tcx: ctxt, t: t, local_hash: ~str) -> u64 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let vstore = |hash: &mut sip::SipState, v: vstore| {
|
let vstore = |state: &mut sip::SipState, v: vstore| {
|
||||||
match v {
|
match v {
|
||||||
vstore_fixed(_) => 0u8.hash(hash),
|
vstore_fixed(_) => 0u8.hash(state),
|
||||||
vstore_uniq => 1u8.hash(hash),
|
vstore_uniq => 1u8.hash(state),
|
||||||
vstore_slice(r) => {
|
vstore_slice(r) => {
|
||||||
2u8.hash(hash);
|
2u8.hash(state);
|
||||||
region(hash, r);
|
region(state, r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let did = |hash: &mut sip::SipState, did: DefId| {
|
let did = |state: &mut sip::SipState, did: DefId| {
|
||||||
let h = if ast_util::is_local(did) {
|
let h = if ast_util::is_local(did) {
|
||||||
local_hash.clone()
|
local_hash.clone()
|
||||||
} else {
|
} else {
|
||||||
tcx.sess.cstore.get_crate_hash(did.krate)
|
tcx.sess.cstore.get_crate_hash(did.krate)
|
||||||
};
|
};
|
||||||
h.as_bytes().hash(hash);
|
h.as_bytes().hash(state);
|
||||||
did.node.hash(hash);
|
did.node.hash(state);
|
||||||
};
|
};
|
||||||
let mt = |hash: &mut sip::SipState, mt: mt| {
|
let mt = |state: &mut sip::SipState, mt: mt| {
|
||||||
mt.mutbl.hash(hash);
|
mt.mutbl.hash(state);
|
||||||
};
|
};
|
||||||
ty::walk_ty(t, |t| {
|
ty::walk_ty(t, |t| {
|
||||||
match ty::get(t).sty {
|
match ty::get(t).sty {
|
||||||
|
@ -5002,17 +5000,17 @@ pub fn hash_crate_independent(tcx: ctxt, t: t, local_hash: ~str) -> u64 {
|
||||||
}
|
}
|
||||||
ty_vec(m, v) => {
|
ty_vec(m, v) => {
|
||||||
byte!(11);
|
byte!(11);
|
||||||
mt(&mut hash, m);
|
mt(&mut state, m);
|
||||||
vstore(&mut hash, v);
|
vstore(&mut state, v);
|
||||||
}
|
}
|
||||||
ty_ptr(m) => {
|
ty_ptr(m) => {
|
||||||
byte!(12);
|
byte!(12);
|
||||||
mt(&mut hash, m);
|
mt(&mut state, m);
|
||||||
}
|
}
|
||||||
ty_rptr(r, m) => {
|
ty_rptr(r, m) => {
|
||||||
byte!(13);
|
byte!(13);
|
||||||
region(&mut hash, r);
|
region(&mut state, r);
|
||||||
mt(&mut hash, m);
|
mt(&mut state, m);
|
||||||
}
|
}
|
||||||
ty_bare_fn(ref b) => {
|
ty_bare_fn(ref b) => {
|
||||||
byte!(14);
|
byte!(14);
|
||||||
|
@ -5025,16 +5023,16 @@ pub fn hash_crate_independent(tcx: ctxt, t: t, local_hash: ~str) -> u64 {
|
||||||
hash!(c.sigil);
|
hash!(c.sigil);
|
||||||
hash!(c.onceness);
|
hash!(c.onceness);
|
||||||
hash!(c.bounds);
|
hash!(c.bounds);
|
||||||
region(&mut hash, c.region);
|
region(&mut state, c.region);
|
||||||
}
|
}
|
||||||
ty_trait(d, _, store, m, bounds) => {
|
ty_trait(d, _, store, m, bounds) => {
|
||||||
byte!(17);
|
byte!(17);
|
||||||
did(&mut hash, d);
|
did(&mut state, d);
|
||||||
match store {
|
match store {
|
||||||
UniqTraitStore => byte!(0),
|
UniqTraitStore => byte!(0),
|
||||||
RegionTraitStore(r) => {
|
RegionTraitStore(r) => {
|
||||||
byte!(1)
|
byte!(1)
|
||||||
region(&mut hash, r);
|
region(&mut state, r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hash!(m);
|
hash!(m);
|
||||||
|
@ -5042,7 +5040,7 @@ pub fn hash_crate_independent(tcx: ctxt, t: t, local_hash: ~str) -> u64 {
|
||||||
}
|
}
|
||||||
ty_struct(d, _) => {
|
ty_struct(d, _) => {
|
||||||
byte!(18);
|
byte!(18);
|
||||||
did(&mut hash, d);
|
did(&mut state, d);
|
||||||
}
|
}
|
||||||
ty_tup(ref inner) => {
|
ty_tup(ref inner) => {
|
||||||
byte!(19);
|
byte!(19);
|
||||||
|
@ -5051,22 +5049,22 @@ pub fn hash_crate_independent(tcx: ctxt, t: t, local_hash: ~str) -> u64 {
|
||||||
ty_param(p) => {
|
ty_param(p) => {
|
||||||
byte!(20);
|
byte!(20);
|
||||||
hash!(p.idx);
|
hash!(p.idx);
|
||||||
did(&mut hash, p.def_id);
|
did(&mut state, p.def_id);
|
||||||
}
|
}
|
||||||
ty_self(d) => {
|
ty_self(d) => {
|
||||||
byte!(21);
|
byte!(21);
|
||||||
did(&mut hash, d);
|
did(&mut state, d);
|
||||||
}
|
}
|
||||||
ty_infer(_) => unreachable!(),
|
ty_infer(_) => unreachable!(),
|
||||||
ty_err => byte!(23),
|
ty_err => byte!(23),
|
||||||
ty_unboxed_vec(m) => {
|
ty_unboxed_vec(m) => {
|
||||||
byte!(24);
|
byte!(24);
|
||||||
mt(&mut hash, m);
|
mt(&mut state, m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
hash.result()
|
state.result()
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Variance {
|
impl Variance {
|
||||||
|
|
|
@ -18,13 +18,12 @@ use str::OwnedStr;
|
||||||
use container::Container;
|
use container::Container;
|
||||||
use cast;
|
use cast;
|
||||||
use fmt;
|
use fmt;
|
||||||
use hash::{Hash, sip};
|
|
||||||
use iter::Iterator;
|
use iter::Iterator;
|
||||||
use vec::{ImmutableVector, MutableVector, Vector};
|
use vec::{ImmutableVector, MutableVector, Vector};
|
||||||
use option::{Option, Some, None};
|
use option::{Option, Some, None};
|
||||||
|
|
||||||
/// Datatype to hold one ascii character. It wraps a `u8`, with the highest bit always zero.
|
/// Datatype to hold one ascii character. It wraps a `u8`, with the highest bit always zero.
|
||||||
#[deriving(Clone, Eq, Ord, TotalOrd, TotalEq)]
|
#[deriving(Clone, Eq, Ord, TotalOrd, TotalEq, Hash)]
|
||||||
pub struct Ascii { priv chr: u8 }
|
pub struct Ascii { priv chr: u8 }
|
||||||
|
|
||||||
impl Ascii {
|
impl Ascii {
|
||||||
|
@ -306,13 +305,6 @@ impl IntoStr for ~[Ascii] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hash for Ascii {
|
|
||||||
#[inline]
|
|
||||||
fn hash(&self, s: &mut sip::SipState) {
|
|
||||||
self.to_byte().hash(s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Trait to convert to an owned byte array by consuming self
|
/// Trait to convert to an owned byte array by consuming self
|
||||||
pub trait IntoBytes {
|
pub trait IntoBytes {
|
||||||
/// Converts to an owned byte array by consuming self
|
/// Converts to an owned byte array by consuming self
|
||||||
|
|
|
@ -55,7 +55,6 @@ pub struct SocketAddr {
|
||||||
port: Port,
|
port: Port,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl fmt::Show for SocketAddr {
|
impl fmt::Show for SocketAddr {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self.ip {
|
match self.ip {
|
||||||
|
|
|
@ -151,7 +151,6 @@ pub mod container;
|
||||||
pub mod default;
|
pub mod default;
|
||||||
pub mod any;
|
pub mod any;
|
||||||
|
|
||||||
|
|
||||||
/* Common data structures */
|
/* Common data structures */
|
||||||
|
|
||||||
pub mod option;
|
pub mod option;
|
||||||
|
|
|
@ -8,14 +8,13 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use std::hash::{Hash, sip};
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fmt::Show;
|
use std::fmt::Show;
|
||||||
|
|
||||||
#[deriving(Eq)]
|
#[deriving(Eq)]
|
||||||
pub enum Os { OsWin32, OsMacos, OsLinux, OsAndroid, OsFreebsd, }
|
pub enum Os { OsWin32, OsMacos, OsLinux, OsAndroid, OsFreebsd, }
|
||||||
|
|
||||||
#[deriving(Eq)]
|
#[deriving(Eq, Hash)]
|
||||||
pub enum Abi {
|
pub enum Abi {
|
||||||
// NB: This ordering MUST match the AbiDatas array below.
|
// NB: This ordering MUST match the AbiDatas array below.
|
||||||
// (This is ensured by the test indices_are_correct().)
|
// (This is ensured by the test indices_are_correct().)
|
||||||
|
@ -267,12 +266,6 @@ impl AbiSet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hash for Abi {
|
|
||||||
fn hash(&self, s: &mut sip::SipState) {
|
|
||||||
self.index().hash(s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Show for Abi {
|
impl fmt::Show for Abi {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
self.data().name.fmt(f)
|
self.data().name.fmt(f)
|
||||||
|
|
|
@ -107,7 +107,7 @@ pub struct SCTable {
|
||||||
pub static EMPTY_CTXT : SyntaxContext = 0;
|
pub static EMPTY_CTXT : SyntaxContext = 0;
|
||||||
pub static ILLEGAL_CTXT : SyntaxContext = 1;
|
pub static ILLEGAL_CTXT : SyntaxContext = 1;
|
||||||
|
|
||||||
#[deriving(Eq, Encodable, Decodable,Hash)]
|
#[deriving(Eq, Encodable, Decodable, Hash)]
|
||||||
pub enum SyntaxContext_ {
|
pub enum SyntaxContext_ {
|
||||||
EmptyCtxt,
|
EmptyCtxt,
|
||||||
Mark (Mrk,SyntaxContext),
|
Mark (Mrk,SyntaxContext),
|
||||||
|
@ -332,7 +332,7 @@ impl Eq for MetaItem_ {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable,Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct Block {
|
pub struct Block {
|
||||||
view_items: ~[ViewItem],
|
view_items: ~[ViewItem],
|
||||||
stmts: ~[@Stmt],
|
stmts: ~[@Stmt],
|
||||||
|
@ -467,7 +467,7 @@ pub enum Stmt_ {
|
||||||
// FIXME (pending discussion of #1697, #2178...): local should really be
|
// FIXME (pending discussion of #1697, #2178...): local should really be
|
||||||
// a refinement on pat.
|
// a refinement on pat.
|
||||||
/// Local represents a `let` statement, e.g., `let <pat>:<ty> = <expr>;`
|
/// Local represents a `let` statement, e.g., `let <pat>:<ty> = <expr>;`
|
||||||
#[deriving(Eq, Encodable, Decodable,Hash)]
|
#[deriving(Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct Local {
|
pub struct Local {
|
||||||
ty: P<Ty>,
|
ty: P<Ty>,
|
||||||
pat: @Pat,
|
pat: @Pat,
|
||||||
|
@ -478,7 +478,7 @@ pub struct Local {
|
||||||
|
|
||||||
pub type Decl = Spanned<Decl_>;
|
pub type Decl = Spanned<Decl_>;
|
||||||
|
|
||||||
#[deriving(Eq, Encodable, Decodable,Hash)]
|
#[deriving(Eq, Encodable, Decodable, Hash)]
|
||||||
pub enum Decl_ {
|
pub enum Decl_ {
|
||||||
// a local (let) binding:
|
// a local (let) binding:
|
||||||
DeclLocal(@Local),
|
DeclLocal(@Local),
|
||||||
|
@ -514,7 +514,7 @@ pub enum UnsafeSource {
|
||||||
UserProvided,
|
UserProvided,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable,Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct Expr {
|
pub struct Expr {
|
||||||
id: NodeId,
|
id: NodeId,
|
||||||
node: Expr_,
|
node: Expr_,
|
||||||
|
@ -732,7 +732,7 @@ pub struct MutTy {
|
||||||
mutbl: Mutability,
|
mutbl: Mutability,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Eq, Encodable, Decodable,Hash)]
|
#[deriving(Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct TypeField {
|
pub struct TypeField {
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
mt: MutTy,
|
mt: MutTy,
|
||||||
|
@ -836,7 +836,7 @@ impl fmt::Show for Onceness {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Eq, Encodable, Decodable,Hash)]
|
#[deriving(Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct ClosureTy {
|
pub struct ClosureTy {
|
||||||
sigil: Sigil,
|
sigil: Sigil,
|
||||||
region: Option<Lifetime>,
|
region: Option<Lifetime>,
|
||||||
|
@ -967,7 +967,7 @@ pub enum ExplicitSelf_ {
|
||||||
|
|
||||||
pub type ExplicitSelf = Spanned<ExplicitSelf_>;
|
pub type ExplicitSelf = Spanned<ExplicitSelf_>;
|
||||||
|
|
||||||
#[deriving(Eq, Encodable, Decodable,Hash)]
|
#[deriving(Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct Method {
|
pub struct Method {
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
attrs: ~[Attribute],
|
attrs: ~[Attribute],
|
||||||
|
@ -987,7 +987,7 @@ pub struct Mod {
|
||||||
items: ~[@Item],
|
items: ~[@Item],
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable,Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct ForeignMod {
|
pub struct ForeignMod {
|
||||||
abis: AbiSet,
|
abis: AbiSet,
|
||||||
view_items: ~[ViewItem],
|
view_items: ~[ViewItem],
|
||||||
|
@ -1074,14 +1074,14 @@ pub type Attribute = Spanned<Attribute_>;
|
||||||
// Distinguishes between Attributes that decorate items and Attributes that
|
// Distinguishes between Attributes that decorate items and Attributes that
|
||||||
// are contained as statements within items. These two cases need to be
|
// are contained as statements within items. These two cases need to be
|
||||||
// distinguished for pretty-printing.
|
// distinguished for pretty-printing.
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable,Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
pub enum AttrStyle {
|
pub enum AttrStyle {
|
||||||
AttrOuter,
|
AttrOuter,
|
||||||
AttrInner,
|
AttrInner,
|
||||||
}
|
}
|
||||||
|
|
||||||
// doc-comments are promoted to attributes that have is_sugared_doc = true
|
// doc-comments are promoted to attributes that have is_sugared_doc = true
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable,Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct Attribute_ {
|
pub struct Attribute_ {
|
||||||
style: AttrStyle,
|
style: AttrStyle,
|
||||||
value: @MetaItem,
|
value: @MetaItem,
|
||||||
|
@ -1095,13 +1095,13 @@ pub struct Attribute_ {
|
||||||
If this impl is an ItemImpl, the impl_id is redundant (it could be the
|
If this impl is an ItemImpl, the impl_id is redundant (it could be the
|
||||||
same as the impl's node id).
|
same as the impl's node id).
|
||||||
*/
|
*/
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable,Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct TraitRef {
|
pub struct TraitRef {
|
||||||
path: Path,
|
path: Path,
|
||||||
ref_id: NodeId,
|
ref_id: NodeId,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable,Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
pub enum Visibility {
|
pub enum Visibility {
|
||||||
Public,
|
Public,
|
||||||
Private,
|
Private,
|
||||||
|
@ -1117,7 +1117,7 @@ impl Visibility {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable,Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct StructField_ {
|
pub struct StructField_ {
|
||||||
kind: StructFieldKind,
|
kind: StructFieldKind,
|
||||||
id: NodeId,
|
id: NodeId,
|
||||||
|
@ -1127,13 +1127,13 @@ pub struct StructField_ {
|
||||||
|
|
||||||
pub type StructField = Spanned<StructField_>;
|
pub type StructField = Spanned<StructField_>;
|
||||||
|
|
||||||
#[deriving(Clone, Eq, Encodable, Decodable,Hash)]
|
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]
|
||||||
pub enum StructFieldKind {
|
pub enum StructFieldKind {
|
||||||
NamedField(Ident, Visibility),
|
NamedField(Ident, Visibility),
|
||||||
UnnamedField // element of a tuple-like struct
|
UnnamedField // element of a tuple-like struct
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Eq, Encodable, Decodable,Hash)]
|
#[deriving(Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct StructDef {
|
pub struct StructDef {
|
||||||
fields: ~[StructField], /* fields, not including ctor */
|
fields: ~[StructField], /* fields, not including ctor */
|
||||||
/* ID of the constructor. This is only used for tuple- or enum-like
|
/* ID of the constructor. This is only used for tuple- or enum-like
|
||||||
|
@ -1173,7 +1173,7 @@ pub enum Item_ {
|
||||||
ItemMac(Mac),
|
ItemMac(Mac),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Eq, Encodable, Decodable,Hash)]
|
#[deriving(Eq, Encodable, Decodable, Hash)]
|
||||||
pub struct ForeignItem {
|
pub struct ForeignItem {
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
attrs: ~[Attribute],
|
attrs: ~[Attribute],
|
||||||
|
@ -1183,7 +1183,7 @@ pub struct ForeignItem {
|
||||||
vis: Visibility,
|
vis: Visibility,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Eq, Encodable, Decodable,Hash)]
|
#[deriving(Eq, Encodable, Decodable, Hash)]
|
||||||
pub enum ForeignItem_ {
|
pub enum ForeignItem_ {
|
||||||
ForeignItemFn(P<FnDecl>, Generics),
|
ForeignItemFn(P<FnDecl>, Generics),
|
||||||
ForeignItemStatic(P<Ty>, /* is_mutbl */ bool),
|
ForeignItemStatic(P<Ty>, /* is_mutbl */ bool),
|
||||||
|
@ -1192,7 +1192,7 @@ pub enum ForeignItem_ {
|
||||||
// The data we save and restore about an inlined item or method. This is not
|
// The data we save and restore about an inlined item or method. This is not
|
||||||
// part of the AST that we parse from a file, but it becomes part of the tree
|
// part of the AST that we parse from a file, but it becomes part of the tree
|
||||||
// that we trans.
|
// that we trans.
|
||||||
#[deriving(Eq, Encodable, Decodable,Hash)]
|
#[deriving(Eq, Encodable, Decodable, Hash)]
|
||||||
pub enum InlinedItem {
|
pub enum InlinedItem {
|
||||||
IIItem(@Item),
|
IIItem(@Item),
|
||||||
IIMethod(DefId /* impl id */, bool /* is provided */, @Method),
|
IIMethod(DefId /* impl id */, bool /* is provided */, @Method),
|
||||||
|
|
|
@ -38,7 +38,7 @@ pub struct BytePos(u32);
|
||||||
/// A character offset. Because of multibyte utf8 characters, a byte offset
|
/// A character offset. Because of multibyte utf8 characters, a byte offset
|
||||||
/// is not equivalent to a character offset. The CodeMap will convert BytePos
|
/// is not equivalent to a character offset. The CodeMap will convert BytePos
|
||||||
/// values to CharPos values as necessary.
|
/// values to CharPos values as necessary.
|
||||||
#[deriving(Eq,Hash, Ord)]
|
#[deriving(Eq, Hash, Ord)]
|
||||||
pub struct CharPos(uint);
|
pub struct CharPos(uint);
|
||||||
|
|
||||||
// FIXME: Lots of boilerplate in these impls, but so far my attempts to fix
|
// FIXME: Lots of boilerplate in these impls, but so far my attempts to fix
|
||||||
|
|
|
@ -75,8 +75,7 @@ impl<T:Eq + Hash + Freeze + Clone + 'static> Interner<T> {
|
||||||
vect.get().len()
|
vect.get().len()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_equiv<Q:Hash + Equiv<T>>(&self, val: &Q)
|
pub fn find_equiv<Q:Hash + Equiv<T>>(&self, val: &Q) -> Option<Name> {
|
||||||
-> Option<Name> {
|
|
||||||
let map = self.map.borrow();
|
let map = self.map.borrow();
|
||||||
match map.get().find_equiv(val) {
|
match map.get().find_equiv(val) {
|
||||||
Some(v) => Some(*v),
|
Some(v) => Some(*v),
|
||||||
|
@ -207,8 +206,7 @@ impl StrInterner {
|
||||||
vect.get().len()
|
vect.get().len()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_equiv<Q:Hash + Equiv<RcStr>>(&self, val: &Q)
|
pub fn find_equiv<Q:Hash + Equiv<RcStr>>(&self, val: &Q) -> Option<Name> {
|
||||||
-> Option<Name> {
|
|
||||||
let map = self.map.borrow();
|
let map = self.map.borrow();
|
||||||
match map.get().find_equiv(val) {
|
match map.get().find_equiv(val) {
|
||||||
Some(v) => Some(*v),
|
Some(v) => Some(*v),
|
||||||
|
|
|
@ -27,18 +27,21 @@ mod submod {
|
||||||
// function calls, then being in a submodule will (correctly)
|
// function calls, then being in a submodule will (correctly)
|
||||||
// cause errors about unrecognised module `std` (or `extra`)
|
// cause errors about unrecognised module `std` (or `extra`)
|
||||||
#[deriving(Eq, Ord, TotalEq, TotalOrd,
|
#[deriving(Eq, Ord, TotalEq, TotalOrd,
|
||||||
|
Hash,
|
||||||
Clone, DeepClone,
|
Clone, DeepClone,
|
||||||
Show, Rand,
|
Show, Rand,
|
||||||
Encodable, Decodable)]
|
Encodable, Decodable)]
|
||||||
enum A { A1(uint), A2(int) }
|
enum A { A1(uint), A2(int) }
|
||||||
|
|
||||||
#[deriving(Eq, Ord, TotalEq, TotalOrd,
|
#[deriving(Eq, Ord, TotalEq, TotalOrd,
|
||||||
|
Hash,
|
||||||
Clone, DeepClone,
|
Clone, DeepClone,
|
||||||
Show, Rand,
|
Show, Rand,
|
||||||
Encodable, Decodable)]
|
Encodable, Decodable)]
|
||||||
struct B { x: uint, y: int }
|
struct B { x: uint, y: int }
|
||||||
|
|
||||||
#[deriving(Eq, Ord, TotalEq, TotalOrd,
|
#[deriving(Eq, Ord, TotalEq, TotalOrd,
|
||||||
|
Hash,
|
||||||
Clone, DeepClone,
|
Clone, DeepClone,
|
||||||
Show, Rand,
|
Show, Rand,
|
||||||
Encodable, Decodable)]
|
Encodable, Decodable)]
|
||||||
|
|
|
@ -10,8 +10,9 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#[deriving(Eq)]
|
use std::hash::hash;
|
||||||
#[deriving(Clone)]
|
|
||||||
|
#[deriving(Eq, Clone, Hash)]
|
||||||
struct Foo {
|
struct Foo {
|
||||||
bar: uint,
|
bar: uint,
|
||||||
baz: int
|
baz: int
|
||||||
|
@ -22,4 +23,5 @@ pub fn main() {
|
||||||
|
|
||||||
a == a; // check for Eq impl w/o testing its correctness
|
a == a; // check for Eq impl w/o testing its correctness
|
||||||
a.clone(); // check for Clone impl w/o testing its correctness
|
a.clone(); // check for Clone impl w/o testing its correctness
|
||||||
|
hash(&a); // check for Hash impl w/o testing its correctness
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,9 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#[deriving(Eq, Clone)]
|
use std::hash::hash;
|
||||||
|
|
||||||
|
#[deriving(Eq, Clone, Hash)]
|
||||||
struct Foo {
|
struct Foo {
|
||||||
bar: uint,
|
bar: uint,
|
||||||
baz: int
|
baz: int
|
||||||
|
@ -21,4 +23,5 @@ pub fn main() {
|
||||||
|
|
||||||
a == a; // check for Eq impl w/o testing its correctness
|
a == a; // check for Eq impl w/o testing its correctness
|
||||||
a.clone(); // check for Clone impl w/o testing its correctness
|
a.clone(); // check for Clone impl w/o testing its correctness
|
||||||
|
hash(&a); // check for Hash impl w/o testing its correctness
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,7 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#[deriving(Eq)]
|
#[deriving(Eq, Hash)]
|
||||||
#[deriving(Hash)]
|
|
||||||
struct Foo<T> {
|
struct Foo<T> {
|
||||||
x: int,
|
x: int,
|
||||||
y: T,
|
y: T,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue