@@ -292,6 +292,9 @@ 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 ( ( value, _ty) ) = tcx. trivial_const ( key. value . instance . def_id ( ) ) {
296+ return Ok ( value) ;
297+ }
295298 tcx. eval_to_allocation_raw ( key) . map ( |val| turn_into_const_value ( tcx, val, key) )
296299}
297300
@@ -368,6 +371,18 @@ fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>(
368371 // so we have to reject reading mutable global memory.
369372 CompileTimeMachine :: new ( CanAccessMutGlobal :: from ( is_static) , CheckAlignment :: Error ) ,
370373 ) ;
374+
375+ if let Some ( ( value, ty) ) = tcx. trivial_const ( def) {
376+ let layout = ecx. layout_of ( ty) . unwrap ( ) ;
377+ let opty = ecx. const_val_to_op ( value, ty, Some ( layout) ) . unwrap ( ) ;
378+ let res = ecx. allocate ( layout, MemoryKind :: Stack ) . unwrap ( ) ;
379+ ecx. copy_op ( & opty, & res) . unwrap ( ) ;
380+
381+ intern_const_alloc_recursive ( & mut ecx, InternKind :: Constant , & res) . unwrap ( ) ;
382+
383+ return Ok ( R :: make_result ( res, & mut ecx) ) ;
384+ }
385+
371386 let res = ecx. load_mir ( cid. instance . def , cid. promoted ) ;
372387 res. and_then ( |body| eval_body_using_ecx ( & mut ecx, cid, body) )
373388 . report_err ( )
0 commit comments