Skip to content

Commit a7baff8

Browse files
committed
Avoid panic when debug info is missing
1 parent a30f178 commit a7baff8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,15 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
465465

466466
if let PlaceRef { local, projection: [] } = deref_base {
467467
let decl = &self.body.local_decls[local];
468+
let local_name = self.local_names[local].map(|sym| format!("`{sym}`"));
468469
if decl.is_ref_for_guard() {
469470
return self
470471
.cannot_move_out_of(
471472
span,
472-
&format!("`{}` in pattern guard", self.local_names[local].unwrap()),
473+
&format!(
474+
"{} in pattern guard",
475+
local_name.as_deref().unwrap_or("the place")
476+
),
473477
)
474478
.with_note(
475479
"variables bound in patterns cannot be moved from \
@@ -825,7 +829,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
825829
}
826830

827831
if binds_to.len() == 1 {
828-
let place_desc = &format!("`{}`", self.local_names[*local].unwrap());
832+
let place_desc = self.local_names[*local].map(|sym| format!("`{sym}`"));
829833

830834
if let Some(expr) = self.find_expr(binding_span) {
831835
self.suggest_cloning(err, bind_to.ty, expr, None);
@@ -834,7 +838,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
834838
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
835839
is_partial_move: false,
836840
ty: bind_to.ty,
837-
place: place_desc,
841+
place: place_desc.as_deref().unwrap_or("the place"),
838842
span: binding_span,
839843
});
840844
}

0 commit comments

Comments
 (0)