@@ -519,7 +519,8 @@ fn default_track_diagnostic(diag: Diagnostic, f: &mut dyn FnMut(Diagnostic)) {
519519pub static TRACK_DIAGNOSTIC : AtomicRef < fn ( Diagnostic , & mut dyn FnMut ( Diagnostic ) ) > =
520520 AtomicRef :: new ( & ( default_track_diagnostic as _ ) ) ;
521521
522- enum DelayedBugKind {
522+ #[ derive( Copy , PartialEq , Eq , Clone , Hash , Debug , Encodable , Decodable ) ]
523+ pub enum DelayedBugKind {
523524 Normal ,
524525 GoodPath ,
525526}
@@ -865,7 +866,8 @@ impl DiagCtxt {
865866 if treat_next_err_as_bug {
866867 self . bug ( msg) ;
867868 }
868- DiagnosticBuilder :: < ErrorGuaranteed > :: new ( self , DelayedBug , msg) . emit ( )
869+ DiagnosticBuilder :: < ErrorGuaranteed > :: new ( self , DelayedBug ( DelayedBugKind :: Normal ) , msg)
870+ . emit ( )
869871 }
870872
871873 /// Like `delayed_bug`, but takes an additional span.
@@ -882,16 +884,15 @@ impl DiagCtxt {
882884 if treat_next_err_as_bug {
883885 self . span_bug ( sp, msg) ;
884886 }
885- DiagnosticBuilder :: < ErrorGuaranteed > :: new ( self , DelayedBug , msg) . with_span ( sp) . emit ( )
887+ DiagnosticBuilder :: < ErrorGuaranteed > :: new ( self , DelayedBug ( DelayedBugKind :: Normal ) , msg)
888+ . with_span ( sp)
889+ . emit ( )
886890 }
887891
888892 // FIXME(eddyb) note the comment inside `impl Drop for DiagCtxtInner`, that's
889893 // where the explanation of what "good path" is (also, it should be renamed).
890894 pub fn good_path_delayed_bug ( & self , msg : impl Into < DiagnosticMessage > ) {
891- let mut inner = self . inner . borrow_mut ( ) ;
892- let diagnostic = Diagnostic :: new ( DelayedBug , msg) ;
893- let backtrace = std:: backtrace:: Backtrace :: capture ( ) ;
894- inner. good_path_delayed_bugs . push ( DelayedDiagnostic :: with_backtrace ( diagnostic, backtrace) ) ;
895+ DiagnosticBuilder :: < ( ) > :: new ( self , DelayedBug ( DelayedBugKind :: GoodPath ) , msg) . emit ( )
895896 }
896897
897898 #[ track_caller]
@@ -1268,17 +1269,27 @@ impl DiagCtxtInner {
12681269 return None ;
12691270 }
12701271
1271- if diagnostic. level == DelayedBug {
1272- // FIXME(eddyb) this should check for `has_errors` and stop pushing
1273- // once *any* errors were emitted (and truncate `span_delayed_bugs`
1274- // when an error is first emitted, also), but maybe there's a case
1275- // in which that's not sound? otherwise this is really inefficient.
1276- let backtrace = std:: backtrace:: Backtrace :: capture ( ) ;
1277- self . span_delayed_bugs
1278- . push ( DelayedDiagnostic :: with_backtrace ( diagnostic. clone ( ) , backtrace) ) ;
1272+ // FIXME(eddyb) this should check for `has_errors` and stop pushing
1273+ // once *any* errors were emitted (and truncate `span_delayed_bugs`
1274+ // when an error is first emitted, also), but maybe there's a case
1275+ // in which that's not sound? otherwise this is really inefficient.
1276+ match diagnostic. level {
1277+ DelayedBug ( DelayedBugKind :: Normal ) => {
1278+ let backtrace = std:: backtrace:: Backtrace :: capture ( ) ;
1279+ self . span_delayed_bugs
1280+ . push ( DelayedDiagnostic :: with_backtrace ( diagnostic. clone ( ) , backtrace) ) ;
12791281
1280- #[ allow( deprecated) ]
1281- return Some ( ErrorGuaranteed :: unchecked_claim_error_was_emitted ( ) ) ;
1282+ #[ allow( deprecated) ]
1283+ return Some ( ErrorGuaranteed :: unchecked_claim_error_was_emitted ( ) ) ;
1284+ }
1285+ DelayedBug ( DelayedBugKind :: GoodPath ) => {
1286+ let backtrace = std:: backtrace:: Backtrace :: capture ( ) ;
1287+ self . good_path_delayed_bugs
1288+ . push ( DelayedDiagnostic :: with_backtrace ( diagnostic. clone ( ) , backtrace) ) ;
1289+
1290+ return None ;
1291+ }
1292+ _ => { }
12821293 }
12831294
12841295 if diagnostic. has_future_breakage ( ) {
@@ -1438,7 +1449,7 @@ impl DiagCtxtInner {
14381449 if backtrace || self . ice_file . is_none ( ) { bug. decorate ( ) } else { bug. inner } ;
14391450
14401451 // "Undelay" the `DelayedBug`s (into plain `Bug`s).
1441- if bug. level != DelayedBug {
1452+ if ! matches ! ( bug. level, DelayedBug ( _ ) ) {
14421453 // NOTE(eddyb) not panicking here because we're already producing
14431454 // an ICE, and the more information the merrier.
14441455 bug. subdiagnostic ( InvalidFlushedDelayedDiagnosticLevel {
@@ -1526,8 +1537,9 @@ pub enum Level {
15261537 /// silently dropped. I.e. "expect other errors are emitted" semantics. Useful on code paths
15271538 /// that should only be reached when compiling erroneous code.
15281539 ///
1529- /// Its `EmissionGuarantee` is `ErrorGuaranteed`.
1530- DelayedBug ,
1540+ /// Its `EmissionGuarantee` is `ErrorGuaranteed` for `Normal` delayed bugs, and `()` for
1541+ /// `GoodPath` delayed bugs.
1542+ DelayedBug ( DelayedBugKind ) ,
15311543
15321544 /// An error that causes an immediate abort. Used for things like configuration errors,
15331545 /// internal overflows, some file operation errors.
@@ -1602,7 +1614,7 @@ impl Level {
16021614 fn color ( self ) -> ColorSpec {
16031615 let mut spec = ColorSpec :: new ( ) ;
16041616 match self {
1605- Bug | DelayedBug | Fatal | Error => {
1617+ Bug | DelayedBug ( _ ) | Fatal | Error => {
16061618 spec. set_fg ( Some ( Color :: Red ) ) . set_intense ( true ) ;
16071619 }
16081620 ForceWarning ( _) | Warning => {
@@ -1622,7 +1634,7 @@ impl Level {
16221634
16231635 pub fn to_str ( self ) -> & ' static str {
16241636 match self {
1625- Bug | DelayedBug => "error: internal compiler error" ,
1637+ Bug | DelayedBug ( _ ) => "error: internal compiler error" ,
16261638 Fatal | Error => "error" ,
16271639 ForceWarning ( _) | Warning => "warning" ,
16281640 Note | OnceNote => "note" ,
0 commit comments