2 use rustc_data_structures::fx::FxHashMap;
3 use rustc_middle::lint::struct_lint_level;
4 use rustc_middle::{lint::LintExpectation, ty::TyCtxt};
5 use rustc_session::lint::LintExpectationId;
6 use rustc_span::symbol::sym;
7 use rustc_span::MultiSpan;
9 pub fn check_expectations(tcx: TyCtxt<'_>) {
10 if !tcx.sess.features_untracked().enabled(sym::lint_reasons) {
14 let fulfilled_expectations = tcx.sess.diagnostic().steal_fulfilled_expectation_ids();
15 let lint_expectations: &FxHashMap<LintExpectationId, LintExpectation> =
16 &tcx.lint_levels(()).lint_expectations;
18 for (id, expectation) in lint_expectations {
19 if fulfilled_expectations.contains(id) {
23 emit_unfulfilled_expectation_lint(tcx, expectation);
27 fn emit_unfulfilled_expectation_lint(tcx: TyCtxt<'_>, expectation: &LintExpectation) {
28 // FIXME: The current implementation doesn't cover cases where the
29 // `unfulfilled_lint_expectations` is actually expected by another lint
30 // expectation. This can be added here as we have the lint level of this
31 // expectation, and we can also mark the lint expectation it would fulfill
32 // as such. This is currently not implemented to get some early feedback
33 // before diving deeper into this.
36 builtin::UNFULFILLED_LINT_EXPECTATIONS,
37 expectation.emission_level,
38 expectation.emission_level_source,
39 Some(MultiSpan::from_span(expectation.emission_span)),
41 let mut diag = diag.build("this lint expectation is unfulfilled");
42 if let Some(rationale) = expectation.reason {
43 diag.note(&rationale.as_str());