From 57fcb2e2d63306e762943b9edffa4454e89ef665 Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Mon, 12 Jul 2021 18:08:14 +0200 Subject: [PATCH] Fix two uses of `span_note` when the source is not available --- .../src/diagnostics/conflict_errors.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index ce1e7c14b1ff6..f4cbbb60b053a 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -218,7 +218,19 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { ); if self.fn_self_span_reported.insert(fn_span) { err.span_note( - self_arg.span, + // Check whether the source is accessible + if self + .infcx + .tcx + .sess + .source_map() + .span_to_snippet(self_arg.span) + .is_ok() + { + self_arg.span + } else { + fn_call_span + }, "calling this operator moves the left-hand side", ); } @@ -429,7 +441,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { deref_target_ty )); - err.span_note(deref_target, "deref defined here"); + // Check first whether the source is accessible (issue #87060) + if self.infcx.tcx.sess.source_map().span_to_snippet(deref_target).is_ok() { + err.span_note(deref_target, "deref defined here"); + } } if let Some((_, mut old_err)) =