@@ -40,12 +40,13 @@ 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 ;
43
44
use std:: borrow:: Cow ;
45
+ use std:: fmt;
44
46
use std:: hash:: Hash ;
45
47
use std:: num:: NonZeroUsize ;
46
48
use std:: panic;
47
49
use std:: path:: Path ;
48
- use std:: { error, fmt} ;
49
50
50
51
use termcolor:: { Color , ColorSpec } ;
51
52
@@ -361,16 +362,11 @@ pub use rustc_span::fatal_error::{FatalError, FatalErrorMarker};
361
362
362
363
/// Signifies that the compiler died with an explicit call to `.bug`
363
364
/// or `.span_bug` rather than a failed assertion, etc.
364
- #[ derive( Copy , Clone , Debug ) ]
365
365
pub struct ExplicitBug ;
366
366
367
- impl fmt:: Display for ExplicitBug {
368
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
369
- write ! ( f, "parser internal bug" )
370
- }
371
- }
372
-
373
- impl error:: Error for ExplicitBug { }
367
+ /// Signifies that the compiler died with an explicit call to `.delay_good_path_bug`
368
+ /// rather than a failed assertion, etc.
369
+ pub struct GoodPathBug ;
374
370
375
371
pub use diagnostic:: {
376
372
AddToDiagnostic , DecorateLint , Diagnostic , DiagnosticArg , DiagnosticArgValue , DiagnosticId ,
@@ -507,7 +503,11 @@ impl Drop for HandlerInner {
507
503
508
504
if !self . has_errors ( ) {
509
505
let bugs = std:: mem:: replace ( & mut self . delayed_span_bugs , Vec :: new ( ) ) ;
510
- self . flush_delayed ( bugs, "no errors encountered even though `delay_span_bug` issued" ) ;
506
+ self . flush_delayed (
507
+ bugs,
508
+ "no errors encountered even though `delay_span_bug` issued" ,
509
+ ExplicitBug ,
510
+ ) ;
511
511
}
512
512
513
513
// FIXME(eddyb) this explains what `delayed_good_path_bugs` are!
@@ -520,6 +520,7 @@ impl Drop for HandlerInner {
520
520
self . flush_delayed (
521
521
bugs. into_iter ( ) . map ( DelayedDiagnostic :: decorate) ,
522
522
"no warnings or errors encountered even though `delayed_good_path_bugs` issued" ,
523
+ GoodPathBug ,
523
524
) ;
524
525
}
525
526
@@ -1203,7 +1204,11 @@ impl Handler {
1203
1204
pub fn flush_delayed ( & self ) {
1204
1205
let mut inner = self . inner . lock ( ) ;
1205
1206
let bugs = std:: mem:: replace ( & mut inner. delayed_span_bugs , Vec :: new ( ) ) ;
1206
- inner. flush_delayed ( bugs, "no errors encountered even though `delay_span_bug` issued" ) ;
1207
+ inner. flush_delayed (
1208
+ bugs,
1209
+ "no errors encountered even though `delay_span_bug` issued" ,
1210
+ ExplicitBug ,
1211
+ ) ;
1207
1212
}
1208
1213
}
1209
1214
@@ -1580,6 +1585,7 @@ impl HandlerInner {
1580
1585
& mut self ,
1581
1586
bugs : impl IntoIterator < Item = Diagnostic > ,
1582
1587
explanation : impl Into < DiagnosticMessage > + Copy ,
1588
+ panic_with : impl Any + Send + ' static ,
1583
1589
) {
1584
1590
let mut no_bugs = true ;
1585
1591
for mut bug in bugs {
@@ -1607,7 +1613,7 @@ impl HandlerInner {
1607
1613
1608
1614
// Panic with `ExplicitBug` to avoid "unexpected panic" messages.
1609
1615
if !no_bugs {
1610
- panic:: panic_any ( ExplicitBug ) ;
1616
+ panic:: panic_any ( panic_with ) ;
1611
1617
}
1612
1618
}
1613
1619
0 commit comments