@@ -23,9 +23,9 @@ use rustc_hir::def::{CtorKind, DefKind};
2323use rustc_hir:: def_id:: LocalDefId ;
2424use rustc_index:: IndexVec ;
2525use rustc_middle:: mir:: {
26- AnalysisPhase , Body , CallSource , ClearCrossCrate , ConstOperand , ConstQualifs , LocalDecl ,
27- MirPhase , Operand , Place , ProjectionElem , Promoted , RuntimePhase , Rvalue , START_BLOCK ,
28- SourceInfo , Statement , StatementKind , TerminatorKind ,
26+ AnalysisPhase , Body , CallSource , ClearCrossCrate , ConstOperand , ConstQualifs , ConstValue ,
27+ LocalDecl , MirPhase , Operand , Place , ProjectionElem , Promoted , RuntimePhase , Rvalue ,
28+ START_BLOCK , SourceInfo , Statement , StatementKind , TerminatorKind ,
2929} ;
3030use rustc_middle:: ty:: { self , Ty , TyCtxt , TypeVisitableExt } ;
3131use rustc_middle:: util:: Providers ;
@@ -382,10 +382,13 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def: LocalDefId) -> ConstQualifs {
382382 validator. qualifs_in_return_place ( )
383383}
384384
385- use rustc_middle:: mir:: ConstValue ;
386385fn is_trivial_const < ' tcx > ( body : & Body < ' tcx > ) -> Option < ( ConstValue , Ty < ' tcx > ) > {
387386 use rustc_middle:: mir:: RETURN_PLACE ;
388387
388+ if body. has_opaque_types ( ) {
389+ return None ;
390+ }
391+
389392 if body. basic_blocks . len ( ) != 1 {
390393 return None ;
391394 }
@@ -452,9 +455,10 @@ fn mir_promoted(
452455 tcx : TyCtxt < ' _ > ,
453456 def : LocalDefId ,
454457) -> ( & 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+ debug_assert ! (
459+ tcx. is_trivial_const( def) . is_some( ) ,
460+ "Tried to get mir_promoted of a trivial const"
461+ ) ;
458462
459463 // Ensure that we compute the `mir_const_qualif` for constants at
460464 // this point, before we steal the mir-const result.
@@ -483,7 +487,7 @@ fn mir_promoted(
483487 tcx. ensure_done ( ) . coroutine_by_move_body_def_id ( def) ;
484488 }
485489
486- // the `is_trivial_const` uses mir_built, so make sure it is run.
490+ // the `is_trivial_const` query uses mir_built, so make sure it is run.
487491 tcx. ensure_done ( ) . is_trivial_const ( def) ;
488492
489493 let mut body = tcx. mir_built ( def) . steal ( ) ;
@@ -513,9 +517,10 @@ fn mir_promoted(
513517
514518/// Compute the MIR that is used during CTFE (and thus has no optimizations run on it)
515519fn mir_for_ctfe ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> & Body < ' _ > {
516- if tcx. is_trivial_const ( def_id) . is_some ( ) {
517- panic ! ( "Tried to get mir_for_ctfe of a trivial const" ) ;
518- }
520+ debug_assert ! (
521+ tcx. is_trivial_const( def_id) . is_none( ) ,
522+ "Tried to get mir_for_ctfe of a trivial const"
523+ ) ;
519524 tcx. arena . alloc ( inner_mir_for_ctfe ( tcx, def_id) )
520525}
521526
0 commit comments