Rollup merge of #120646 - clubby789:uninit-destructuring-sugg, r=michaelwoerister

Fix incorrect suggestion for uninitialized binding in pattern

Fixes #120634
This commit is contained in:
Matthias Krüger
2024-03-01 17:51:28 +01:00
committed by GitHub
3 changed files with 55 additions and 2 deletions

View File

@@ -613,7 +613,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
if self.sugg_span.is_some() {
return;
}
if let hir::StmtKind::Local(hir::Local { span, ty, init: None, .. }) = &ex.kind
// FIXME: We make sure that this is a normal top-level binding,
// but we could suggest `todo!()` for all uninitalized bindings in the pattern pattern
if let hir::StmtKind::Local(hir::Local { span, ty, init: None, pat, .. }) =
&ex.kind
&& let hir::PatKind::Binding(..) = pat.kind
&& span.contains(self.decl_span)
{
self.sugg_span = ty.map_or(Some(self.decl_span), |ty| Some(ty.span));