Skip to content

Commit 57fcb2e

Browse files
committed
Fix two uses of span_note when the source is not available
1 parent 497ee32 commit 57fcb2e

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,19 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
218218
);
219219
if self.fn_self_span_reported.insert(fn_span) {
220220
err.span_note(
221-
self_arg.span,
221+
// Check whether the source is accessible
222+
if self
223+
.infcx
224+
.tcx
225+
.sess
226+
.source_map()
227+
.span_to_snippet(self_arg.span)
228+
.is_ok()
229+
{
230+
self_arg.span
231+
} else {
232+
fn_call_span
233+
},
222234
"calling this operator moves the left-hand side",
223235
);
224236
}
@@ -429,7 +441,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
429441
deref_target_ty
430442
));
431443

432-
err.span_note(deref_target, "deref defined here");
444+
// Check first whether the source is accessible (issue #87060)
445+
if self.infcx.tcx.sess.source_map().span_to_snippet(deref_target).is_ok() {
446+
err.span_note(deref_target, "deref defined here");
447+
}
433448
}
434449

435450
if let Some((_, mut old_err)) =

0 commit comments

Comments
 (0)