@@ -473,10 +473,12 @@ pub enum StashKey {
473473 CallAssocMethod ,
474474}
475475
476- fn default_track_diagnostic ( _: & Diagnostic ) { }
476+ fn default_track_diagnostic ( d : & mut Diagnostic , f : & mut dyn FnMut ( & mut Diagnostic ) ) {
477+ ( * f) ( d)
478+ }
477479
478- pub static TRACK_DIAGNOSTICS : AtomicRef < fn ( & Diagnostic ) > =
479- AtomicRef :: new ( & ( default_track_diagnostic as fn ( & _ ) ) ) ;
480+ pub static TRACK_DIAGNOSTICS : AtomicRef < fn ( & mut Diagnostic , & mut dyn FnMut ( & mut Diagnostic ) ) > =
481+ AtomicRef :: new ( & ( default_track_diagnostic as _ ) ) ;
480482
481483#[ derive( Copy , Clone , Default ) ]
482484pub struct HandlerFlags {
@@ -1290,67 +1292,69 @@ impl HandlerInner {
12901292 && !diagnostic. is_force_warn ( )
12911293 {
12921294 if diagnostic. has_future_breakage ( ) {
1293- ( * TRACK_DIAGNOSTICS ) ( diagnostic) ;
1295+ ( * TRACK_DIAGNOSTICS ) ( diagnostic, & mut |_| { } ) ;
12941296 }
12951297 return None ;
12961298 }
12971299
1298- ( * TRACK_DIAGNOSTICS ) ( diagnostic) ;
1299-
13001300 if matches ! ( diagnostic. level, Level :: Expect ( _) | Level :: Allow ) {
1301+ ( * TRACK_DIAGNOSTICS ) ( diagnostic, & mut |_| { } ) ;
13011302 return None ;
13021303 }
13031304
1304- if let Some ( ref code) = diagnostic. code {
1305- self . emitted_diagnostic_codes . insert ( code. clone ( ) ) ;
1306- }
1307-
1308- let already_emitted = |this : & mut Self | {
1309- let mut hasher = StableHasher :: new ( ) ;
1310- diagnostic. hash ( & mut hasher) ;
1311- let diagnostic_hash = hasher. finish ( ) ;
1312- !this. emitted_diagnostics . insert ( diagnostic_hash)
1313- } ;
1305+ let mut guaranteed = None ;
1306+ ( * TRACK_DIAGNOSTICS ) ( diagnostic, & mut |diagnostic| {
1307+ if let Some ( ref code) = diagnostic. code {
1308+ self . emitted_diagnostic_codes . insert ( code. clone ( ) ) ;
1309+ }
13141310
1315- // Only emit the diagnostic if we've been asked to deduplicate or
1316- // haven't already emitted an equivalent diagnostic.
1317- if !( self . flags . deduplicate_diagnostics && already_emitted ( self ) ) {
1318- debug ! ( ?diagnostic) ;
1319- debug ! ( ?self . emitted_diagnostics) ;
1320- let already_emitted_sub = |sub : & mut SubDiagnostic | {
1321- debug ! ( ?sub) ;
1322- if sub. level != Level :: OnceNote {
1323- return false ;
1324- }
1311+ let already_emitted = |this : & mut Self | {
13251312 let mut hasher = StableHasher :: new ( ) ;
1326- sub . hash ( & mut hasher) ;
1313+ diagnostic . hash ( & mut hasher) ;
13271314 let diagnostic_hash = hasher. finish ( ) ;
1328- debug ! ( ?diagnostic_hash) ;
1329- !self . emitted_diagnostics . insert ( diagnostic_hash)
1315+ !this. emitted_diagnostics . insert ( diagnostic_hash)
13301316 } ;
13311317
1332- diagnostic. children . drain_filter ( already_emitted_sub) . for_each ( |_| { } ) ;
1333-
1334- self . emitter . emit_diagnostic ( diagnostic) ;
1335- if diagnostic. is_error ( ) {
1336- self . deduplicated_err_count += 1 ;
1337- } else if let Warning ( _) = diagnostic. level {
1338- self . deduplicated_warn_count += 1 ;
1318+ // Only emit the diagnostic if we've been asked to deduplicate or
1319+ // haven't already emitted an equivalent diagnostic.
1320+ if !( self . flags . deduplicate_diagnostics && already_emitted ( self ) ) {
1321+ debug ! ( ?diagnostic) ;
1322+ debug ! ( ?self . emitted_diagnostics) ;
1323+ let already_emitted_sub = |sub : & mut SubDiagnostic | {
1324+ debug ! ( ?sub) ;
1325+ if sub. level != Level :: OnceNote {
1326+ return false ;
1327+ }
1328+ let mut hasher = StableHasher :: new ( ) ;
1329+ sub. hash ( & mut hasher) ;
1330+ let diagnostic_hash = hasher. finish ( ) ;
1331+ debug ! ( ?diagnostic_hash) ;
1332+ !self . emitted_diagnostics . insert ( diagnostic_hash)
1333+ } ;
1334+
1335+ diagnostic. children . drain_filter ( already_emitted_sub) . for_each ( |_| { } ) ;
1336+
1337+ self . emitter . emit_diagnostic ( diagnostic) ;
1338+ if diagnostic. is_error ( ) {
1339+ self . deduplicated_err_count += 1 ;
1340+ } else if let Warning ( _) = diagnostic. level {
1341+ self . deduplicated_warn_count += 1 ;
1342+ }
13391343 }
1340- }
1341- if diagnostic. is_error ( ) {
1342- if matches ! ( diagnostic. level, Level :: Error { lint: true } ) {
1343- self . bump_lint_err_count ( ) ;
1344+ if diagnostic. is_error ( ) {
1345+ if matches ! ( diagnostic. level, Level :: Error { lint: true } ) {
1346+ self . bump_lint_err_count ( ) ;
1347+ } else {
1348+ self . bump_err_count ( ) ;
1349+ }
1350+
1351+ guaranteed = Some ( ErrorGuaranteed :: unchecked_claim_error_was_emitted ( ) ) ;
13441352 } else {
1345- self . bump_err_count ( ) ;
1353+ self . bump_warn_count ( ) ;
13461354 }
1355+ } ) ;
13471356
1348- Some ( ErrorGuaranteed :: unchecked_claim_error_was_emitted ( ) )
1349- } else {
1350- self . bump_warn_count ( ) ;
1351-
1352- None
1353- }
1357+ guaranteed
13541358 }
13551359
13561360 fn emit_artifact_notification ( & mut self , path : & Path , artifact_type : & str ) {
0 commit comments