Skip to content

Commit 4887eb7

Browse files
committed
Added panics for unreachable states for expectations (RFC 2383)
1 parent 3414ad9 commit 4887eb7

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

compiler/rustc_errors/src/lib.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -942,18 +942,22 @@ impl Handler {
942942

943943
let mut inner = self.inner.borrow_mut();
944944
for mut diag in diags.into_iter() {
945-
if let Some(mut unstable_id) = diag.level.get_expectation_id() {
946-
let lint_index = unstable_id.get_lint_index();
947-
948-
// The unstable to stable map only maps the unstable it to a stable id
949-
// the lint index is manually transferred here.
950-
unstable_id.set_lint_index(None);
951-
if let Some(mut stable_id) = unstable_to_stable.get(&unstable_id).map(|id| *id) {
952-
stable_id.set_lint_index(lint_index);
953-
diag.level = Level::Expect(stable_id);
954-
inner.fulfilled_expectations.insert(stable_id);
955-
}
956-
}
945+
let mut unstable_id = diag
946+
.level
947+
.get_expectation_id()
948+
.expect("all diagnostics inside `unstable_expect_diagnostics` must have a `LintExpectationId`");
949+
950+
// The unstable to stable map only maps the unstable it to a stable id
951+
// the lint index is manually transferred here.
952+
let lint_index = unstable_id.get_lint_index();
953+
unstable_id.set_lint_index(None);
954+
let mut stable_id = *unstable_to_stable
955+
.get(&unstable_id)
956+
.expect("each unstable `LintExpectationId` must have a matching stable id");
957+
958+
stable_id.set_lint_index(lint_index);
959+
diag.level = Level::Expect(stable_id);
960+
inner.fulfilled_expectations.insert(stable_id);
957961

958962
(*TRACK_DIAGNOSTICS)(&diag);
959963
}

compiler/rustc_lint/src/expect.rs

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub fn check_expectations(tcx: TyCtxt<'_>) {
2020
// holds stable ids
2121
if let LintExpectationId::Stable { hir_id, .. } = id {
2222
emit_unfulfilled_expectation_lint(tcx, *hir_id, expectation);
23+
} else {
24+
unreachable!("at this stage all `LintExpectationId`s are stable");
2325
}
2426
}
2527
}

0 commit comments

Comments
 (0)