Skip to content

Commit 157e68d

Browse files
committed
Fix delayed_good_path_bug ice for expected diagnostics (RFC 2383)
1 parent 7e9b92c commit 157e68d

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

compiler/rustc_errors/src/lib.rs

+17-12
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,9 @@ struct HandlerInner {
401401
emitter: Box<dyn Emitter + sync::Send>,
402402
delayed_span_bugs: Vec<Diagnostic>,
403403
delayed_good_path_bugs: Vec<DelayedDiagnostic>,
404+
/// This flag indicates that an expected diagnostic was emitted and suppressed.
405+
/// This is used for the `delayed_good_path_bugs` check.
406+
suppressed_expected_diag: bool,
404407

405408
/// This set contains the `DiagnosticId` of all emitted diagnostics to avoid
406409
/// emitting the same diagnostic with extended help (`--teach`) twice, which
@@ -496,7 +499,7 @@ impl Drop for HandlerInner {
496499
// instead of "require some error happened". Sadly that isn't ideal, as
497500
// lints can be `#[allow]`'d, potentially leading to this triggering.
498501
// Also, "good path" should be replaced with a better naming.
499-
if !self.has_any_message() {
502+
if !self.has_any_message() && !self.suppressed_expected_diag {
500503
let bugs = std::mem::replace(&mut self.delayed_good_path_bugs, Vec::new());
501504
self.flush_delayed(
502505
bugs.into_iter().map(DelayedDiagnostic::decorate),
@@ -578,6 +581,7 @@ impl Handler {
578581
emitter,
579582
delayed_span_bugs: Vec::new(),
580583
delayed_good_path_bugs: Vec::new(),
584+
suppressed_expected_diag: false,
581585
taught_diagnostics: Default::default(),
582586
emitted_diagnostic_codes: Default::default(),
583587
emitted_diagnostics: Default::default(),
@@ -1001,20 +1005,20 @@ impl Handler {
10011005
let mut inner = self.inner.borrow_mut();
10021006
let diags = std::mem::take(&mut inner.unstable_expect_diagnostics);
10031007
inner.check_unstable_expect_diagnostics = true;
1004-
if diags.is_empty() {
1005-
return;
1006-
}
10071008

1008-
for mut diag in diags.into_iter() {
1009-
diag.update_unstable_expectation_id(unstable_to_stable);
1009+
if !diags.is_empty() {
1010+
inner.suppressed_expected_diag = true;
1011+
for mut diag in diags.into_iter() {
1012+
diag.update_unstable_expectation_id(unstable_to_stable);
10101013

1011-
let stable_id = diag
1012-
.level
1013-
.get_expectation_id()
1014-
.expect("all diagnostics inside `unstable_expect_diagnostics` must have a `LintExpectationId`");
1015-
inner.fulfilled_expectations.insert(stable_id);
1014+
let stable_id = diag
1015+
.level
1016+
.get_expectation_id()
1017+
.expect("all diagnostics inside `unstable_expect_diagnostics` must have a `LintExpectationId`");
1018+
inner.fulfilled_expectations.insert(stable_id);
10161019

1017-
(*TRACK_DIAGNOSTICS)(&diag);
1020+
(*TRACK_DIAGNOSTICS)(&diag);
1021+
}
10181022
}
10191023

10201024
inner
@@ -1101,6 +1105,7 @@ impl HandlerInner {
11011105
(*TRACK_DIAGNOSTICS)(diagnostic);
11021106

11031107
if let Level::Expect(expectation_id) = diagnostic.level {
1108+
self.suppressed_expected_diag = true;
11041109
self.fulfilled_expectations.insert(expectation_id);
11051110
return None;
11061111
} else if diagnostic.level == Allow {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// check-pass
2+
#![feature(lint_reasons)]
3+
4+
#[expect(drop_bounds)]
5+
fn trigger_rustc_lints<T: Drop>() {
6+
}
7+
8+
fn main() {}

0 commit comments

Comments
 (0)