@@ -40,12 +40,13 @@ use rustc_span::source_map::SourceMap;
4040use rustc_span:: HashStableContext ;
4141use rustc_span:: { Loc , Span } ;
4242
43+ use std:: any:: Any ;
4344use std:: borrow:: Cow ;
45+ use std:: fmt;
4446use std:: hash:: Hash ;
4547use std:: num:: NonZeroUsize ;
4648use std:: panic;
4749use std:: path:: Path ;
48- use std:: { error, fmt} ;
4950
5051use termcolor:: { Color , ColorSpec } ;
5152
@@ -361,16 +362,11 @@ pub use rustc_span::fatal_error::{FatalError, FatalErrorMarker};
361362
362363/// Signifies that the compiler died with an explicit call to `.bug`
363364/// or `.span_bug` rather than a failed assertion, etc.
364- #[ derive( Copy , Clone , Debug ) ]
365365pub struct ExplicitBug ;
366366
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 ;
374370
375371pub use diagnostic:: {
376372 AddToDiagnostic , DecorateLint , Diagnostic , DiagnosticArg , DiagnosticArgValue , DiagnosticId ,
@@ -507,7 +503,11 @@ impl Drop for HandlerInner {
507503
508504 if !self . has_errors ( ) {
509505 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+ ) ;
511511 }
512512
513513 // FIXME(eddyb) this explains what `delayed_good_path_bugs` are!
@@ -520,6 +520,7 @@ impl Drop for HandlerInner {
520520 self . flush_delayed (
521521 bugs. into_iter ( ) . map ( DelayedDiagnostic :: decorate) ,
522522 "no warnings or errors encountered even though `delayed_good_path_bugs` issued" ,
523+ GoodPathBug ,
523524 ) ;
524525 }
525526
@@ -1203,7 +1204,11 @@ impl Handler {
12031204 pub fn flush_delayed ( & self ) {
12041205 let mut inner = self . inner . lock ( ) ;
12051206 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+ ) ;
12071212 }
12081213}
12091214
@@ -1580,6 +1585,7 @@ impl HandlerInner {
15801585 & mut self ,
15811586 bugs : impl IntoIterator < Item = Diagnostic > ,
15821587 explanation : impl Into < DiagnosticMessage > + Copy ,
1588+ panic_with : impl Any + Send + ' static ,
15831589 ) {
15841590 let mut no_bugs = true ;
15851591 for mut bug in bugs {
@@ -1607,7 +1613,7 @@ impl HandlerInner {
16071613
16081614 // Panic with `ExplicitBug` to avoid "unexpected panic" messages.
16091615 if !no_bugs {
1610- panic:: panic_any ( ExplicitBug ) ;
1616+ panic:: panic_any ( panic_with ) ;
16111617 }
16121618 }
16131619
0 commit comments