@@ -292,10 +292,8 @@ pub fn eval_to_const_value_raw_provider<'tcx>(
292292 tcx : TyCtxt < ' tcx > ,
293293 key : ty:: PseudoCanonicalInput < ' tcx , GlobalId < ' tcx > > ,
294294) -> :: rustc_middle:: mir:: interpret:: EvalToConstValueResult < ' tcx > {
295- if let Some ( def) = key. value . instance . def_id ( ) . as_local ( ) {
296- if let Some ( value) = tcx. is_trivial_const ( def) {
297- return Ok ( value) ;
298- }
295+ if let Some ( ( value, _ty) ) = tcx. is_trivial_const ( key. value . instance . def_id ( ) ) {
296+ return Ok ( value) ;
299297 }
300298 tcx. eval_to_allocation_raw ( key) . map ( |val| turn_into_const_value ( tcx, val, key) )
301299}
@@ -361,6 +359,7 @@ fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>(
361359 typing_env : ty:: TypingEnv < ' tcx > ,
362360) -> Result < R , ErrorHandled > {
363361 let def = cid. instance . def . def_id ( ) ;
362+
364363 let is_static = tcx. is_static ( def) ;
365364
366365 let mut ecx = InterpCx :: new (
@@ -373,6 +372,18 @@ fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>(
373372 // so we have to reject reading mutable global memory.
374373 CompileTimeMachine :: new ( CanAccessMutGlobal :: from ( is_static) , CheckAlignment :: Error ) ,
375374 ) ;
375+
376+ if let Some ( ( value, ty) ) = tcx. is_trivial_const ( def) {
377+ let layout = ecx. layout_of ( ty) . unwrap ( ) ;
378+ let opty = ecx. const_val_to_op ( value, ty, Some ( layout) ) . unwrap ( ) ;
379+ let res = ecx. allocate ( layout, MemoryKind :: Stack ) . unwrap ( ) ;
380+ ecx. copy_op ( & opty, & res) . unwrap ( ) ;
381+
382+ intern_const_alloc_recursive ( & mut ecx, InternKind :: Constant , & res) . unwrap ( ) ;
383+
384+ return Ok ( R :: make_result ( res, & mut ecx) ) ;
385+ }
386+
376387 let res = ecx. load_mir ( cid. instance . def , cid. promoted ) ;
377388 res. and_then ( |body| eval_body_using_ecx ( & mut ecx, cid, body) )
378389 . report_err ( )
0 commit comments