Skip to content

Commit

Permalink
Add comments about TRACK_DIAGNOSTIC use.
Browse files Browse the repository at this point in the history
Also add an assertion for the levels allowed with `has_future_breakage`.
  • Loading branch information
nnethercote committed Feb 18, 2024
1 parent 690805a commit c2b6e91
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,10 +1307,13 @@ impl DiagCtxtInner {
// Future breakages aren't emitted if they're Level::Allow,
// but they still need to be constructed and stashed below,
// so they'll trigger the must_produce_diag check.
self.suppressed_expected_diag = true;
assert!(matches!(diagnostic.level, Error | Warning | Allow));
self.future_breakage_diagnostics.push(diagnostic.clone());
}

// We call TRACK_DIAGNOSTIC with an empty closure for the cases that
// return early *and* have some kind of side-effect, except where
// noted.
match diagnostic.level {
Fatal | Error if self.treat_next_err_as_bug() => {
// `Fatal` and `Error` can be promoted to `Bug`.
Expand All @@ -1334,6 +1337,9 @@ impl DiagCtxtInner {
return if let Some(guar) = self.has_errors_or_lint_errors() {
Some(guar)
} else {
// No `TRACK_DIAGNOSTIC` call is needed, because the
// incremental session is deleted if there is a delayed
// bug. This also saves us from cloning the diagnostic.
let backtrace = std::backtrace::Backtrace::capture();
// This `unchecked_error_guaranteed` is valid. It is where the
// `ErrorGuaranteed` for delayed bugs originates.
Expand All @@ -1347,11 +1353,17 @@ impl DiagCtxtInner {
}
Warning if !self.flags.can_emit_warnings => {
if diagnostic.has_future_breakage() {
// The side-effect is at the top of this method.
TRACK_DIAGNOSTIC(diagnostic, &mut |_| None);
}
return None;
}
Allow => {
if diagnostic.has_future_breakage() {
// The side-effect is at the top of this method.
TRACK_DIAGNOSTIC(diagnostic, &mut |_| None);
self.suppressed_expected_diag = true;
}
return None;
}
Expect(expect_id) | ForceWarning(Some(expect_id)) => {
Expand All @@ -1360,6 +1372,9 @@ impl DiagCtxtInner {
// buffered until the `LintExpectationId` is replaced by a
// stable one by the `LintLevelsBuilder`.
if let LintExpectationId::Unstable { .. } = expect_id {
// We don't call TRACK_DIAGNOSTIC because we wait for the
// unstable ID to be updated, whereupon the diagnostic will
// be passed into this method again.
self.unstable_expect_diagnostics.push(diagnostic);
return None;
}
Expand Down

0 comments on commit c2b6e91

Please sign in to comment.