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