Skip to content

Commit 72ba683

Browse files
committed
extract allocation info from byref
1 parent 66d7216 commit 72ba683

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

Diff for: src/librustc_mir/interpret/memory.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::ptr;
2222

2323
use rustc::ty::{self, Instance, query::TyCtxtAt};
2424
use rustc::ty::layout::{self, Align, TargetDataLayout, Size, HasDataLayout};
25-
use rustc::mir::interpret::{Pointer, AllocId, Allocation, ScalarMaybeUndef, GlobalId,
25+
use rustc::mir::interpret::{Pointer, AllocId, Allocation, ConstValue, ScalarMaybeUndef, GlobalId,
2626
EvalResult, Scalar, EvalErrorKind, AllocType, PointerArithmetic,
2727
truncate};
2828
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> {
340340
// no need to report anything, the const_eval call takes care of that for statics
341341
assert!(tcx.is_static(def_id).is_some());
342342
EvalErrorKind::ReferencedConstant(err).into()
343-
}).map(|val| {
344-
// FIXME We got our static (will be a ByRef), now we make a *copy*?!?
345-
tcx.const_to_allocation(val)
343+
}).map(|const_val| {
344+
if let ConstValue::ByRef(_, allocation, _) = const_val.val {
345+
allocation
346+
} else {
347+
panic!("Trying to get allocation info from non-byref const value")
348+
}
346349
})
347350
}
348351

Diff for: src/librustc_typeck/check/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ use rustc::infer::{self, InferCtxt, InferOk, RegionVariableOrigin};
9494
use rustc::infer::anon_types::AnonTypeDecl;
9595
use rustc::infer::type_variable::{TypeVariableOrigin};
9696
use rustc::middle::region;
97-
use rustc::mir::interpret::{GlobalId};
97+
use rustc::mir::interpret::{ConstValue, GlobalId};
9898
use rustc::ty::subst::{CanonicalSubsts, UnpackedKind, Subst, Substs};
9999
use rustc::traits::{self, ObligationCause, ObligationCauseCode, TraitEngine};
100100
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) {
13751375
};
13761376
let param_env = ty::ParamEnv::reveal_all();
13771377
if let Ok(static_) = tcx.const_eval(param_env.and(cid)) {
1378-
let alloc = tcx.const_to_allocation(static_);
1378+
let alloc = if let ConstValue::ByRef(_, allocation, _) = static_.val {
1379+
allocation
1380+
} else {
1381+
panic!("Trying to get allocation info from non-byref const value")
1382+
};
13791383
if alloc.relocations.len() != 0 {
13801384
let msg = "statics with a custom `#[link_section]` must be a \
13811385
simple list of bytes on the wasm target with no \

0 commit comments

Comments
 (0)