2 use rustc_errors::fluent;
4 use rustc_middle::ty::query::Providers;
5 use rustc_middle::{lint::LintExpectation, ty::TyCtxt};
6 use rustc_session::lint::LintExpectationId;
7 use rustc_span::symbol::sym;
8 use rustc_span::Symbol;
10 pub(crate) fn provide(providers: &mut Providers) {
11 *providers = Providers { check_expectations, ..*providers };
14 fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option<Symbol>) {
15 if !tcx.sess.features_untracked().enabled(sym::lint_reasons) {
19 let lint_expectations = tcx.lint_expectations(());
20 let fulfilled_expectations = tcx.sess.diagnostic().steal_fulfilled_expectation_ids();
22 tracing::debug!(?lint_expectations, ?fulfilled_expectations);
24 for (id, expectation) in lint_expectations {
25 // This check will always be true, since `lint_expectations` only
27 if let LintExpectationId::Stable { hir_id, .. } = id {
28 if !fulfilled_expectations.contains(&id)
29 && tool_filter.map_or(true, |filter| expectation.lint_tool == Some(filter))
31 emit_unfulfilled_expectation_lint(tcx, *hir_id, expectation);
34 unreachable!("at this stage all `LintExpectationId`s are stable");
39 fn emit_unfulfilled_expectation_lint(
42 expectation: &LintExpectation,
44 tcx.struct_span_lint_hir(
45 builtin::UNFULFILLED_LINT_EXPECTATIONS,
47 expectation.emission_span,
49 let mut diag = diag.build(fluent::lint::expectation);
50 if let Some(rationale) = expectation.reason {
51 diag.note(rationale.as_str());
54 if expectation.is_unfulfilled_lint_expectations {
55 diag.note(fluent::lint::note);