diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 2fc057ae3882..bd46a40c02da 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -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 diff --git a/compiler/rustc_borrowck/src/session_diagnostics.rs b/compiler/rustc_borrowck/src/session_diagnostics.rs index eaa41ce1caac..fea5c2b99037 100644 --- a/compiler/rustc_borrowck/src/session_diagnostics.rs +++ b/compiler/rustc_borrowck/src/session_diagnostics.rs @@ -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)> { pub borrowed: Span, + pub callback: F, +} + +impl<'a, F: FnOnce(&mut Diag<'_, ()>)> Diagnostic<'a, ()> for TailExprDropOrder { + 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 + } }