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 fulfilled_expectations = tcx.sess.diagnostic().steal_fulfilled_expectation_ids();
20 let lint_expectations = &tcx.lint_levels(()).lint_expectations;
22 for (id, expectation) in lint_expectations {
23 // This check will always be true, since `lint_expectations` only
25 if let LintExpectationId::Stable { hir_id, .. } = id {
26 if !fulfilled_expectations.contains(&id)
27 && tool_filter.map_or(true, |filter| expectation.lint_tool == Some(filter))
29 emit_unfulfilled_expectation_lint(tcx, *hir_id, expectation);
32 unreachable!("at this stage all `LintExpectationId`s are stable");
37 fn emit_unfulfilled_expectation_lint(
40 expectation: &LintExpectation,
42 tcx.struct_span_lint_hir(
43 builtin::UNFULFILLED_LINT_EXPECTATIONS,
45 expectation.emission_span,
46 fluent::lint::expectation,
48 if let Some(rationale) = expectation.reason {
49 lint.note(rationale.as_str());
52 if expectation.is_unfulfilled_lint_expectations {
53 lint.note(fluent::lint::note);