@@ -27,7 +27,7 @@ use rustc_abi::FieldIdx;
2727use rustc_data_structures:: frozen:: Frozen ;
2828use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet } ;
2929use rustc_data_structures:: graph:: dominators:: Dominators ;
30- use rustc_errors:: LintDiagnostic ;
30+ use rustc_errors:: Diagnostic ;
3131use rustc_hir as hir;
3232use rustc_hir:: CRATE_HIR_ID ;
3333use rustc_hir:: def_id:: LocalDefId ;
@@ -1397,6 +1397,26 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
13971397 place : Place < ' tcx > ,
13981398 state : & BorrowckDomain ,
13991399 ) {
1400+ struct Borrowed < ' a , ' b , ' infcx , ' tcx > {
1401+ borrowed : Span ,
1402+ this : & ' a MirBorrowckCtxt < ' b , ' infcx , ' tcx > ,
1403+ explain : crate :: diagnostics:: BorrowExplanation < ' tcx > ,
1404+ }
1405+
1406+ impl < ' a , ' b , ' c , ' infcx , ' tcx : ' c > Diagnostic < ' a , ( ) > for Borrowed < ' b , ' c , ' infcx , ' tcx > {
1407+ fn into_diag (
1408+ self ,
1409+ dcx : rustc_errors:: DiagCtxtHandle < ' a > ,
1410+ level : rustc_errors:: Level ,
1411+ ) -> rustc_errors:: Diag < ' a , ( ) > {
1412+ let Self { borrowed, this, explain } = self ;
1413+ let mut diag =
1414+ session_diagnostics:: TailExprDropOrder { borrowed } . into_diag ( dcx, level) ;
1415+ explain. add_explanation_to_diagnostic ( this, & mut diag, "" , None , None ) ;
1416+ diag
1417+ }
1418+ }
1419+
14001420 let tcx = self . infcx . tcx ;
14011421 // If this type does not need `Drop`, then treat it like a `StorageDead`.
14021422 // This is needed because we track the borrows of refs to thread locals,
@@ -1428,14 +1448,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
14281448 borrow,
14291449 Some ( ( WriteKind :: StorageDeadOrDrop , place) ) ,
14301450 ) ;
1431- this. infcx . tcx . node_span_lint (
1451+ this. infcx . tcx . emit_node_span_lint (
14321452 TAIL_EXPR_DROP_ORDER ,
14331453 CRATE_HIR_ID ,
14341454 borrowed,
1435- |diag| {
1436- session_diagnostics:: TailExprDropOrder { borrowed } . decorate_lint ( diag) ;
1437- explain. add_explanation_to_diagnostic ( & this, diag, "" , None , None ) ;
1438- } ,
1455+ Borrowed { borrowed, this, explain } ,
14391456 ) ;
14401457 // We may stop at the first case
14411458 ControlFlow :: Break ( ( ) )
0 commit comments