Skip to content

Commit 4d9ce73

Browse files
committed
Add comments about TRACK_DIAGNOSTIC use.
Also add an assertion for the levels allowed with `has_future_breakage`.
1 parent 3337105 commit 4d9ce73

File tree

1 file changed

+16
-1
lines changed
  • compiler/rustc_errors/src

1 file changed

+16
-1
lines changed

compiler/rustc_errors/src/lib.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -1304,10 +1304,12 @@ impl DiagCtxtInner {
13041304
// Future breakages aren't emitted if they're Level::Allow,
13051305
// but they still need to be constructed and stashed below,
13061306
// so they'll trigger the must_produce_diag check.
1307-
self.suppressed_expected_diag = true;
1307+
assert!(matches!(diagnostic.level, Error | Warning | Allow));
13081308
self.future_breakage_diagnostics.push(diagnostic.clone());
13091309
}
13101310

1311+
// We call TRACK_DIAGNOSTIC with an empty closure for the cases that
1312+
// return early *and* have some kind of side-effect.
13111313
match diagnostic.level {
13121314
Fatal | Error if self.treat_next_err_as_bug() => {
13131315
// `Fatal` and `Error` can be promoted to `Bug`.
@@ -1331,6 +1333,10 @@ impl DiagCtxtInner {
13311333
return if let Some(guar) = self.has_errors_or_lint_errors() {
13321334
Some(guar)
13331335
} 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.
13341340
let backtrace = std::backtrace::Backtrace::capture();
13351341
// This `unchecked_error_guaranteed` is valid. It is where the
13361342
// `ErrorGuaranteed` for delayed bugs originates.
@@ -1344,11 +1350,17 @@ impl DiagCtxtInner {
13441350
}
13451351
Warning if !self.flags.can_emit_warnings => {
13461352
if diagnostic.has_future_breakage() {
1353+
// The side-effect is at the top of this method.
13471354
TRACK_DIAGNOSTIC(diagnostic, &mut |_| None);
13481355
}
13491356
return None;
13501357
}
13511358
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+
}
13521364
return None;
13531365
}
13541366
Expect(expect_id) | ForceWarning(Some(expect_id)) => {
@@ -1357,6 +1369,9 @@ impl DiagCtxtInner {
13571369
// buffered until the `LintExpectationId` is replaced by a
13581370
// stable one by the `LintLevelsBuilder`.
13591371
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.
13601375
self.unstable_expect_diagnostics.push(diagnostic);
13611376
return None;
13621377
}

0 commit comments

Comments
 (0)