Skip to content

Commit 1840454

Browse files
authored
Rollup merge of #97718 - xFrednet:95540-delayed-good-path-ice-for-expect, r=wesleywiser
Fix `delayed_good_path_bug` ice for expected diagnostics (RFC 2383) Fixes a small ICE with the `delayed_good_path_bug` check. --- r? ``@wesleywiser`` cc: ``@eddyb`` this might be interesting, since you've added a `FIXME` comment above the modified check which kind of discusses a case like this closes: #95540 cc: #85549
2 parents 52ee2a2 + 157e68d commit 1840454

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
@@ -400,6 +400,9 @@ struct HandlerInner {
400400
emitter: Box<dyn Emitter + sync::Send>,
401401
delayed_span_bugs: Vec<Diagnostic>,
402402
delayed_good_path_bugs: Vec<DelayedDiagnostic>,
403+
/// This flag indicates that an expected diagnostic was emitted and suppressed.
404+
/// This is used for the `delayed_good_path_bugs` check.
405+
suppressed_expected_diag: bool,
403406

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

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

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

1016-
(*TRACK_DIAGNOSTICS)(&diag);
1019+
(*TRACK_DIAGNOSTICS)(&diag);
1020+
}
10171021
}
10181022

10191023
inner
@@ -1100,6 +1104,7 @@ impl HandlerInner {
11001104
(*TRACK_DIAGNOSTICS)(diagnostic);
11011105

11021106
if let Level::Expect(expectation_id) = diagnostic.level {
1107+
self.suppressed_expected_diag = true;
11031108
self.fulfilled_expectations.insert(expectation_id);
11041109
return None;
11051110
} 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)