@@ -534,12 +534,18 @@ pub enum StashKey {
534
534
UndeterminedMacroResolution ,
535
535
}
536
536
537
- fn default_track_diagnostic ( diag : Diagnostic , f : & mut dyn FnMut ( Diagnostic ) ) {
537
+ fn default_track_diagnostic < R > ( diag : Diagnostic , f : & mut dyn FnMut ( Diagnostic ) -> R ) -> R {
538
538
( * f) ( diag)
539
539
}
540
540
541
- pub static TRACK_DIAGNOSTIC : AtomicRef < fn ( Diagnostic , & mut dyn FnMut ( Diagnostic ) ) > =
542
- AtomicRef :: new ( & ( default_track_diagnostic as _ ) ) ;
541
+ /// Diagnostics emitted by `DiagCtxtInner::emit_diagnostic` are passed through this function. Used
542
+ /// for tracking by incremental, to replay diagnostics as necessary.
543
+ pub static TRACK_DIAGNOSTIC : AtomicRef <
544
+ fn (
545
+ Diagnostic ,
546
+ & mut dyn FnMut ( Diagnostic ) -> Option < ErrorGuaranteed > ,
547
+ ) -> Option < ErrorGuaranteed > ,
548
+ > = AtomicRef :: new ( & ( default_track_diagnostic as _ ) ) ;
543
549
544
550
#[ derive( Copy , Clone , Default ) ]
545
551
pub struct DiagCtxtFlags {
@@ -1349,19 +1355,18 @@ impl DiagCtxtInner {
1349
1355
}
1350
1356
Warning if !self . flags . can_emit_warnings => {
1351
1357
if diagnostic. has_future_breakage ( ) {
1352
- ( * TRACK_DIAGNOSTIC ) ( diagnostic, & mut |_| { } ) ;
1358
+ TRACK_DIAGNOSTIC ( diagnostic, & mut |_| None ) ;
1353
1359
}
1354
1360
return None ;
1355
1361
}
1356
1362
Allow | Expect ( _) => {
1357
- ( * TRACK_DIAGNOSTIC ) ( diagnostic, & mut |_| { } ) ;
1363
+ TRACK_DIAGNOSTIC ( diagnostic, & mut |_| None ) ;
1358
1364
return None ;
1359
1365
}
1360
1366
_ => { }
1361
1367
}
1362
1368
1363
- let mut guaranteed = None ;
1364
- ( * TRACK_DIAGNOSTIC ) ( diagnostic, & mut |mut diagnostic| {
1369
+ TRACK_DIAGNOSTIC ( diagnostic, & mut |mut diagnostic| {
1365
1370
if let Some ( code) = diagnostic. code {
1366
1371
self . emitted_diagnostic_codes . insert ( code) ;
1367
1372
}
@@ -1425,17 +1430,17 @@ impl DiagCtxtInner {
1425
1430
// `ErrorGuaranteed` for errors and lint errors originates.
1426
1431
#[ allow( deprecated) ]
1427
1432
let guar = ErrorGuaranteed :: unchecked_error_guaranteed ( ) ;
1428
- guaranteed = Some ( guar) ;
1429
1433
if is_lint {
1430
1434
self . lint_err_guars . push ( guar) ;
1431
1435
} else {
1432
1436
self . err_guars . push ( guar) ;
1433
1437
}
1434
1438
self . panic_if_treat_err_as_bug ( ) ;
1439
+ Some ( guar)
1440
+ } else {
1441
+ None
1435
1442
}
1436
- } ) ;
1437
-
1438
- guaranteed
1443
+ } )
1439
1444
}
1440
1445
1441
1446
fn treat_err_as_bug ( & self ) -> bool {
0 commit comments