3 use rustc_middle::ty::query::Providers;
4 use rustc_middle::{lint::LintExpectation, ty::TyCtxt};
5 use rustc_session::lint::LintExpectationId;
6 use rustc_span::symbol::sym;
7 use rustc_span::Symbol;
9 pub(crate) fn provide(providers: &mut Providers) {
10 *providers = Providers { check_expectations, ..*providers };
13 fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option<Symbol>) {
14 if !tcx.sess.features_untracked().enabled(sym::lint_reasons) {
18 let fulfilled_expectations = tcx.sess.diagnostic().steal_fulfilled_expectation_ids();
19 let lint_expectations = &tcx.lint_levels(()).lint_expectations;
21 for (id, expectation) in lint_expectations {
22 // This check will always be true, since `lint_expectations` only
24 if let LintExpectationId::Stable { hir_id, .. } = id {
25 if !fulfilled_expectations.contains(&id)
26 && tool_filter.map_or(true, |filter| expectation.lint_tool == Some(filter))
28 emit_unfulfilled_expectation_lint(tcx, *hir_id, expectation);
31 unreachable!("at this stage all `LintExpectationId`s are stable");
36 fn emit_unfulfilled_expectation_lint(
39 expectation: &LintExpectation,
41 tcx.struct_span_lint_hir(
42 builtin::UNFULFILLED_LINT_EXPECTATIONS,
44 expectation.emission_span,
46 let mut diag = diag.build("this lint expectation is unfulfilled");
47 if let Some(rationale) = expectation.reason {
48 diag.note(rationale.as_str());
51 if expectation.is_unfulfilled_lint_expectations {
52 diag.note("the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message");