@@ -11,12 +11,12 @@ use rustc_infer::traits::{Obligation, ObligationCause};
1111use rustc_middle:: mir:: coverage:: CoverageKind ;
1212use rustc_middle:: mir:: visit:: { MutatingUseContext , NonUseContext , PlaceContext , Visitor } ;
1313use rustc_middle:: mir:: * ;
14+ use rustc_middle:: span_bug;
1415use rustc_middle:: ty:: adjustment:: PointerCoercion ;
1516use rustc_middle:: ty:: print:: with_no_trimmed_paths;
1617use rustc_middle:: ty:: {
1718 self , CoroutineArgsExt , InstanceKind , ScalarInt , Ty , TyCtxt , TypeVisitableExt , Upcast , Variance ,
1819} ;
19- use rustc_middle:: { bug, span_bug} ;
2020use rustc_mir_dataflow:: debuginfo:: debuginfo_locals;
2121use rustc_trait_selection:: traits:: ObligationCtxt ;
2222
@@ -122,18 +122,17 @@ struct CfgChecker<'a, 'tcx> {
122122
123123impl < ' a , ' tcx > CfgChecker < ' a , ' tcx > {
124124 #[ track_caller]
125- fn fail ( & self , location : Location , msg : impl AsRef < str > ) {
125+ fn fail ( & self , location : Location , msg : impl std :: fmt :: Display ) {
126126 // We might see broken MIR when other errors have already occurred.
127- if self . tcx . dcx ( ) . has_errors ( ) . is_none ( ) {
128- span_bug ! (
129- self . body. source_info( location) . span,
127+ // But we may have some cases of errors happening *after* MIR construction,
128+ // for instance because of generic constants or coroutines.
129+ self . tcx . dcx ( ) . span_delayed_bug (
130+ self . body . source_info ( location) . span ,
131+ format ! (
130132 "broken MIR in {:?} ({}) at {:?}:\n {}" ,
131- self . body. source. instance,
132- self . when,
133- location,
134- msg. as_ref( ) ,
135- ) ;
136- }
133+ self . body. source. instance, self . when, location, msg,
134+ ) ,
135+ ) ;
137136 }
138137
139138 fn check_edge ( & mut self , location : Location , bb : BasicBlock , edge_kind : EdgeKind ) {
@@ -1641,7 +1640,11 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
16411640 ty:: Int ( int) => int. normalize ( target_width) . bit_width ( ) . unwrap ( ) ,
16421641 ty:: Char => 32 ,
16431642 ty:: Bool => 1 ,
1644- other => bug ! ( "unhandled type: {:?}" , other) ,
1643+ other => {
1644+ self . fail ( location, format ! ( "unhandled type in SwitchInt {other:?}" ) ) ;
1645+ // Magic number to avoid ICEing.
1646+ 1
1647+ }
16451648 } ) ;
16461649
16471650 for ( value, _) in targets. iter ( ) {
0 commit comments