diff options
| author | Michael Goulet <michael@errs.io> | 2025-01-06 03:25:45 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-01-08 16:02:44 +0000 |
| commit | c55eefe8bc51f302cfc89d375198ca7211d4709b (patch) | |
| tree | 40024a316d1007e00dd46abd862919d604cc563d /compiler/rustc_borrowck/src/lib.rs | |
| parent | 4a099b29cdb6a7841019406f0f2b5035a1fd9a08 (diff) | |
| download | rust-c55eefe8bc51f302cfc89d375198ca7211d4709b.tar.gz rust-c55eefe8bc51f302cfc89d375198ca7211d4709b.zip | |
Try to explain borrow for tail expr temporary drop order change in 2024
Diffstat (limited to 'compiler/rustc_borrowck/src/lib.rs')
| -rw-r--r-- | compiler/rustc_borrowck/src/lib.rs | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 8b3870e5cc6..f90f7514102 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -24,6 +24,7 @@ use std::ops::{ControlFlow, Deref}; use rustc_abi::FieldIdx; 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; @@ -1192,17 +1193,25 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> { |borrow_index| borrows_in_scope.contains(borrow_index), |this, _borrow_index, borrow| { if matches!(borrow.kind, BorrowKind::Fake(_)) { - return Control::Continue; + return ControlFlow::Continue(()); } let borrowed = this.retrieve_borrow_spans(borrow).var_or_use_path_span(); - this.infcx.tcx.emit_node_span_lint( + let explain = this.explain_why_borrow_contains_point( + location, + borrow, + Some((WriteKind::StorageDeadOrDrop, place)), + ); + this.infcx.tcx.node_span_lint( TAIL_EXPR_DROP_ORDER, CRATE_HIR_ID, - place_span, - session_diagnostics::TailExprDropOrder { borrowed }, + borrowed, + |diag| { + session_diagnostics::TailExprDropOrder { borrowed }.decorate_lint(diag); + explain.add_explanation_to_diagnostic(&this, diag, "", None, None); + }, ); // We may stop at the first case - Control::Break + ControlFlow::Break(()) }, ); } |
