3 use rustc_middle::{lint::LintExpectation, ty::TyCtxt};
4 use rustc_session::lint::LintExpectationId;
5 use rustc_span::symbol::sym;
7 pub fn check_expectations(tcx: TyCtxt<'_>) {
8 if !tcx.sess.features_untracked().enabled(sym::lint_reasons) {
12 let fulfilled_expectations = tcx.sess.diagnostic().steal_fulfilled_expectation_ids();
13 let lint_expectations = &tcx.lint_levels(()).lint_expectations;
15 for (id, expectation) in lint_expectations {
16 if !fulfilled_expectations.contains(id) {
17 // This check will always be true, since `lint_expectations` only
19 if let LintExpectationId::Stable { hir_id, .. } = id {
20 emit_unfulfilled_expectation_lint(tcx, *hir_id, expectation);
22 unreachable!("at this stage all `LintExpectationId`s are stable");
28 fn emit_unfulfilled_expectation_lint(
31 expectation: &LintExpectation,
33 tcx.struct_span_lint_hir(
34 builtin::UNFULFILLED_LINT_EXPECTATIONS,
36 expectation.emission_span,
38 let mut diag = diag.build("this lint expectation is unfulfilled");
39 if let Some(rationale) = expectation.reason {
40 diag.note(&rationale.as_str());
43 if expectation.is_unfulfilled_lint_expectations {
44 diag.note("the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message");