From 64d98f8ee037282c35007b64c2649055c56af1db Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:03 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_lint/src/expect.rs | 42 +++++++++++---------------------------- 1 file changed, 12 insertions(+), 30 deletions(-) (limited to 'compiler/rustc_lint/src/expect.rs') diff --git a/compiler/rustc_lint/src/expect.rs b/compiler/rustc_lint/src/expect.rs index cf8f31bcb..e9eb14ea1 100644 --- a/compiler/rustc_lint/src/expect.rs +++ b/compiler/rustc_lint/src/expect.rs @@ -1,8 +1,7 @@ -use crate::builtin; -use rustc_errors::fluent; -use rustc_hir::HirId; +use crate::lints::{Expectation, ExpectationNote}; use rustc_middle::ty::query::Providers; -use rustc_middle::{lint::LintExpectation, ty::TyCtxt}; +use rustc_middle::ty::TyCtxt; +use rustc_session::lint::builtin::UNFULFILLED_LINT_EXPECTATIONS; use rustc_session::lint::LintExpectationId; use rustc_span::symbol::sym; use rustc_span::Symbol; @@ -12,7 +11,7 @@ pub(crate) fn provide(providers: &mut Providers) { } fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option) { - if !tcx.sess.features_untracked().enabled(sym::lint_reasons) { + if !tcx.features().enabled(sym::lint_reasons) { return; } @@ -28,34 +27,17 @@ fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option) { if !fulfilled_expectations.contains(&id) && tool_filter.map_or(true, |filter| expectation.lint_tool == Some(filter)) { - emit_unfulfilled_expectation_lint(tcx, *hir_id, expectation); + let rationale = expectation.reason.map(|rationale| ExpectationNote { rationale }); + let note = expectation.is_unfulfilled_lint_expectations.then_some(()); + tcx.emit_spanned_lint( + UNFULFILLED_LINT_EXPECTATIONS, + *hir_id, + expectation.emission_span, + Expectation { rationale, note }, + ); } } else { unreachable!("at this stage all `LintExpectationId`s are stable"); } } } - -fn emit_unfulfilled_expectation_lint( - tcx: TyCtxt<'_>, - hir_id: HirId, - expectation: &LintExpectation, -) { - tcx.struct_span_lint_hir( - builtin::UNFULFILLED_LINT_EXPECTATIONS, - hir_id, - expectation.emission_span, - fluent::lint_expectation, - |lint| { - if let Some(rationale) = expectation.reason { - lint.note(rationale.as_str()); - } - - if expectation.is_unfulfilled_lint_expectations { - lint.note(fluent::note); - } - - lint - }, - ); -} -- cgit v1.2.3