@@ -526,12 +526,15 @@ pub enum StashKey {
526526 UndeterminedMacroResolution ,
527527}
528528
529- fn default_track_diagnostic ( diag : DiagInner , f : & mut dyn FnMut ( DiagInner ) ) {
529+ fn default_track_diagnostic < R > ( diag : DiagInner , f : & mut dyn FnMut ( DiagInner ) -> R ) -> R {
530530 ( * f) ( diag)
531531}
532532
533- pub static TRACK_DIAGNOSTIC : AtomicRef < fn ( DiagInner , & mut dyn FnMut ( DiagInner ) ) > =
534- AtomicRef :: new ( & ( default_track_diagnostic as _ ) ) ;
533+ /// Diagnostics emitted by `DiagCtxtInner::emit_diagnostic` are passed through this function. Used
534+ /// for tracking by incremental, to replay diagnostics as necessary.
535+ pub static TRACK_DIAGNOSTIC : AtomicRef <
536+ fn ( DiagInner , & mut dyn FnMut ( DiagInner ) -> Option < ErrorGuaranteed > ) -> Option < ErrorGuaranteed > ,
537+ > = AtomicRef :: new ( & ( default_track_diagnostic as _ ) ) ;
535538
536539#[ derive( Copy , Clone , Default ) ]
537540pub struct DiagCtxtFlags {
@@ -1406,19 +1409,18 @@ impl DiagCtxtInner {
14061409 }
14071410 Warning if !self . flags . can_emit_warnings => {
14081411 if diagnostic. has_future_breakage ( ) {
1409- ( * TRACK_DIAGNOSTIC ) ( diagnostic, & mut |_| { } ) ;
1412+ TRACK_DIAGNOSTIC ( diagnostic, & mut |_| None ) ;
14101413 }
14111414 return None ;
14121415 }
14131416 Allow | Expect ( _) => {
1414- ( * TRACK_DIAGNOSTIC ) ( diagnostic, & mut |_| { } ) ;
1417+ TRACK_DIAGNOSTIC ( diagnostic, & mut |_| None ) ;
14151418 return None ;
14161419 }
14171420 _ => { }
14181421 }
14191422
1420- let mut guaranteed = None ;
1421- ( * TRACK_DIAGNOSTIC ) ( diagnostic, & mut |mut diagnostic| {
1423+ TRACK_DIAGNOSTIC ( diagnostic, & mut |mut diagnostic| {
14221424 if let Some ( code) = diagnostic. code {
14231425 self . emitted_diagnostic_codes . insert ( code) ;
14241426 }
@@ -1481,17 +1483,17 @@ impl DiagCtxtInner {
14811483 // `ErrorGuaranteed` for errors and lint errors originates.
14821484 #[ allow( deprecated) ]
14831485 let guar = ErrorGuaranteed :: unchecked_error_guaranteed ( ) ;
1484- guaranteed = Some ( guar) ;
14851486 if is_lint {
14861487 self . lint_err_guars . push ( guar) ;
14871488 } else {
14881489 self . err_guars . push ( guar) ;
14891490 }
14901491 self . panic_if_treat_err_as_bug ( ) ;
1492+ Some ( guar)
1493+ } else {
1494+ None
14911495 }
1492- } ) ;
1493-
1494- guaranteed
1496+ } )
14951497 }
14961498
14971499 fn treat_err_as_bug ( & self ) -> bool {
0 commit comments