@@ -1304,10 +1304,12 @@ impl DiagCtxtInner {
1304
1304
// Future breakages aren't emitted if they're Level::Allow,
1305
1305
// but they still need to be constructed and stashed below,
1306
1306
// so they'll trigger the must_produce_diag check.
1307
- self . suppressed_expected_diag = true ;
1307
+ assert ! ( matches! ( diagnostic . level , Error | Warning | Allow ) ) ;
1308
1308
self . future_breakage_diagnostics . push ( diagnostic. clone ( ) ) ;
1309
1309
}
1310
1310
1311
+ // We call TRACK_DIAGNOSTIC with an empty closure for the cases that
1312
+ // return early *and* have some kind of side-effect.
1311
1313
match diagnostic. level {
1312
1314
Fatal | Error if self . treat_next_err_as_bug ( ) => {
1313
1315
// `Fatal` and `Error` can be promoted to `Bug`.
@@ -1331,6 +1333,10 @@ impl DiagCtxtInner {
1331
1333
return if let Some ( guar) = self . has_errors_or_lint_errors ( ) {
1332
1334
Some ( guar)
1333
1335
} else {
1336
+ // Is saving the diagnostic in `delayed_bugs` a notable
1337
+ // side-effect? Should `TRACK_DIAGNOSTIC` be called?
1338
+ // Unclear. Currently we err on the side of "no" to avoid
1339
+ // having to clone the diagnostic.
1334
1340
let backtrace = std:: backtrace:: Backtrace :: capture ( ) ;
1335
1341
// This `unchecked_error_guaranteed` is valid. It is where the
1336
1342
// `ErrorGuaranteed` for delayed bugs originates.
@@ -1344,11 +1350,17 @@ impl DiagCtxtInner {
1344
1350
}
1345
1351
Warning if !self . flags . can_emit_warnings => {
1346
1352
if diagnostic. has_future_breakage ( ) {
1353
+ // The side-effect is at the top of this method.
1347
1354
TRACK_DIAGNOSTIC ( diagnostic, & mut |_| None ) ;
1348
1355
}
1349
1356
return None ;
1350
1357
}
1351
1358
Allow => {
1359
+ if diagnostic. has_future_breakage ( ) {
1360
+ // The side-effect is at the top of this method.
1361
+ TRACK_DIAGNOSTIC ( diagnostic, & mut |_| None ) ;
1362
+ self . suppressed_expected_diag = true ;
1363
+ }
1352
1364
return None ;
1353
1365
}
1354
1366
Expect ( expect_id) | ForceWarning ( Some ( expect_id) ) => {
@@ -1357,6 +1369,9 @@ impl DiagCtxtInner {
1357
1369
// buffered until the `LintExpectationId` is replaced by a
1358
1370
// stable one by the `LintLevelsBuilder`.
1359
1371
if let LintExpectationId :: Unstable { .. } = expect_id {
1372
+ // We don't call TRACK_DIAGNOSTIC because we wait for the
1373
+ // unstable ID to be updated, whereupon the diagnostic will
1374
+ // be passed into this method again.
1360
1375
self . unstable_expect_diagnostics . push ( diagnostic) ;
1361
1376
return None ;
1362
1377
}
0 commit comments