@@ -59,7 +59,7 @@ pub(crate) fn eval_promoted<'a, 'mir, 'tcx>(
59
59
) -> EvalResult < ' tcx , MPlaceTy < ' tcx > > {
60
60
let span = tcx. def_span ( cid. instance . def_id ( ) ) ;
61
61
let mut ecx = mk_eval_cx ( tcx, span, param_env) ;
62
- eval_body_using_ecx ( & mut ecx, cid, Some ( mir) , param_env)
62
+ eval_body_using_ecx ( & mut ecx, cid, mir, param_env)
63
63
}
64
64
65
65
fn mplace_to_const < ' tcx > (
@@ -107,37 +107,15 @@ fn op_to_const<'tcx>(
107
107
ty:: Const { val, ty : op. layout . ty }
108
108
}
109
109
110
- fn eval_body_and_ecx < ' a , ' mir , ' tcx > (
111
- tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
112
- cid : GlobalId < ' tcx > ,
113
- mir : Option < & ' mir mir:: Mir < ' tcx > > ,
114
- param_env : ty:: ParamEnv < ' tcx > ,
115
- ) -> ( EvalResult < ' tcx , MPlaceTy < ' tcx > > , CompileTimeEvalContext < ' a , ' mir , ' tcx > ) {
116
- // we start out with the best span we have
117
- // and try improving it down the road when more information is available
118
- let span = tcx. def_span ( cid. instance . def_id ( ) ) ;
119
- let span = mir. map ( |mir| mir. span ) . unwrap_or ( span) ;
120
- let mut ecx = InterpretCx :: new ( tcx. at ( span) , param_env, CompileTimeInterpreter :: new ( ) ) ;
121
- let r = eval_body_using_ecx ( & mut ecx, cid, mir, param_env) ;
122
- ( r, ecx)
123
- }
124
-
125
110
// Returns a pointer to where the result lives
126
111
fn eval_body_using_ecx < ' mir , ' tcx > (
127
112
ecx : & mut CompileTimeEvalContext < ' _ , ' mir , ' tcx > ,
128
113
cid : GlobalId < ' tcx > ,
129
- mir : Option < & ' mir mir:: Mir < ' tcx > > ,
114
+ mir : & ' mir mir:: Mir < ' tcx > ,
130
115
param_env : ty:: ParamEnv < ' tcx > ,
131
116
) -> EvalResult < ' tcx , MPlaceTy < ' tcx > > {
132
117
debug ! ( "eval_body_using_ecx: {:?}, {:?}" , cid, param_env) ;
133
118
let tcx = ecx. tcx . tcx ;
134
- let mut mir = match mir {
135
- Some ( mir) => mir,
136
- None => ecx. load_mir ( cid. instance . def ) ?,
137
- } ;
138
- if let Some ( index) = cid. promoted {
139
- mir = & mir. promoted [ index] ;
140
- }
141
119
let layout = ecx. layout_of ( mir. return_ty ( ) . subst ( tcx, cid. instance . substs ) ) ?;
142
120
assert ! ( !layout. is_unsized( ) ) ;
143
121
let ret = ecx. allocate ( layout, MemoryKind :: Stack ) ;
@@ -618,8 +596,19 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
618
596
return Err ( ErrorHandled :: Reported ) ;
619
597
}
620
598
621
- let ( res, ecx) = eval_body_and_ecx ( tcx, cid, None , key. param_env ) ;
622
- res. and_then ( |place| {
599
+ let span = tcx. def_span ( cid. instance . def_id ( ) ) ;
600
+ let mut ecx = InterpretCx :: new ( tcx. at ( span) , key. param_env , CompileTimeInterpreter :: new ( ) ) ;
601
+
602
+ let res = ecx. load_mir ( cid. instance . def ) ;
603
+ res. map ( |mir| {
604
+ if let Some ( index) = cid. promoted {
605
+ & mir. promoted [ index]
606
+ } else {
607
+ mir
608
+ }
609
+ } ) . and_then (
610
+ |mir| eval_body_using_ecx ( & mut ecx, cid, mir, key. param_env )
611
+ ) . and_then ( |place| {
623
612
Ok ( RawConst {
624
613
alloc_id : place. to_ptr ( ) . expect ( "we allocated this ptr!" ) . alloc_id ,
625
614
ty : place. layout . ty
0 commit comments