From d63ab5f8c313a5868d245f9cf1969fc991a301f6 Mon Sep 17 00:00:00 2001
From: Scott Olson <scott@solson.me>
Date: Sat, 17 Dec 2016 01:47:24 -0800
Subject: [PATCH] Refactor PrimVal::relocation out of existence.

---
 src/eval_context.rs | 20 ++++++++++----------
 src/value.rs        | 12 +-----------
 2 files changed, 11 insertions(+), 21 deletions(-)

diff --git a/src/eval_context.rs b/src/eval_context.rs
index 7108286193f..c1774099b8c 100644
--- a/src/eval_context.rs
+++ b/src/eval_context.rs
@@ -315,15 +315,15 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
                                        .expect("global should have been cached (freeze)");
                 match global_value.data.expect("global should have been initialized") {
                     Value::ByRef(ptr) => self.memory.freeze(ptr.alloc_id)?,
-                    Value::ByVal(val) => if let Some(alloc_id) = val.relocation() {
-                        self.memory.freeze(alloc_id)?;
+                    Value::ByVal(val) => if let PrimVal::Ptr(ptr) = val {
+                        self.memory.freeze(ptr.alloc_id)?;
                     },
-                    Value::ByValPair(a, b) => {
-                        if let Some(alloc_id) = a.relocation() {
-                            self.memory.freeze(alloc_id)?;
+                    Value::ByValPair(val1, val2) => {
+                        if let PrimVal::Ptr(ptr) = val1 {
+                            self.memory.freeze(ptr.alloc_id)?;
                         }
-                        if let Some(alloc_id) = b.relocation() {
-                            self.memory.freeze(alloc_id)?;
+                        if let PrimVal::Ptr(ptr) = val2 {
+                            self.memory.freeze(ptr.alloc_id)?;
                         }
                     },
                 }
@@ -1301,12 +1301,12 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
                     }
                     Value::ByVal(val) => {
                         trace!("frame[{}] {:?}: {:?}", frame, local, val);
-                        if let Some(alloc_id) = val.relocation() { allocs.push(alloc_id); }
+                        if let PrimVal::Ptr(ptr) = val { allocs.push(ptr.alloc_id); }
                     }
                     Value::ByValPair(val1, val2) => {
                         trace!("frame[{}] {:?}: ({:?}, {:?})", frame, local, val1, val2);
-                        if let Some(alloc_id) = val1.relocation() { allocs.push(alloc_id); }
-                        if let Some(alloc_id) = val2.relocation() { allocs.push(alloc_id); }
+                        if let PrimVal::Ptr(ptr) = val1 { allocs.push(ptr.alloc_id); }
+                        if let PrimVal::Ptr(ptr) = val2 { allocs.push(ptr.alloc_id); }
                     }
                 }
             }
diff --git a/src/value.rs b/src/value.rs
index c7c81e5c947..a4b4f18ee2f 100644
--- a/src/value.rs
+++ b/src/value.rs
@@ -4,7 +4,7 @@
 use std::mem::transmute;
 
 use error::{EvalError, EvalResult};
-use memory::{AllocId, Memory, Pointer};
+use memory::{Memory, Pointer};
 
 pub(super) fn bits_to_f32(bits: u64) -> f32 {
     unsafe { transmute::<u32, f32>(bits as u32) }
@@ -127,16 +127,6 @@ impl<'tcx> PrimVal {
         }
     }
 
-    // FIXME(solson): Remove this. It's a temporary function to aid refactoring, but it shouldn't
-    // stick around with this name.
-    pub fn relocation(self) -> Option<AllocId> {
-        if let PrimVal::Ptr(ref p) = self {
-            Some(p.alloc_id)
-        } else {
-            None
-        }
-    }
-
     pub fn from_u64(n: u64) -> Self {
         PrimVal::Bytes(n)
     }