@@ -1307,10 +1307,13 @@ impl DiagCtxtInner {
13071307 // Future breakages aren't emitted if they're Level::Allow,
13081308 // but they still need to be constructed and stashed below,
13091309 // so they'll trigger the must_produce_diag check.
1310- self . suppressed_expected_diag = true ;
1310+ assert ! ( matches! ( diagnostic . level , Error | Warning | Allow ) ) ;
13111311 self . future_breakage_diagnostics . push ( diagnostic. clone ( ) ) ;
13121312 }
13131313
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.
13141317 match diagnostic. level {
13151318 Fatal | Error if self . treat_next_err_as_bug ( ) => {
13161319 // `Fatal` and `Error` can be promoted to `Bug`.
@@ -1334,6 +1337,9 @@ impl DiagCtxtInner {
13341337 return if let Some ( guar) = self . has_errors_or_lint_errors ( ) {
13351338 Some ( guar)
13361339 } 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.
13371343 let backtrace = std:: backtrace:: Backtrace :: capture ( ) ;
13381344 // This `unchecked_error_guaranteed` is valid. It is where the
13391345 // `ErrorGuaranteed` for delayed bugs originates.
@@ -1347,11 +1353,17 @@ impl DiagCtxtInner {
13471353 }
13481354 Warning if !self . flags . can_emit_warnings => {
13491355 if diagnostic. has_future_breakage ( ) {
1356+ // The side-effect is at the top of this method.
13501357 TRACK_DIAGNOSTIC ( diagnostic, & mut |_| None ) ;
13511358 }
13521359 return None ;
13531360 }
13541361 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+ }
13551367 return None ;
13561368 }
13571369 Expect ( expect_id) | ForceWarning ( Some ( expect_id) ) => {
@@ -1360,6 +1372,9 @@ impl DiagCtxtInner {
13601372 // buffered until the `LintExpectationId` is replaced by a
13611373 // stable one by the `LintLevelsBuilder`.
13621374 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.
13631378 self . unstable_expect_diagnostics . push ( diagnostic) ;
13641379 return None ;
13651380 }
0 commit comments