about summary refs log tree commit diff
diff options
context:
space:
mode:
authorcsmoe <35686186+csmoe@users.noreply.github.com>2018-08-31 18:31:15 +0800
committercsmoe <35686186+csmoe@users.noreply.github.com>2018-08-31 18:31:15 +0800
commit72ba683457f3bb2b62754dec78ddd0c633982c65 (patch)
tree224f8b989c7503837f6aedff3aaea4c31cff0c3c
parent66d7216469faa5f22d0fe1deb9573e84d22142c5 (diff)
downloadrust-72ba683457f3bb2b62754dec78ddd0c633982c65.tar.gz
rust-72ba683457f3bb2b62754dec78ddd0c633982c65.zip
extract allocation info from byref
-rw-r--r--src/librustc_mir/interpret/memory.rs11
-rw-r--r--src/librustc_typeck/check/mod.rs8
2 files changed, 13 insertions, 6 deletions
diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs
index 91fc6453446..79e635a03b2 100644
--- a/src/librustc_mir/interpret/memory.rs
+++ b/src/librustc_mir/interpret/memory.rs
@@ -22,7 +22,7 @@ use std::ptr;
 
 use rustc::ty::{self, Instance, query::TyCtxtAt};
 use rustc::ty::layout::{self, Align, TargetDataLayout, Size, HasDataLayout};
-use rustc::mir::interpret::{Pointer, AllocId, Allocation, ScalarMaybeUndef, GlobalId,
+use rustc::mir::interpret::{Pointer, AllocId, Allocation, ConstValue, ScalarMaybeUndef, GlobalId,
                             EvalResult, Scalar, EvalErrorKind, AllocType, PointerArithmetic,
                             truncate};
 pub use rustc::mir::interpret::{write_target_uint, read_target_uint};
@@ -340,9 +340,12 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
             // no need to report anything, the const_eval call takes care of that for statics
             assert!(tcx.is_static(def_id).is_some());
             EvalErrorKind::ReferencedConstant(err).into()
-        }).map(|val| {
-            // FIXME We got our static (will be a ByRef), now we make a *copy*?!?
-            tcx.const_to_allocation(val)
+        }).map(|const_val| {
+            if let ConstValue::ByRef(_, allocation, _) = const_val.val {
+                allocation
+            } else {
+                panic!("Trying to get allocation info from non-byref const value")
+            }
         })
     }
 
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index bbb45c04e4e..2129cdf6f46 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -94,7 +94,7 @@ use rustc::infer::{self, InferCtxt, InferOk, RegionVariableOrigin};
 use rustc::infer::anon_types::AnonTypeDecl;
 use rustc::infer::type_variable::{TypeVariableOrigin};
 use rustc::middle::region;
-use rustc::mir::interpret::{GlobalId};
+use rustc::mir::interpret::{ConstValue, GlobalId};
 use rustc::ty::subst::{CanonicalSubsts, UnpackedKind, Subst, Substs};
 use rustc::traits::{self, ObligationCause, ObligationCauseCode, TraitEngine};
 use rustc::ty::{self, Ty, TyCtxt, GenericParamDefKind, Visibility, ToPredicate, RegionKind};
@@ -1375,7 +1375,11 @@ fn maybe_check_static_with_link_section(tcx: TyCtxt, id: DefId, span: Span) {
     };
     let param_env = ty::ParamEnv::reveal_all();
     if let Ok(static_) = tcx.const_eval(param_env.and(cid)) {
-        let alloc = tcx.const_to_allocation(static_);
+        let alloc = if let ConstValue::ByRef(_, allocation, _) = static_.val {
+            allocation
+        } else {
+            panic!("Trying to get allocation info from non-byref const value")
+        };
         if alloc.relocations.len() != 0 {
             let msg = "statics with a custom `#[link_section]` must be a \
                        simple list of bytes on the wasm target with no \