Skip to content

Commit d8de66f

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

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -3112,12 +3112,21 @@ 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 end_of_function = if drop_span.is_empty() {
3120+
drop_span.with_lo(BytePos(drop_span.lo().0 - 1))
3121+
} else {
3122+
drop_span
3123+
};
31153124
self.thread_local_value_does_not_live_long_enough(borrow_span)
31163125
.with_span_label(
31173126
borrow_span,
31183127
"thread-local variables cannot be borrowed beyond the end of the function",
31193128
)
3120-
.with_span_label(drop_span, "end of enclosing function is here")
3129+
.with_span_label(end_of_function, "end of enclosing function is here")
31213130
}
31223131

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

0 commit comments

Comments
 (0)