@@ -1360,10 +1360,13 @@ impl DiagCtxtInner {
1360
1360
// Future breakages aren't emitted if they're Level::Allow,
1361
1361
// but they still need to be constructed and stashed below,
1362
1362
// so they'll trigger the must_produce_diag check.
1363
- self . suppressed_expected_diag = true ;
1363
+ assert ! ( matches! ( diagnostic . level , Error | Warning | Allow ) ) ;
1364
1364
self . future_breakage_diagnostics . push ( diagnostic. clone ( ) ) ;
1365
1365
}
1366
1366
1367
+ // We call TRACK_DIAGNOSTIC with an empty closure for the cases that
1368
+ // return early *and* have some kind of side-effect, except where
1369
+ // noted.
1367
1370
match diagnostic. level {
1368
1371
Fatal | Error if self . treat_next_err_as_bug ( ) => {
1369
1372
// `Fatal` and `Error` can be promoted to `Bug`.
@@ -1387,6 +1390,9 @@ impl DiagCtxtInner {
1387
1390
return if let Some ( guar) = self . has_errors ( ) {
1388
1391
Some ( guar)
1389
1392
} else {
1393
+ // No `TRACK_DIAGNOSTIC` call is needed, because the
1394
+ // incremental session is deleted if there is a delayed
1395
+ // bug. This also saves us from cloning the diagnostic.
1390
1396
let backtrace = std:: backtrace:: Backtrace :: capture ( ) ;
1391
1397
// This `unchecked_error_guaranteed` is valid. It is where the
1392
1398
// `ErrorGuaranteed` for delayed bugs originates. See
@@ -1401,11 +1407,17 @@ impl DiagCtxtInner {
1401
1407
}
1402
1408
Warning if !self . flags . can_emit_warnings => {
1403
1409
if diagnostic. has_future_breakage ( ) {
1410
+ // The side-effect is at the top of this method.
1404
1411
TRACK_DIAGNOSTIC ( diagnostic, & mut |_| None ) ;
1405
1412
}
1406
1413
return None ;
1407
1414
}
1408
1415
Allow => {
1416
+ if diagnostic. has_future_breakage ( ) {
1417
+ // The side-effect is at the top of this method.
1418
+ TRACK_DIAGNOSTIC ( diagnostic, & mut |_| None ) ;
1419
+ self . suppressed_expected_diag = true ;
1420
+ }
1409
1421
return None ;
1410
1422
}
1411
1423
Expect ( expect_id) | ForceWarning ( Some ( expect_id) ) => {
@@ -1414,6 +1426,9 @@ impl DiagCtxtInner {
1414
1426
// buffered until the `LintExpectationId` is replaced by a
1415
1427
// stable one by the `LintLevelsBuilder`.
1416
1428
if let LintExpectationId :: Unstable { .. } = expect_id {
1429
+ // We don't call TRACK_DIAGNOSTIC because we wait for the
1430
+ // unstable ID to be updated, whereupon the diagnostic will
1431
+ // be passed into this method again.
1417
1432
self . unstable_expect_diagnostics . push ( diagnostic) ;
1418
1433
return None ;
1419
1434
}
0 commit comments