@@ -452,6 +452,10 @@ fn mir_promoted(
452452 tcx : TyCtxt < ' _ > ,
453453 def : LocalDefId ,
454454) -> ( & Steal < Body < ' _ > > , & Steal < IndexVec < Promoted , Body < ' _ > > > ) {
455+ if tcx. is_trivial_const ( def) . is_some ( ) {
456+ panic ! ( "Tried to get MIR of a trivial const" ) ;
457+ }
458+
455459 // Ensure that we compute the `mir_const_qualif` for constants at
456460 // this point, before we steal the mir-const result.
457461 // Also this means promotion can rely on all const checks having been done.
@@ -479,7 +483,9 @@ fn mir_promoted(
479483 tcx. ensure_done ( ) . coroutine_by_move_body_def_id ( def) ;
480484 }
481485
486+ // the `is_trivial_const` uses mir_built, so make sure it is run.
482487 tcx. ensure_done ( ) . is_trivial_const ( def) ;
488+
483489 let mut body = tcx. mir_built ( def) . steal ( ) ;
484490 if let Some ( error_reported) = const_qualifs. tainted_by_errors {
485491 body. tainted_by_errors = Some ( error_reported) ;
@@ -542,9 +548,6 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: LocalDefId) -> Body<'_> {
542548/// mir borrowck *before* doing so in order to ensure that borrowck can be run and doesn't
543549/// end up missing the source MIR due to stealing happening.
544550fn mir_drops_elaborated_and_const_checked ( tcx : TyCtxt < ' _ > , def : LocalDefId ) -> & Steal < Body < ' _ > > {
545- if tcx. is_trivial_const ( def) . is_some ( ) {
546- panic ! ( "Tried to get mir_for_ctfe of a trivial const" ) ;
547- }
548551 if tcx. is_coroutine ( def. to_def_id ( ) ) {
549552 tcx. ensure_done ( ) . mir_coroutine_witnesses ( def) ;
550553 }
0 commit comments