1
Fork 0

Fix incorrect suggestion for uninitialize binding in destructuring pattern

This commit is contained in:
clubby789 2024-02-04 17:11:29 +00:00
parent b11fbfbf35
commit 75da582987
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));