2022-11-09 18:22:48 -05:00
|
|
|
#![deny(rustc::untranslatable_diagnostic)]
|
|
|
|
#![deny(rustc::diagnostic_outside_of_impl)]
|
|
|
|
use crate::lints::Expectation;
|
2022-03-29 00:10:45 +02:00
|
|
|
use rustc_middle::ty::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>) {
|
2021-08-06 23:36:33 +02:00
|
|
|
if !tcx.sess.features_untracked().enabled(sym::lint_reasons) {
|
|
|
|
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-09 18:22:48 -05:00
|
|
|
tcx.emit_spanned_lint(
|
|
|
|
UNFULFILLED_LINT_EXPECTATIONS,
|
|
|
|
*hir_id,
|
|
|
|
expectation.emission_span,
|
|
|
|
Expectation { expectation },
|
|
|
|
);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|