1 use crate::lints::{Expectation, ExpectationNote};
2 use rustc_middle::ty::query::Providers;
3 use rustc_middle::ty::TyCtxt;
4 use rustc_session::lint::builtin::UNFULFILLED_LINT_EXPECTATIONS;
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.features().enabled(sym::lint_reasons) {
18 let lint_expectations = tcx.lint_expectations(());
19 let fulfilled_expectations = tcx.sess.diagnostic().steal_fulfilled_expectation_ids();
21 tracing::debug!(?lint_expectations, ?fulfilled_expectations);
23 for (id, expectation) in lint_expectations {
24 // This check will always be true, since `lint_expectations` only
26 if let LintExpectationId::Stable { hir_id, .. } = id {
27 if !fulfilled_expectations.contains(&id)
28 && tool_filter.map_or(true, |filter| expectation.lint_tool == Some(filter))
30 let rationale = expectation.reason.map(|rationale| ExpectationNote { rationale });
31 let note = expectation.is_unfulfilled_lint_expectations.then_some(());
32 tcx.emit_spanned_lint(
33 UNFULFILLED_LINT_EXPECTATIONS,
35 expectation.emission_span,
36 Expectation { rationale, note },
40 unreachable!("at this stage all `LintExpectationId`s are stable");