@@ -1360,10 +1360,13 @@ impl DiagCtxtInner {
13601360 // Future breakages aren't emitted if they're Level::Allow,
13611361 // but they still need to be constructed and stashed below,
13621362 // so they'll trigger the must_produce_diag check.
1363- self . suppressed_expected_diag = true ;
1363+ assert ! ( matches! ( diagnostic . level , Error | Warning | Allow ) ) ;
13641364 self . future_breakage_diagnostics . push ( diagnostic. clone ( ) ) ;
13651365 }
13661366
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.
13671370 match diagnostic. level {
13681371 Fatal | Error if self . treat_next_err_as_bug ( ) => {
13691372 // `Fatal` and `Error` can be promoted to `Bug`.
@@ -1387,6 +1390,9 @@ impl DiagCtxtInner {
13871390 return if let Some ( guar) = self . has_errors ( ) {
13881391 Some ( guar)
13891392 } 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.
13901396 let backtrace = std:: backtrace:: Backtrace :: capture ( ) ;
13911397 // This `unchecked_error_guaranteed` is valid. It is where the
13921398 // `ErrorGuaranteed` for delayed bugs originates. See
@@ -1401,11 +1407,17 @@ impl DiagCtxtInner {
14011407 }
14021408 Warning if !self . flags . can_emit_warnings => {
14031409 if diagnostic. has_future_breakage ( ) {
1410+ // The side-effect is at the top of this method.
14041411 TRACK_DIAGNOSTIC ( diagnostic, & mut |_| None ) ;
14051412 }
14061413 return None ;
14071414 }
14081415 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+ }
14091421 return None ;
14101422 }
14111423 Expect ( expect_id) | ForceWarning ( Some ( expect_id) ) => {
@@ -1414,6 +1426,9 @@ impl DiagCtxtInner {
14141426 // buffered until the `LintExpectationId` is replaced by a
14151427 // stable one by the `LintLevelsBuilder`.
14161428 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.
14171432 self . unstable_expect_diagnostics . push ( diagnostic) ;
14181433 return None ;
14191434 }
0 commit comments