@@ -40,7 +40,6 @@ use rustc_span::source_map::SourceMap;
40
40
use rustc_span:: HashStableContext ;
41
41
use rustc_span:: { Loc , Span } ;
42
42
43
- use std:: any:: Any ;
44
43
use std:: borrow:: Cow ;
45
44
use std:: fmt;
46
45
use std:: hash:: Hash ;
@@ -364,9 +363,9 @@ pub use rustc_span::fatal_error::{FatalError, FatalErrorMarker};
364
363
/// or `.span_bug` rather than a failed assertion, etc.
365
364
pub struct ExplicitBug ;
366
365
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 `
368
367
/// rather than a failed assertion, etc.
369
- pub struct GoodPathBug ;
368
+ pub struct DelayedBugPanic ;
370
369
371
370
pub use diagnostic:: {
372
371
AddToDiagnostic , DecorateLint , Diagnostic , DiagnosticArg , DiagnosticArgValue , DiagnosticId ,
@@ -399,7 +398,7 @@ struct HandlerInner {
399
398
warn_count : usize ,
400
399
deduplicated_err_count : usize ,
401
400
emitter : Box < dyn Emitter + sync:: Send > ,
402
- delayed_span_bugs : Vec < Diagnostic > ,
401
+ delayed_span_bugs : Vec < DelayedDiagnostic > ,
403
402
delayed_good_path_bugs : Vec < DelayedDiagnostic > ,
404
403
/// This flag indicates that an expected diagnostic was emitted and suppressed.
405
404
/// This is used for the `delayed_good_path_bugs` check.
@@ -505,11 +504,7 @@ impl Drop for HandlerInner {
505
504
506
505
if !self . has_errors ( ) {
507
506
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" ) ;
513
508
}
514
509
515
510
// FIXME(eddyb) this explains what `delayed_good_path_bugs` are!
@@ -520,9 +515,8 @@ impl Drop for HandlerInner {
520
515
if !self . has_any_message ( ) && !self . suppressed_expected_diag {
521
516
let bugs = std:: mem:: replace ( & mut self . delayed_good_path_bugs , Vec :: new ( ) ) ;
522
517
self . flush_delayed (
523
- bugs. into_iter ( ) . map ( DelayedDiagnostic :: decorate ) ,
518
+ bugs,
524
519
"no warnings or errors encountered even though `delayed_good_path_bugs` issued" ,
525
- GoodPathBug ,
526
520
) ;
527
521
}
528
522
@@ -1223,11 +1217,7 @@ impl Handler {
1223
1217
pub fn flush_delayed ( & self ) {
1224
1218
let mut inner = self . inner . lock ( ) ;
1225
1219
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" ) ;
1231
1221
}
1232
1222
}
1233
1223
@@ -1287,7 +1277,9 @@ impl HandlerInner {
1287
1277
// once *any* errors were emitted (and truncate `delayed_span_bugs`
1288
1278
// when an error is first emitted, also), but maybe there's a case
1289
1279
// 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) ) ;
1291
1283
1292
1284
if !self . flags . report_delayed_bugs {
1293
1285
return Some ( ErrorGuaranteed :: unchecked_claim_error_was_emitted ( ) ) ;
@@ -1562,7 +1554,6 @@ impl HandlerInner {
1562
1554
}
1563
1555
let mut diagnostic = Diagnostic :: new ( Level :: DelayedBug , msg) ;
1564
1556
diagnostic. set_span ( sp. into ( ) ) ;
1565
- diagnostic. note ( & format ! ( "delayed at {}" , std:: panic:: Location :: caller( ) ) ) ;
1566
1557
self . emit_diagnostic ( & mut diagnostic) . unwrap ( )
1567
1558
}
1568
1559
@@ -1605,12 +1596,13 @@ impl HandlerInner {
1605
1596
1606
1597
fn flush_delayed (
1607
1598
& mut self ,
1608
- bugs : impl IntoIterator < Item = Diagnostic > ,
1599
+ bugs : impl IntoIterator < Item = DelayedDiagnostic > ,
1609
1600
explanation : impl Into < DiagnosticMessage > + Copy ,
1610
- panic_with : impl Any + Send + ' static ,
1611
1601
) {
1612
1602
let mut no_bugs = true ;
1613
- for mut bug in bugs {
1603
+ for bug in bugs {
1604
+ let mut bug = bug. decorate ( ) ;
1605
+
1614
1606
if no_bugs {
1615
1607
// Put the overall explanation before the `DelayedBug`s, to
1616
1608
// frame them better (e.g. separate warnings from them).
@@ -1633,9 +1625,9 @@ impl HandlerInner {
1633
1625
self . emit_diagnostic ( & mut bug) ;
1634
1626
}
1635
1627
1636
- // Panic with `ExplicitBug ` to avoid "unexpected panic" messages.
1628
+ // Panic with `DelayedBugPanic ` to avoid "unexpected panic" messages.
1637
1629
if !no_bugs {
1638
- panic:: panic_any ( panic_with ) ;
1630
+ panic:: panic_any ( DelayedBugPanic ) ;
1639
1631
}
1640
1632
}
1641
1633
0 commit comments