@@ -519,6 +519,11 @@ fn default_track_diagnostic(diag: Diagnostic, f: &mut dyn FnMut(Diagnostic)) {
519
519
pub static TRACK_DIAGNOSTIC : AtomicRef < fn ( Diagnostic , & mut dyn FnMut ( Diagnostic ) ) > =
520
520
AtomicRef :: new ( & ( default_track_diagnostic as _ ) ) ;
521
521
522
+ enum DelayedBugKind {
523
+ Normal ,
524
+ GoodPath ,
525
+ }
526
+
522
527
#[ derive( Copy , Clone , Default ) ]
523
528
pub struct DiagCtxtFlags {
524
529
/// If false, warning-level lints are suppressed.
@@ -541,8 +546,7 @@ impl Drop for DiagCtxtInner {
541
546
self . emit_stashed_diagnostics ( ) ;
542
547
543
548
if !self . has_errors ( ) {
544
- let bugs = std:: mem:: replace ( & mut self . span_delayed_bugs , Vec :: new ( ) ) ;
545
- self . flush_delayed ( bugs, "no errors encountered even though `span_delayed_bug` issued" ) ;
549
+ self . flush_delayed ( DelayedBugKind :: Normal )
546
550
}
547
551
548
552
// FIXME(eddyb) this explains what `good_path_delayed_bugs` are!
@@ -551,11 +555,7 @@ impl Drop for DiagCtxtInner {
551
555
// lints can be `#[allow]`'d, potentially leading to this triggering.
552
556
// Also, "good path" should be replaced with a better naming.
553
557
if !self . has_printed && !self . suppressed_expected_diag && !std:: thread:: panicking ( ) {
554
- let bugs = std:: mem:: replace ( & mut self . good_path_delayed_bugs , Vec :: new ( ) ) ;
555
- self . flush_delayed (
556
- bugs,
557
- "no warnings or errors encountered even though `good_path_delayed_bugs` issued" ,
558
- ) ;
558
+ self . flush_delayed ( DelayedBugKind :: GoodPath ) ;
559
559
}
560
560
561
561
if self . check_unstable_expect_diagnostics {
@@ -1218,9 +1218,7 @@ impl DiagCtxt {
1218
1218
}
1219
1219
1220
1220
pub fn flush_delayed ( & self ) {
1221
- let mut inner = self . inner . borrow_mut ( ) ;
1222
- let bugs = std:: mem:: replace ( & mut inner. span_delayed_bugs , Vec :: new ( ) ) ;
1223
- inner. flush_delayed ( bugs, "no errors encountered even though `span_delayed_bug` issued" ) ;
1221
+ self . inner . borrow_mut ( ) . flush_delayed ( DelayedBugKind :: Normal ) ;
1224
1222
}
1225
1223
}
1226
1224
@@ -1396,11 +1394,18 @@ impl DiagCtxtInner {
1396
1394
self . emit_diagnostic ( Diagnostic :: new ( FailureNote , msg) ) ;
1397
1395
}
1398
1396
1399
- fn flush_delayed (
1400
- & mut self ,
1401
- bugs : Vec < DelayedDiagnostic > ,
1402
- explanation : impl Into < DiagnosticMessage > + Copy ,
1403
- ) {
1397
+ fn flush_delayed ( & mut self , kind : DelayedBugKind ) {
1398
+ let ( bugs, explanation) = match kind {
1399
+ DelayedBugKind :: Normal => (
1400
+ std:: mem:: take ( & mut self . span_delayed_bugs ) ,
1401
+ "no errors encountered even though `span_delayed_bug` issued" ,
1402
+ ) ,
1403
+ DelayedBugKind :: GoodPath => (
1404
+ std:: mem:: take ( & mut self . good_path_delayed_bugs ) ,
1405
+ "no warnings or errors encountered even though `good_path_delayed_bugs` issued" ,
1406
+ ) ,
1407
+ } ;
1408
+
1404
1409
if bugs. is_empty ( ) {
1405
1410
return ;
1406
1411
}
0 commit comments