@@ -531,12 +531,18 @@ pub enum StashKey {
531531 UndeterminedMacroResolution ,
532532}
533533
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 {
535535 ( * f) ( diag)
536536}
537537
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 _ ) ) ;
540546
541547#[ derive( Copy , Clone , Default ) ]
542548pub struct DiagCtxtFlags {
@@ -1346,19 +1352,18 @@ impl DiagCtxtInner {
13461352 }
13471353 Warning if !self . flags . can_emit_warnings => {
13481354 if diagnostic. has_future_breakage ( ) {
1349- ( * TRACK_DIAGNOSTIC ) ( diagnostic, & mut |_| { } ) ;
1355+ TRACK_DIAGNOSTIC ( diagnostic, & mut |_| None ) ;
13501356 }
13511357 return None ;
13521358 }
13531359 Allow | Expect ( _) => {
1354- ( * TRACK_DIAGNOSTIC ) ( diagnostic, & mut |_| { } ) ;
1360+ TRACK_DIAGNOSTIC ( diagnostic, & mut |_| None ) ;
13551361 return None ;
13561362 }
13571363 _ => { }
13581364 }
13591365
1360- let mut guaranteed = None ;
1361- ( * TRACK_DIAGNOSTIC ) ( diagnostic, & mut |mut diagnostic| {
1366+ TRACK_DIAGNOSTIC ( diagnostic, & mut |mut diagnostic| {
13621367 if let Some ( code) = diagnostic. code {
13631368 self . emitted_diagnostic_codes . insert ( code) ;
13641369 }
@@ -1422,17 +1427,17 @@ impl DiagCtxtInner {
14221427 // `ErrorGuaranteed` for errors and lint errors originates.
14231428 #[ allow( deprecated) ]
14241429 let guar = ErrorGuaranteed :: unchecked_error_guaranteed ( ) ;
1425- guaranteed = Some ( guar) ;
14261430 if is_lint {
14271431 self . lint_err_guars . push ( guar) ;
14281432 } else {
14291433 self . err_guars . push ( guar) ;
14301434 }
14311435 self . panic_if_treat_err_as_bug ( ) ;
1436+ Some ( guar)
1437+ } else {
1438+ None
14321439 }
1433- } ) ;
1434-
1435- guaranteed
1440+ } )
14361441 }
14371442
14381443 fn treat_err_as_bug ( & self ) -> bool {
0 commit comments