2022-11-10 19:32:30 -05:00
|
|
|
use crate::lints::{Expectation, ExpectationNote};
|
2023-05-15 06:24:45 +02:00
|
|
|
use rustc_middle::query::Providers;
|
2022-11-09 18:22:48 -05:00
|
|
|
use rustc_middle::ty::TyCtxt;
|
|
|
|
use rustc_session::lint::builtin::UNFULFILLED_LINT_EXPECTATIONS;
|
2021-08-06 23:36:33 +02:00
|
|
|
use rustc_session::lint::LintExpectationId;
|
|
|
|
use rustc_span::symbol::sym;
|
2022-03-29 00:10:45 +02:00
|
|
|
use rustc_span::Symbol;
|
2021-08-06 23:36:33 +02:00
|
|
|
|
2022-03-29 00:10:45 +02:00
|
|
|
pub(crate) fn provide(providers: &mut Providers) {
|
|
|
|
*providers = Providers { check_expectations, ..*providers };
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option<Symbol>) {
|
2022-12-05 17:52:17 +00:00
|
|
|
if !tcx.features().enabled(sym::lint_reasons) {
|
2021-08-06 23:36:33 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-22 16:48:36 +00:00
|
|
|
let lint_expectations = tcx.lint_expectations(());
|
2021-08-06 23:36:33 +02:00
|
|
|
let fulfilled_expectations = tcx.sess.diagnostic().steal_fulfilled_expectation_ids();
|
2022-07-22 16:48:36 +00:00
|
|
|
|
|
|
|
tracing::debug!(?lint_expectations, ?fulfilled_expectations);
|
2021-08-06 23:36:33 +02:00
|
|
|
|
|
|
|
for (id, expectation) in lint_expectations {
|
2022-06-05 12:33:45 +02:00
|
|
|
// This check will always be true, since `lint_expectations` only
|
|
|
|
// holds stable ids
|
|
|
|
if let LintExpectationId::Stable { hir_id, .. } = id {
|
|
|
|
if !fulfilled_expectations.contains(&id)
|
|
|
|
&& tool_filter.map_or(true, |filter| expectation.lint_tool == Some(filter))
|
|
|
|
{
|
2022-11-10 19:32:30 -05:00
|
|
|
let rationale = expectation.reason.map(|rationale| ExpectationNote { rationale });
|
|
|
|
let note = expectation.is_unfulfilled_lint_expectations.then_some(());
|
2022-11-09 18:22:48 -05:00
|
|
|
tcx.emit_spanned_lint(
|
|
|
|
UNFULFILLED_LINT_EXPECTATIONS,
|
|
|
|
*hir_id,
|
|
|
|
expectation.emission_span,
|
2022-11-10 19:32:30 -05:00
|
|
|
Expectation { rationale, note },
|
2022-11-09 18:22:48 -05:00
|
|
|
);
|
2021-11-25 17:45:11 +01:00
|
|
|
}
|
2022-06-05 12:33:45 +02:00
|
|
|
} else {
|
|
|
|
unreachable!("at this stage all `LintExpectationId`s are stable");
|
2021-08-06 23:36:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|