@@ -40,7 +40,6 @@ use rustc_span::source_map::SourceMap;
4040use rustc_span:: HashStableContext ;
4141use rustc_span:: { Loc , Span } ;
4242
43- use std:: any:: Any ;
4443use std:: borrow:: Cow ;
4544use std:: fmt;
4645use std:: hash:: Hash ;
@@ -364,9 +363,9 @@ pub use rustc_span::fatal_error::{FatalError, FatalErrorMarker};
364363/// or `.span_bug` rather than a failed assertion, etc.
365364pub struct ExplicitBug ;
366365
367- /// Signifies that the compiler died with an explicit call to `.delay_good_path_bug `
366+ /// Signifies that the compiler died with an explicit call to `.delay_*_bug `
368367/// rather than a failed assertion, etc.
369- pub struct GoodPathBug ;
368+ pub struct DelayedBugPanic ;
370369
371370pub use diagnostic:: {
372371 AddToDiagnostic , DecorateLint , Diagnostic , DiagnosticArg , DiagnosticArgValue , DiagnosticId ,
@@ -399,7 +398,7 @@ struct HandlerInner {
399398 warn_count : usize ,
400399 deduplicated_err_count : usize ,
401400 emitter : Box < dyn Emitter + sync:: Send > ,
402- delayed_span_bugs : Vec < Diagnostic > ,
401+ delayed_span_bugs : Vec < DelayedDiagnostic > ,
403402 delayed_good_path_bugs : Vec < DelayedDiagnostic > ,
404403 /// This flag indicates that an expected diagnostic was emitted and suppressed.
405404 /// This is used for the `delayed_good_path_bugs` check.
@@ -505,11 +504,7 @@ impl Drop for HandlerInner {
505504
506505 if !self . has_errors ( ) {
507506 let bugs = std:: mem:: replace ( & mut self . delayed_span_bugs , Vec :: new ( ) ) ;
508- self . flush_delayed (
509- bugs,
510- "no errors encountered even though `delay_span_bug` issued" ,
511- ExplicitBug ,
512- ) ;
507+ self . flush_delayed ( bugs, "no errors encountered even though `delay_span_bug` issued" ) ;
513508 }
514509
515510 // FIXME(eddyb) this explains what `delayed_good_path_bugs` are!
@@ -520,9 +515,8 @@ impl Drop for HandlerInner {
520515 if !self . has_any_message ( ) && !self . suppressed_expected_diag {
521516 let bugs = std:: mem:: replace ( & mut self . delayed_good_path_bugs , Vec :: new ( ) ) ;
522517 self . flush_delayed (
523- bugs. into_iter ( ) . map ( DelayedDiagnostic :: decorate ) ,
518+ bugs,
524519 "no warnings or errors encountered even though `delayed_good_path_bugs` issued" ,
525- GoodPathBug ,
526520 ) ;
527521 }
528522
@@ -1223,11 +1217,7 @@ impl Handler {
12231217 pub fn flush_delayed ( & self ) {
12241218 let mut inner = self . inner . lock ( ) ;
12251219 let bugs = std:: mem:: replace ( & mut inner. delayed_span_bugs , Vec :: new ( ) ) ;
1226- inner. flush_delayed (
1227- bugs,
1228- "no errors encountered even though `delay_span_bug` issued" ,
1229- ExplicitBug ,
1230- ) ;
1220+ inner. flush_delayed ( bugs, "no errors encountered even though `delay_span_bug` issued" ) ;
12311221 }
12321222}
12331223
@@ -1287,7 +1277,9 @@ impl HandlerInner {
12871277 // once *any* errors were emitted (and truncate `delayed_span_bugs`
12881278 // when an error is first emitted, also), but maybe there's a case
12891279 // in which that's not sound? otherwise this is really inefficient.
1290- self . delayed_span_bugs . push ( diagnostic. clone ( ) ) ;
1280+ let backtrace = std:: backtrace:: Backtrace :: force_capture ( ) ;
1281+ self . delayed_span_bugs
1282+ . push ( DelayedDiagnostic :: with_backtrace ( diagnostic. clone ( ) , backtrace) ) ;
12911283
12921284 if !self . flags . report_delayed_bugs {
12931285 return Some ( ErrorGuaranteed :: unchecked_claim_error_was_emitted ( ) ) ;
@@ -1562,7 +1554,6 @@ impl HandlerInner {
15621554 }
15631555 let mut diagnostic = Diagnostic :: new ( Level :: DelayedBug , msg) ;
15641556 diagnostic. set_span ( sp. into ( ) ) ;
1565- diagnostic. note ( & format ! ( "delayed at {}" , std:: panic:: Location :: caller( ) ) ) ;
15661557 self . emit_diagnostic ( & mut diagnostic) . unwrap ( )
15671558 }
15681559
@@ -1605,12 +1596,13 @@ impl HandlerInner {
16051596
16061597 fn flush_delayed (
16071598 & mut self ,
1608- bugs : impl IntoIterator < Item = Diagnostic > ,
1599+ bugs : impl IntoIterator < Item = DelayedDiagnostic > ,
16091600 explanation : impl Into < DiagnosticMessage > + Copy ,
1610- panic_with : impl Any + Send + ' static ,
16111601 ) {
16121602 let mut no_bugs = true ;
1613- for mut bug in bugs {
1603+ for bug in bugs {
1604+ let mut bug = bug. decorate ( ) ;
1605+
16141606 if no_bugs {
16151607 // Put the overall explanation before the `DelayedBug`s, to
16161608 // frame them better (e.g. separate warnings from them).
@@ -1633,9 +1625,9 @@ impl HandlerInner {
16331625 self . emit_diagnostic ( & mut bug) ;
16341626 }
16351627
1636- // Panic with `ExplicitBug ` to avoid "unexpected panic" messages.
1628+ // Panic with `DelayedBugPanic ` to avoid "unexpected panic" messages.
16371629 if !no_bugs {
1638- panic:: panic_any ( panic_with ) ;
1630+ panic:: panic_any ( DelayedBugPanic ) ;
16391631 }
16401632 }
16411633
0 commit comments