@@ -473,10 +473,12 @@ pub enum StashKey {
473
473
CallAssocMethod ,
474
474
}
475
475
476
- fn default_track_diagnostic ( _: & Diagnostic ) { }
476
+ fn default_track_diagnostic ( d : & mut Diagnostic , f : & mut dyn FnMut ( & mut Diagnostic ) ) {
477
+ ( * f) ( d)
478
+ }
477
479
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 _ ) ) ;
480
482
481
483
#[ derive( Copy , Clone , Default ) ]
482
484
pub struct HandlerFlags {
@@ -1290,67 +1292,69 @@ impl HandlerInner {
1290
1292
&& !diagnostic. is_force_warn ( )
1291
1293
{
1292
1294
if diagnostic. has_future_breakage ( ) {
1293
- ( * TRACK_DIAGNOSTICS ) ( diagnostic) ;
1295
+ ( * TRACK_DIAGNOSTICS ) ( diagnostic, & mut |_| { } ) ;
1294
1296
}
1295
1297
return None ;
1296
1298
}
1297
1299
1298
- ( * TRACK_DIAGNOSTICS ) ( diagnostic) ;
1299
-
1300
1300
if matches ! ( diagnostic. level, Level :: Expect ( _) | Level :: Allow ) {
1301
+ ( * TRACK_DIAGNOSTICS ) ( diagnostic, & mut |_| { } ) ;
1301
1302
return None ;
1302
1303
}
1303
1304
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
+ }
1314
1310
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 | {
1325
1312
let mut hasher = StableHasher :: new ( ) ;
1326
- sub . hash ( & mut hasher) ;
1313
+ diagnostic . hash ( & mut hasher) ;
1327
1314
let diagnostic_hash = hasher. finish ( ) ;
1328
- debug ! ( ?diagnostic_hash) ;
1329
- !self . emitted_diagnostics . insert ( diagnostic_hash)
1315
+ !this. emitted_diagnostics . insert ( diagnostic_hash)
1330
1316
} ;
1331
1317
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
+ }
1339
1343
}
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 ( ) ) ;
1344
1352
} else {
1345
- self . bump_err_count ( ) ;
1353
+ self . bump_warn_count ( ) ;
1346
1354
}
1355
+ } ) ;
1347
1356
1348
- Some ( ErrorGuaranteed :: unchecked_claim_error_was_emitted ( ) )
1349
- } else {
1350
- self . bump_warn_count ( ) ;
1351
-
1352
- None
1353
- }
1357
+ guaranteed
1354
1358
}
1355
1359
1356
1360
fn emit_artifact_notification ( & mut self , path : & Path , artifact_type : & str ) {
0 commit comments