diff options
| author | Kornel <kornel@geekhood.net> | 2025-06-22 16:49:38 +0100 |
|---|---|---|
| committer | Kornel <kornel@geekhood.net> | 2025-06-22 17:00:09 +0100 |
| commit | a7baff819d7034246a63c01b07038555097e0b5d (patch) | |
| tree | 1a048f84607bc8e62366b13fb6d16a183d60719e | |
| parent | a30f1783fe136d92545423dd30b12eb619973cdb (diff) | |
| download | rust-a7baff819d7034246a63c01b07038555097e0b5d.tar.gz rust-a7baff819d7034246a63c01b07038555097e0b5d.zip | |
Avoid panic when debug info is missing
| -rw-r--r-- | compiler/rustc_borrowck/src/diagnostics/move_errors.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs index 0394a42ea9c..52ed0f2a42c 100644 --- a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs @@ -465,11 +465,15 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { if let PlaceRef { local, projection: [] } = deref_base { let decl = &self.body.local_decls[local]; + let local_name = self.local_names[local].map(|sym| format!("`{sym}`")); if decl.is_ref_for_guard() { return self .cannot_move_out_of( span, - &format!("`{}` in pattern guard", self.local_names[local].unwrap()), + &format!( + "{} in pattern guard", + local_name.as_deref().unwrap_or("the place") + ), ) .with_note( "variables bound in patterns cannot be moved from \ @@ -825,7 +829,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { } if binds_to.len() == 1 { - let place_desc = &format!("`{}`", self.local_names[*local].unwrap()); + let place_desc = self.local_names[*local].map(|sym| format!("`{sym}`")); if let Some(expr) = self.find_expr(binding_span) { self.suggest_cloning(err, bind_to.ty, expr, None); @@ -834,7 +838,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label { is_partial_move: false, ty: bind_to.ty, - place: place_desc, + place: place_desc.as_deref().unwrap_or("the place"), span: binding_span, }); } |
