Replace TyCtxt::node_span_lint with emit_node_span_lint in rustc_borrowck

This commit is contained in:
Guillaume Gomez
2026-02-25 13:53:41 +01:00
parent 5edbf6a9f9
commit 4803bb96c1
2 changed files with 24 additions and 12 deletions
+7 -6
View File
@@ -27,7 +27,6 @@
use rustc_data_structures::frozen::Frozen;
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::graph::dominators::Dominators;
use rustc_errors::LintDiagnostic;
use rustc_hir as hir;
use rustc_hir::CRATE_HIR_ID;
use rustc_hir::def_id::LocalDefId;
@@ -715,7 +714,7 @@ fn deref(&self) -> &Self::Target {
}
}
struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
pub(crate) struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
root_cx: &'a mut BorrowCheckRootCtxt<'tcx>,
infcx: &'infcx BorrowckInferCtxt<'tcx>,
body: &'a Body<'tcx>,
@@ -1428,13 +1427,15 @@ fn check_backward_incompatible_drop(
borrow,
Some((WriteKind::StorageDeadOrDrop, place)),
);
this.infcx.tcx.node_span_lint(
this.infcx.tcx.emit_node_span_lint(
TAIL_EXPR_DROP_ORDER,
CRATE_HIR_ID,
borrowed,
|diag| {
session_diagnostics::TailExprDropOrder { borrowed }.decorate_lint(diag);
explain.add_explanation_to_diagnostic(&this, diag, "", None, None);
session_diagnostics::TailExprDropOrder {
borrowed,
callback: |diag| {
explain.add_explanation_to_diagnostic(&this, diag, "", None, None);
},
},
);
// We may stop at the first case
@@ -1,6 +1,6 @@
use rustc_errors::MultiSpan;
use rustc_errors::codes::*;
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, Level, MultiSpan};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_middle::ty::{GenericArg, Ty};
use rustc_span::Span;
@@ -595,9 +595,20 @@ pub(crate) struct SimdIntrinsicArgConst {
pub intrinsic: String,
}
#[derive(LintDiagnostic)]
#[diag("relative drop order changing in Rust 2024")]
pub(crate) struct TailExprDropOrder {
#[label("this temporary value will be dropped at the end of the block")]
pub(crate) struct TailExprDropOrder<F: FnOnce(&mut Diag<'_, ()>)> {
pub borrowed: Span,
pub callback: F,
}
impl<'a, F: FnOnce(&mut Diag<'_, ()>)> Diagnostic<'a, ()> for TailExprDropOrder<F> {
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
let Self { borrowed, callback } = self;
let mut diag = Diag::new(dcx, level, "relative drop order changing in Rust 2024")
.with_span_label(
borrowed,
"this temporary value will be dropped at the end of the block",
);
callback(&mut diag);
diag
}
}