pub fn hash_crate_independent(&self, ty: Ty<'tcx>, svh: &Svh) -> u64 {
        let mut state = SipHasher::new();
        helper(self, ty, svh, &mut state);
        return state.finish();

        fn helper<'tcx>(tcx: &ctxt<'tcx>, ty: Ty<'tcx>, svh: &Svh,
                        state: &mut SipHasher) {
            macro_rules! byte { ($b:expr) => { ($b as u8).hash(state) } }
            macro_rules! hash { ($e:expr) => { $e.hash(state) }  }

            let region = |state: &mut SipHasher, r: Region| {
                match r {
                    ReStatic => {}
                    ReLateBound(db, BrAnon(i)) => {
                        db.hash(state);
                        i.hash(state);
                    }
                    ReEmpty |
                    ReEarlyBound(..) |
                    ReLateBound(..) |
                    ReFree(..) |
                    ReScope(..) |
                    ReVar(..) |
                    ReSkolemized(..) => {
                        tcx.sess.bug("unexpected region found when hashing a type")
                    }
                }
            };
            let did = |state: &mut SipHasher, did: DefId| {
                let h = if did.is_local() {
                    svh.clone()
                } else {
                    tcx.sess.cstore.get_crate_hash(did.krate)
                };
                h.as_str().hash(state);
                did.node.hash(state);
            };
            let mt = |state: &mut SipHasher, mt: TypeAndMut| {
                mt.mutbl.hash(state);
            };
            let fn_sig = |state: &mut SipHasher, sig: &Binder<FnSig<'tcx>>| {
                let sig = tcx.anonymize_late_bound_regions(sig).0;
                for a in &sig.inputs { helper(tcx, *a, svh, state); }
                if let ty::FnConverging(output) = sig.output {
                    helper(tcx, output, svh, state);
                }
            };
            ty.maybe_walk(|ty| {
                match ty.sty {
                    TyBool => byte!(2),
                    TyChar => byte!(3),
                    TyInt(i) => {
                        byte!(4);
                        hash!(i);
                    }
                    TyUint(u) => {
                        byte!(5);
                        hash!(u);
                    }
                    TyFloat(f) => {
                        byte!(6);
                        hash!(f);
                    }
                    TyStr => {
                        byte!(7);
                    }
                    TyEnum(d, _) => {
                        byte!(8);
                        did(state, d.did);
                    }
                    TyBox(_) => {
                        byte!(9);
                    }
                    TyArray(_, n) => {
                        byte!(10);
                        n.hash(state);
                    }
                    TySlice(_) => {
                        byte!(11);
                    }
                    TyRawPtr(m) => {
                        byte!(12);
                        mt(state, m);
                    }
                    TyRef(r, m) => {
                        byte!(13);
                        region(state, *r);
                        mt(state, m);
                    }
                    TyBareFn(opt_def_id, ref b) => {
                        byte!(14);
                        hash!(opt_def_id);
                        hash!(b.unsafety);
                        hash!(b.abi);
                        fn_sig(state, &b.sig);
                        return false;
                    }
                    TyTrait(ref data) => {
                        byte!(17);
                        did(state, data.principal_def_id());
                        hash!(data.bounds);

                        let principal = tcx.anonymize_late_bound_regions(&data.principal).0;
                        for subty in &principal.substs.types {
                            helper(tcx, subty, svh, state);
                        }

                        return false;
                    }
                    TyStruct(d, _) => {
                        byte!(18);
                        did(state, d.did);
                    }
                    TyTuple(ref inner) => {
                        byte!(19);
                        hash!(inner.len());
                    }
                    TyParam(p) => {
                        byte!(20);
                        hash!(p.space);
                        hash!(p.idx);
                        hash!(p.name.as_str());
                    }
                    TyInfer(_) => unreachable!(),
                    TyError => byte!(21),
                    TyClosure(d, _) => {
                        byte!(22);
                        did(state, d);
                    }
                    TyProjection(ref data) => {
                        byte!(23);
                        did(state, data.trait_ref.def_id);
                        hash!(data.item_name.as_str());
                    }
                }
                true
            });
        }
    }
/// Creates a hash of the type `Ty` which will be the same no matter what crate
/// context it's calculated within. This is used by the `type_id` intrinsic.
Creates a hash of the type `Ty` which will be the same no matter what crate
context it's calculated within. This is used by the `type_id` intrinsic.
Creates a hash of the type ` Ty ` which will be the same no matter what crate context it ' s calculated within . This is used by the ` type_id ` intrinsic .
pub fn hash_crate_independent(&self, ty: Ty<'tcx>, svh: &Svh) -> u64 {
        let mut state = SipHasher::new();
        helper(self, ty, svh, &mut state);
        return state.finish();
        fn helper<'tcx>(tcx: &ctxt<'tcx>, ty: Ty<'tcx>, svh: &Svh,
                        state: &mut SipHasher) {
            macro_rules! byte { ($b:expr) => { ($b as u8).hash(state) } }
            macro_rules! hash { ($e:expr) => { $e.hash(state) }  }
            let region = |state: &mut SipHasher, r: Region| {
                match r {
                    ReStatic => {}
                    ReLateBound(db, BrAnon(i)) => {
                        db.hash(state);
                        i.hash(state);
                    }
                    ReEmpty |
                    ReEarlyBound(..) |
                    ReLateBound(..) |
                    ReFree(..) |
                    ReScope(..) |
                    ReVar(..) |
                    ReSkolemized(..) => {
                        tcx.sess.bug("unexpected region found when hashing a type")
                    }
                }
            };
            let did = |state: &mut SipHasher, did: DefId| {
                let h = if did.is_local() {
                    svh.clone()
                } else {
                    tcx.sess.cstore.get_crate_hash(did.krate)
                };
                h.as_str().hash(state);
                did.node.hash(state);
            };
            let mt = |state: &mut SipHasher, mt: TypeAndMut| {
                mt.mutbl.hash(state);
            };
            let fn_sig = |state: &mut SipHasher, sig: &Binder<FnSig<'tcx>>| {
                let sig = tcx.anonymize_late_bound_regions(sig).0;
                for a in &sig.inputs { helper(tcx, *a, svh, state); }
                if let ty::FnConverging(output) = sig.output {
                    helper(tcx, output, svh, state);
                }
            };
            ty.maybe_walk(|ty| {
                match ty.sty {
                    TyBool => byte!(2),
                    TyChar => byte!(3),
                    TyInt(i) => {
                        byte!(4);
                        hash!(i);
                    }
                    TyUint(u) => {
                        byte!(5);
                        hash!(u);
                    }
                    TyFloat(f) => {
                        byte!(6);
                        hash!(f);
                    }
                    TyStr => {
                        byte!(7);
                    }
                    TyEnum(d, _) => {
                        byte!(8);
                        did(state, d.did);
                    }
                    TyBox(_) => {
                        byte!(9);
                    }
                    TyArray(_, n) => {
                        byte!(10);
                        n.hash(state);
                    }
                    TySlice(_) => {
                        byte!(11);
                    }
                    TyRawPtr(m) => {
                        byte!(12);
                        mt(state, m);
                    }
                    TyRef(r, m) => {
                        byte!(13);
                        region(state, *r);
                        mt(state, m);
                    }
                    TyBareFn(opt_def_id, ref b) => {
                        byte!(14);
                        hash!(opt_def_id);
                        hash!(b.unsafety);
                        hash!(b.abi);
                        fn_sig(state, &b.sig);
                        return false;
                    }
                    TyTrait(ref data) => {
                        byte!(17);
                        did(state, data.principal_def_id());
                        hash!(data.bounds);
                        let principal = tcx.anonymize_late_bound_regions(&data.principal).0;
                        for subty in &principal.substs.types {
                            helper(tcx, subty, svh, state);
                        }
                        return false;
                    }
                    TyStruct(d, _) => {
                        byte!(18);
                        did(state, d.did);
                    }
                    TyTuple(ref inner) => {
                        byte!(19);
                        hash!(inner.len());
                    }
                    TyParam(p) => {
                        byte!(20);
                        hash!(p.space);
                        hash!(p.idx);
                        hash!(p.name.as_str());
                    }
                    TyInfer(_) => unreachable!(),
                    TyError => byte!(21),
                    TyClosure(d, _) => {
                        byte!(22);
                        did(state, d);
                    }
                    TyProjection(ref data) => {
                        byte!(23);
                        did(state, data.trait_ref.def_id);
                        hash!(data.item_name.as_str());
                    }
                }
                true
            });
        }
    }
pub fn hash_crate_independent ( & self , ty : Ty < ' tcx > , svh : & Svh ) -> u64 { let mut state = SipHasher :: new ( ) ; helper ( self , ty , svh , & mut state ) ; return state . finish ( ) ; fn helper < ' tcx > ( tcx : & ctxt < ' tcx > , ty : Ty < ' tcx > , svh : & Svh , state : & mut SipHasher ) { macro_rules! byte { ( $b : expr ) => { ( $b as u8 ) hash ( state ) } } macro_rules! hash { ( $e : expr ) => { $e hash ( state ) } } let region = | state : & mut SipHasher , r : Region | { match r { ReStatic => { } ReLateBound ( db , BrAnon ( i ) ) => { db . hash ( state ) ; i . hash ( state ) ; } ReEmpty | ReEarlyBound ( .. ) | ReLateBound ( .. ) | ReFree ( .. ) | ReScope ( .. ) | ReVar ( .. ) | ReSkolemized ( .. ) => { tcx . sess . bug ( " " ) } } } ; let did = | state : & mut SipHasher , did : DefId | { let h = if did . is_local ( ) { svh . clone ( ) } else { tcx . sess . cstore . get_crate_hash ( did . krate ) } ; h . as_str ( ) . hash ( state ) ; did . node . hash ( state ) ; } ; let mt = | state : & mut SipHasher , mt : TypeAndMut | { mt . mutbl . hash ( state ) ; } ; let fn_sig = | state : & mut SipHasher , sig : & Binder < FnSig < ' tcx > > | { let sig = tcx . anonymize_late_bound_regions ( sig ) . 0 ; for a in & sig . inputs { helper ( tcx , * a , svh , state ) ; } if let ty :: FnConverging ( output ) = sig . output { helper ( tcx , output , svh , state ) ; } } ; ty . maybe_walk ( | ty | { match ty . sty { TyBool => byte ! ( 2 ) , TyChar => byte ! ( 3 ) , TyInt ( i ) => { byte ! ( 4 ) ; hash ! ( i ) ; } TyUint ( u ) => { byte ! ( 5 ) ; hash ! ( u ) ; } TyFloat ( f ) => { byte ! ( 6 ) ; hash ! ( f ) ; } TyStr => { byte ! ( 7 ) ; } TyEnum ( d , _ ) => { byte ! ( 8 ) ; did ( state , d . did ) ; } TyBox ( _ ) => { byte ! ( 9 ) ; } TyArray ( _ , n ) => { byte ! ( 10 ) ; n . hash ( state ) ; } TySlice ( _ ) => { byte ! ( 11 ) ; } TyRawPtr ( m ) => { byte ! ( 12 ) ; mt ( state , m ) ; } TyRef ( r , m ) => { byte ! ( 13 ) ; region ( state , * r ) ; mt ( state , m ) ; } TyBareFn ( opt_def_id , ref b ) => { byte ! ( 14 ) ; hash ! ( opt_def_id ) ; hash ! ( b unsafety ) ; hash ! ( b abi ) ; fn_sig ( state , & b . sig ) ; return false ; } TyTrait ( ref data ) => { byte ! ( 17 ) ; did ( state , data . principal_def_id ( ) ) ; hash ! ( data bounds ) ; let principal = tcx . anonymize_late_bound_regions ( & data . principal ) . 0 ; for subty in & principal . substs . types { helper ( tcx , subty , svh , state ) ; } return false ; } TyStruct ( d , _ ) => { byte ! ( 18 ) ; did ( state , d . did ) ; } TyTuple ( ref inner ) => { byte ! ( 19 ) ; hash ! ( inner len ( ) ) ; } TyParam ( p ) => { byte ! ( 20 ) ; hash ! ( p space ) ; hash ! ( p idx ) ; hash ! ( p name as_str ( ) ) ; } TyInfer ( _ ) => unreachable ! ( ) , TyError => byte ! ( 21 ) , TyClosure ( d , _ ) => { byte ! ( 22 ) ; did ( state , d ) ; } TyProjection ( ref data ) => { byte ! ( 23 ) ; did ( state , data . trait_ref . def_id ) ; hash ! ( data item_name as_str ( ) ) ; } } true } ) ; } }
Creates a hash of the type `Ty` which will be the same no matter what crate
context it's calculated within.
Creates a hash of the type ` Ty ` which will be the same no matter what crate context it ' s calculated within .
&self
ty
Ty<'tcx>
svh
&Svh
&self
ty
Ty<'tcx>
svh
&Svh