@@ -21,7 +21,6 @@ use rustc_data_structures::indexed_vec::{IndexVec, Idx};
21
21
22
22
use syntax:: ast:: Mutability ;
23
23
use syntax:: source_map:: Span ;
24
- use syntax:: source_map:: DUMMY_SP ;
25
24
26
25
use rustc:: mir:: interpret:: {
27
26
EvalResult , EvalError , EvalErrorKind , GlobalId ,
@@ -390,30 +389,19 @@ pub fn const_variant_index<'a, 'tcx>(
390
389
}
391
390
392
391
pub fn const_to_allocation_provider < ' a , ' tcx > (
393
- tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
392
+ _tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
394
393
val : & ' tcx ty:: Const < ' tcx > ,
395
394
) -> & ' tcx Allocation {
395
+ // FIXME: This really does not need to be a query. Instead, we should have a query for statics
396
+ // that returns an allocation directly (or an `AllocId`?), after doing a sanity check of the
397
+ // value and centralizing error reporting.
396
398
match val. val {
397
399
ConstValue :: ByRef ( _, alloc, offset) => {
398
400
assert_eq ! ( offset. bytes( ) , 0 ) ;
399
401
return alloc;
400
402
} ,
401
- _ => ( )
403
+ _ => bug ! ( "const_to_allocation called on non-static" ) ,
402
404
}
403
- let result = || -> EvalResult < ' tcx , & ' tcx Allocation > {
404
- let mut ecx = EvalContext :: new (
405
- tcx. at ( DUMMY_SP ) ,
406
- ty:: ParamEnv :: reveal_all ( ) ,
407
- CompileTimeEvaluator ,
408
- ( ) ) ;
409
- let op = const_to_op ( & mut ecx, val) ?;
410
- // Make a new allocation, copy things there
411
- let ptr = ecx. allocate ( op. layout , MemoryKind :: Stack ) ?;
412
- ecx. copy_op ( op, ptr. into ( ) ) ?;
413
- let alloc = ecx. memory . get ( ptr. to_ptr ( ) ?. alloc_id ) ?;
414
- Ok ( tcx. intern_const_alloc ( alloc. clone ( ) ) )
415
- } ;
416
- result ( ) . expect ( "unable to convert ConstValue to Allocation" )
417
405
}
418
406
419
407
pub fn const_eval_provider < ' a , ' tcx > (
0 commit comments