1313
1414use std:: convert:: TryInto ;
1515
16- use rustc:: { mir, ty } ;
16+ use rustc:: mir;
1717use rustc:: ty:: layout:: { self , Size , LayoutOf , TyLayout , HasDataLayout , IntegerExt , VariantIdx } ;
1818
1919use rustc:: mir:: interpret:: {
@@ -535,20 +535,21 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
535535 . collect ( )
536536 }
537537
538- // Also used e.g. when miri runs into a constant.
539- // FIXME: Can we avoid converting with ConstValue and Const? We should be using RawConst.
540- fn const_value_to_op (
538+ // Used when miri runs into a constant, and by CTFE.
539+ // FIXME: CTFE should use allocations, then we can make this private (embed it into
540+ // `eval_operand`, ideally).
541+ pub ( crate ) fn const_value_to_op (
541542 & self ,
542543 val : ConstValue < ' tcx > ,
543544 ) -> EvalResult < ' tcx , Operand < M :: PointerTag > > {
544545 trace ! ( "const_value_to_op: {:?}" , val) ;
545546 match val {
546547 ConstValue :: Unevaluated ( def_id, substs) => {
547548 let instance = self . resolve ( def_id, substs) ?;
548- self . global_to_op ( GlobalId {
549+ Ok ( * OpTy :: from ( self . const_eval_raw ( GlobalId {
549550 instance,
550551 promoted : None ,
551- } )
552+ } ) ? ) )
552553 }
553554 ConstValue :: ByRef ( id, alloc, offset) => {
554555 // We rely on mutability being set correctly in that allocation to prevent writes
@@ -566,21 +567,6 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
566567 Ok ( Operand :: Immediate ( Immediate :: Scalar ( x. into ( ) ) ) . with_default_tag ( ) ) ,
567568 }
568569 }
569- pub fn const_to_op (
570- & self ,
571- cnst : & ty:: Const < ' tcx > ,
572- ) -> EvalResult < ' tcx , OpTy < ' tcx , M :: PointerTag > > {
573- let op = self . const_value_to_op ( cnst. val ) ?;
574- Ok ( OpTy { op, layout : self . layout_of ( cnst. ty ) ? } )
575- }
576-
577- pub ( super ) fn global_to_op (
578- & self ,
579- gid : GlobalId < ' tcx >
580- ) -> EvalResult < ' tcx , Operand < M :: PointerTag > > {
581- let cv = self . const_eval ( gid) ?;
582- self . const_value_to_op ( cv. val )
583- }
584570
585571 /// Read discriminant, return the runtime value as well as the variant index.
586572 pub fn read_discriminant (
0 commit comments