@@ -534,12 +534,18 @@ pub enum StashKey {
534534 UndeterminedMacroResolution ,
535535}
536536
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 {
538538 ( * f) ( diag)
539539}
540540
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 _ ) ) ;
543549
544550#[ derive( Copy , Clone , Default ) ]
545551pub struct DiagCtxtFlags {
@@ -1349,19 +1355,18 @@ impl DiagCtxtInner {
13491355 }
13501356 Warning if !self . flags . can_emit_warnings => {
13511357 if diagnostic. has_future_breakage ( ) {
1352- ( * TRACK_DIAGNOSTIC ) ( diagnostic, & mut |_| { } ) ;
1358+ TRACK_DIAGNOSTIC ( diagnostic, & mut |_| None ) ;
13531359 }
13541360 return None ;
13551361 }
13561362 Allow | Expect ( _) => {
1357- ( * TRACK_DIAGNOSTIC ) ( diagnostic, & mut |_| { } ) ;
1363+ TRACK_DIAGNOSTIC ( diagnostic, & mut |_| None ) ;
13581364 return None ;
13591365 }
13601366 _ => { }
13611367 }
13621368
1363- let mut guaranteed = None ;
1364- ( * TRACK_DIAGNOSTIC ) ( diagnostic, & mut |mut diagnostic| {
1369+ TRACK_DIAGNOSTIC ( diagnostic, & mut |mut diagnostic| {
13651370 if let Some ( code) = diagnostic. code {
13661371 self . emitted_diagnostic_codes . insert ( code) ;
13671372 }
@@ -1425,17 +1430,17 @@ impl DiagCtxtInner {
14251430 // `ErrorGuaranteed` for errors and lint errors originates.
14261431 #[ allow( deprecated) ]
14271432 let guar = ErrorGuaranteed :: unchecked_error_guaranteed ( ) ;
1428- guaranteed = Some ( guar) ;
14291433 if is_lint {
14301434 self . lint_err_guars . push ( guar) ;
14311435 } else {
14321436 self . err_guars . push ( guar) ;
14331437 }
14341438 self . panic_if_treat_err_as_bug ( ) ;
1439+ Some ( guar)
1440+ } else {
1441+ None
14351442 }
1436- } ) ;
1437-
1438- guaranteed
1443+ } )
14391444 }
14401445
14411446 fn treat_err_as_bug ( & self ) -> bool {
0 commit comments