1 #![deny(rustc::untranslatable_diagnostic)]
2 #![deny(rustc::diagnostic_outside_of_impl)]
3 use crate::lints::{Expectation, ExpectationNote};
4 use rustc_middle::ty::query::Providers;
5 use rustc_middle::ty::TyCtxt;
6 use rustc_session::lint::builtin::UNFULFILLED_LINT_EXPECTATIONS;
7 use rustc_session::lint::LintExpectationId;
8 use rustc_span::symbol::sym;
9 use rustc_span::Symbol;
11 pub(crate) fn provide(providers: &mut Providers) {
12 *providers = Providers { check_expectations, ..*providers };
15 fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option<Symbol>) {
16 if !tcx.sess.features_untracked().enabled(sym::lint_reasons) {
20 let lint_expectations = tcx.lint_expectations(());
21 let fulfilled_expectations = tcx.sess.diagnostic().steal_fulfilled_expectation_ids();
23 tracing::debug!(?lint_expectations, ?fulfilled_expectations);
25 for (id, expectation) in lint_expectations {
26 // This check will always be true, since `lint_expectations` only
28 if let LintExpectationId::Stable { hir_id, .. } = id {
29 if !fulfilled_expectations.contains(&id)
30 && tool_filter.map_or(true, |filter| expectation.lint_tool == Some(filter))
32 let rationale = expectation.reason.map(|rationale| ExpectationNote { rationale });
33 let note = expectation.is_unfulfilled_lint_expectations.then_some(());
34 tcx.emit_spanned_lint(
35 UNFULFILLED_LINT_EXPECTATIONS,
37 expectation.emission_span,
38 Expectation { rationale, note },
42 unreachable!("at this stage all `LintExpectationId`s are stable");