diff options
| author | León Orell Valerian Liehr <me@fmease.dev> | 2025-06-15 23:51:58 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-15 23:51:58 +0200 |
| commit | 07048643ddcb2245ba6251fc65403f308e6c38c4 (patch) | |
| tree | 161db3474e8c9a541c54f01f460100a913b3020a /compiler/rustc_borrowck/src | |
| parent | b83fb800a7ffc321c63ec2f716cef3e15ee6f81b (diff) | |
| parent | 6ff3713e0fc60146a36774b447204677ab7b8d5a (diff) | |
| download | rust-07048643ddcb2245ba6251fc65403f308e6c38c4.tar.gz rust-07048643ddcb2245ba6251fc65403f308e6c38c4.zip | |
Rollup merge of #142543 - Urgau:span-borrowck-semicolon, r=fmease
Suggest adding semicolon in user code rather than macro impl details This PR tries to find the right span (by peeling expansion) so that the suggestion for adding a semicolon is suggested in user code rather than in the expanded code (in the example a macro impl). Fixes rust-lang/rust#139049 r? `@fmease`
Diffstat (limited to 'compiler/rustc_borrowck/src')
| -rw-r--r-- | compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs index a845431faca..c4b0f503664 100644 --- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs +++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs @@ -342,6 +342,10 @@ impl<'tcx> BorrowExplanation<'tcx> { } } } else if let LocalInfo::BlockTailTemp(info) = local_decl.local_info() { + let sp = info + .span + .find_ancestor_in_same_ctxt(local_decl.source_info.span) + .unwrap_or(info.span); if info.tail_result_is_ignored { // #85581: If the first mutable borrow's scope contains // the second borrow, this suggestion isn't helpful. @@ -349,7 +353,7 @@ impl<'tcx> BorrowExplanation<'tcx> { old.to(info.span.shrink_to_hi()).contains(new) }) { err.span_suggestion_verbose( - info.span.shrink_to_hi(), + sp.shrink_to_hi(), "consider adding semicolon after the expression so its \ temporaries are dropped sooner, before the local variables \ declared by the block are dropped", @@ -368,8 +372,8 @@ impl<'tcx> BorrowExplanation<'tcx> { local variable `x` and then make `x` be the expression at the \ end of the block", vec![ - (info.span.shrink_to_lo(), "let x = ".to_string()), - (info.span.shrink_to_hi(), "; x".to_string()), + (sp.shrink_to_lo(), "let x = ".to_string()), + (sp.shrink_to_hi(), "; x".to_string()), ], Applicability::MaybeIncorrect, ); |
