Skip to content

Commit 7207a7c

Browse files
committed
fix NLL TLS end of function spans
1 parent 7daf4cf commit 7207a7c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3112,12 +3112,22 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
31123112
drop_span, borrow_span
31133113
);
31143114

3115+
// `TerminatorKind::Return`'s span (the `drop_span` here) `lo` can be subtly wrong and point
3116+
// at a single character after the end of the function. This is somehow relied upon in
3117+
// existing diagnostics, and changing this in `rustc_mir_build` makes diagnostics worse in
3118+
// general. We fix these here.
3119+
let lo = drop_span.lo().0;
3120+
let end_of_function = if lo == drop_span.hi().0 && lo > 0 {
3121+
drop_span.with_lo(BytePos(lo - 1))
3122+
} else {
3123+
drop_span
3124+
};
31153125
self.thread_local_value_does_not_live_long_enough(borrow_span)
31163126
.with_span_label(
31173127
borrow_span,
31183128
"thread-local variables cannot be borrowed beyond the end of the function",
31193129
)
3120-
.with_span_label(drop_span, "end of enclosing function is here")
3130+
.with_span_label(end_of_function, "end of enclosing function is here")
31213131
}
31223132

31233133
#[instrument(level = "debug", skip(self))]

0 commit comments

Comments
 (0)