55use std:: borrow:: Cow ;
66
77use rustc_data_structures:: fx:: FxHashSet ;
8+ use rustc_hir:: { CRATE_HIR_ID , HirId } ;
89use rustc_index:: bit_set:: DenseBitSet ;
910use rustc_middle:: mir:: visit:: { PlaceContext , VisitPlacesWith , Visitor } ;
1011use rustc_middle:: mir:: * ;
1112use rustc_middle:: ty:: TyCtxt ;
1213use rustc_mir_dataflow:: impls:: { MaybeStorageDead , MaybeStorageLive , always_storage_live_locals} ;
1314use rustc_mir_dataflow:: { Analysis , ResultsCursor } ;
15+ use rustc_session:: lint:: builtin:: BROKEN_MIR ;
1416
1517pub ( super ) fn lint_body < ' tcx > ( tcx : TyCtxt < ' tcx > , body : & Body < ' tcx > , when : String ) {
1618 let always_live_locals = & always_storage_live_locals ( body) ;
@@ -27,6 +29,11 @@ pub(super) fn lint_body<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, when: String
2729 tcx,
2830 when,
2931 body,
32+ lint_id : body
33+ . source
34+ . def_id ( )
35+ . as_local ( )
36+ . map_or ( CRATE_HIR_ID , |def_id| tcx. local_def_id_to_hir_id ( def_id) ) ,
3037 is_fn_like : tcx. def_kind ( body. source . def_id ( ) ) . is_fn_like ( ) ,
3138 always_live_locals,
3239 maybe_storage_live,
@@ -42,6 +49,7 @@ struct Lint<'a, 'tcx> {
4249 tcx : TyCtxt < ' tcx > ,
4350 when : String ,
4451 body : & ' a Body < ' tcx > ,
52+ lint_id : HirId ,
4553 is_fn_like : bool ,
4654 always_live_locals : & ' a DenseBitSet < Local > ,
4755 maybe_storage_live : ResultsCursor < ' a , ' tcx , MaybeStorageLive < ' a > > ,
@@ -50,19 +58,19 @@ struct Lint<'a, 'tcx> {
5058}
5159
5260impl < ' a , ' tcx > Lint < ' a , ' tcx > {
53- #[ track_caller]
61+ #[ allow( rustc:: untranslatable_diagnostic) ]
62+ #[ allow( rustc:: diagnostic_outside_of_impl) ]
5463 fn fail ( & self , location : Location , msg : impl AsRef < str > ) {
5564 let span = self . body . source_info ( location) . span ;
56- self . tcx . sess . dcx ( ) . span_delayed_bug (
57- span,
58- format ! (
65+ self . tcx . node_span_lint ( BROKEN_MIR , self . lint_id , span, |lint| {
66+ lint. primary_message ( format ! (
5967 "broken MIR in {:?} ({}) at {:?}:\n {}" ,
6068 self . body. source. instance,
6169 self . when,
6270 location,
6371 msg. as_ref( )
64- ) ,
65- ) ;
72+ ) ) ;
73+ } ) ;
6674 }
6775}
6876
0 commit comments