]> git.lizzy.rs Git - rust.git/commitdiff
Prefer enum instead of magic numbers
authorOliver Schneider <git-no-reply-9879165716479413131@oli-obk.de>
Fri, 26 Jan 2018 12:54:51 +0000 (13:54 +0100)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Thu, 8 Mar 2018 07:34:10 +0000 (08:34 +0100)
src/librustc/ich/impls_ty.rs

index 74441d4694567d065c2e2520e60c46fd79da7daf..4f691c0d39485a331e4b9f638eacb3029eddf212 100644 (file)
@@ -368,6 +368,17 @@ fn hash_stable<W: StableHasherResult>(&self,
     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 @@ fn hash_stable<W: StableHasherResult>(
         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);