Prefer enum instead of magic numbers

This commit is contained in:
Oliver Schneider 2018-01-26 13:54:51 +01:00 committed by Oliver Schneider
parent 8c2db0ba8c
commit c5d2e178e7
No known key found for this signature in database
GPG Key ID: A69F8D225B3AD7D9

View File

@ -368,6 +368,17 @@ impl_stable_hash_for!(struct mir::interpret::MemoryPointer {
offset
});
enum AllocDiscriminant {
Static,
Constant,
Function,
}
impl_stable_hash_for!(enum self::AllocDiscriminant {
Static,
Constant,
Function
});
impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
fn hash_stable<W: StableHasherResult>(
&self,
@ -377,15 +388,15 @@ impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
ty::tls::with_opt(|tcx| {
let tcx = tcx.expect("can't hash AllocIds during hir lowering");
if let Some(def_id) = tcx.interpret_interner.get_corresponding_static_def_id(*self) {
0.hash_stable(hcx, hasher);
AllocDiscriminant::Static.hash_stable(hcx, hasher);
// statics are unique via their DefId
def_id.hash_stable(hcx, hasher);
} else if let Some(alloc) = tcx.interpret_interner.get_alloc(*self) {
// not a static, can't be recursive, hash the allocation
1.hash_stable(hcx, hasher);
AllocDiscriminant::Constant.hash_stable(hcx, hasher);
alloc.hash_stable(hcx, hasher);
} else if let Some(inst) = tcx.interpret_interner.get_fn(*self) {
2.hash_stable(hcx, hasher);
AllocDiscriminant::Function.hash_stable(hcx, hasher);
inst.hash_stable(hcx, hasher);
} else {
bug!("no allocation for {}", self);