@@ -1307,10 +1307,13 @@ impl DiagCtxtInner {
1307
1307
// Future breakages aren't emitted if they're Level::Allow,
1308
1308
// but they still need to be constructed and stashed below,
1309
1309
// so they'll trigger the must_produce_diag check.
1310
- self . suppressed_expected_diag = true ;
1310
+ assert ! ( matches! ( diagnostic . level , Error | Warning | Allow ) ) ;
1311
1311
self . future_breakage_diagnostics . push ( diagnostic. clone ( ) ) ;
1312
1312
}
1313
1313
1314
+ // We call TRACK_DIAGNOSTIC with an empty closure for the cases that
1315
+ // return early *and* have some kind of side-effect, except where
1316
+ // noted.
1314
1317
match diagnostic. level {
1315
1318
Fatal | Error if self . treat_next_err_as_bug ( ) => {
1316
1319
// `Fatal` and `Error` can be promoted to `Bug`.
@@ -1334,6 +1337,9 @@ impl DiagCtxtInner {
1334
1337
return if let Some ( guar) = self . has_errors_or_lint_errors ( ) {
1335
1338
Some ( guar)
1336
1339
} else {
1340
+ // No `TRACK_DIAGNOSTIC` call is needed, because the
1341
+ // incremental session is deleted if there is a delayed
1342
+ // bug. This also saves us from cloning the diagnostic.
1337
1343
let backtrace = std:: backtrace:: Backtrace :: capture ( ) ;
1338
1344
// This `unchecked_error_guaranteed` is valid. It is where the
1339
1345
// `ErrorGuaranteed` for delayed bugs originates.
@@ -1347,11 +1353,17 @@ impl DiagCtxtInner {
1347
1353
}
1348
1354
Warning if !self . flags . can_emit_warnings => {
1349
1355
if diagnostic. has_future_breakage ( ) {
1356
+ // The side-effect is at the top of this method.
1350
1357
TRACK_DIAGNOSTIC ( diagnostic, & mut |_| None ) ;
1351
1358
}
1352
1359
return None ;
1353
1360
}
1354
1361
Allow => {
1362
+ if diagnostic. has_future_breakage ( ) {
1363
+ // The side-effect is at the top of this method.
1364
+ TRACK_DIAGNOSTIC ( diagnostic, & mut |_| None ) ;
1365
+ self . suppressed_expected_diag = true ;
1366
+ }
1355
1367
return None ;
1356
1368
}
1357
1369
Expect ( expect_id) | ForceWarning ( Some ( expect_id) ) => {
@@ -1360,6 +1372,9 @@ impl DiagCtxtInner {
1360
1372
// buffered until the `LintExpectationId` is replaced by a
1361
1373
// stable one by the `LintLevelsBuilder`.
1362
1374
if let LintExpectationId :: Unstable { .. } = expect_id {
1375
+ // We don't call TRACK_DIAGNOSTIC because we wait for the
1376
+ // unstable ID to be updated, whereupon the diagnostic will
1377
+ // be passed into this method again.
1363
1378
self . unstable_expect_diagnostics . push ( diagnostic) ;
1364
1379
return None ;
1365
1380
}
0 commit comments