Skip to content

Commit 47f3f66

Browse files
committed
Update unstable ExpectationIds in stored diagnostics
1 parent 1b14fd3 commit 47f3f66

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

compiler/rustc_errors/src/diagnostic.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use crate::Substitution;
55
use crate::SubstitutionPart;
66
use crate::SuggestionStyle;
77
use crate::ToolMetadata;
8-
use rustc_lint_defs::Applicability;
8+
use rustc_data_structures::stable_map::FxHashMap;
9+
use rustc_lint_defs::{Applicability, LintExpectationId};
910
use rustc_serialize::json::Json;
1011
use rustc_span::{MultiSpan, Span, DUMMY_SP};
1112
use std::fmt;
@@ -137,6 +138,28 @@ impl Diagnostic {
137138
}
138139
}
139140

141+
pub fn update_unstable_expectation_id(
142+
&mut self,
143+
unstable_to_stable: &FxHashMap<LintExpectationId, LintExpectationId>,
144+
) {
145+
if let Level::Expect(expectation_id) = &mut self.level {
146+
if expectation_id.is_stable() {
147+
return;
148+
}
149+
150+
// The unstable to stable map only maps the unstable `AttrId` to a stable `HirId` with an attribute index.
151+
// The lint index inside the attribute is manually transferred here.
152+
let lint_index = expectation_id.get_lint_index();
153+
expectation_id.set_lint_index(None);
154+
let mut stable_id = *unstable_to_stable
155+
.get(&expectation_id)
156+
.expect("each unstable `LintExpectationId` must have a matching stable id");
157+
158+
stable_id.set_lint_index(lint_index);
159+
*expectation_id = stable_id;
160+
}
161+
}
162+
140163
pub fn has_future_breakage(&self) -> bool {
141164
match self.code {
142165
Some(DiagnosticId::Lint { has_future_breakage, .. }) => has_future_breakage,

compiler/rustc_errors/src/lib.rs

+17-12
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,11 @@ impl Drop for HandlerInner {
522522
"no warnings or errors encountered even though `delayed_good_path_bugs` issued",
523523
);
524524
}
525+
526+
assert!(
527+
self.unstable_expect_diagnostics.is_empty(),
528+
"all diagnostics with unstable expectations should have been converted",
529+
);
525530
}
526531
}
527532

@@ -942,25 +947,25 @@ impl Handler {
942947

943948
let mut inner = self.inner.borrow_mut();
944949
for mut diag in diags.into_iter() {
945-
let mut unstable_id = diag
950+
diag.update_unstable_expectation_id(unstable_to_stable);
951+
952+
let stable_id = diag
946953
.level
947954
.get_expectation_id()
948955
.expect("all diagnostics inside `unstable_expect_diagnostics` must have a `LintExpectationId`");
949-
950-
// The unstable to stable map only maps the unstable `AttrId` to a stable `HirId` with an attribute index.
951-
// The lint index inside the attribute 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);
960956
inner.fulfilled_expectations.insert(stable_id);
961957

962958
(*TRACK_DIAGNOSTICS)(&diag);
963959
}
960+
961+
inner
962+
.stashed_diagnostics
963+
.values_mut()
964+
.for_each(|diag| diag.update_unstable_expectation_id(unstable_to_stable));
965+
inner
966+
.future_breakage_diagnostics
967+
.iter_mut()
968+
.for_each(|diag| diag.update_unstable_expectation_id(unstable_to_stable));
964969
}
965970

966971
/// This methods steals all [`LintExpectationId`]s that are stored inside

0 commit comments

Comments
 (0)