From 2431ff5987ee1f802ede0db5eedc863ce9a8e70f Mon Sep 17 00:00:00 2001 From: Dawer <7803845+iDawer@users.noreply.github.com> Date: Mon, 3 May 2021 00:09:21 +0500 Subject: Handle unordered fields in struct patterns --- crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs b/crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs index d3513c406..248a379b3 100644 --- a/crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs +++ b/crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs @@ -857,8 +857,18 @@ impl Fields { self.replace_with_fieldpats(args.iter().copied()) } Pat::Record { args, ellipsis, .. } => { - // FIXME(iDawer) handle ellipsis. - self.replace_with_fieldpats(args.iter().map(|field_pat| field_pat.pat)) + let variant_id = + cx.infer.variant_resolution_for_pat(pat).unwrap_or_else(|| todo!()); + let variant_data = variant_id.variant_data(cx.db.upcast()); + + let new_pats = args.iter().map(|field_pat| { + // TODO: field lookup is inefficient + let raw = + variant_data.field(&field_pat.name).unwrap_or_else(|| todo!()).into_raw(); + let idx = u32::from(raw) as usize; + (idx, field_pat.pat) + }); + self.replace_fields_indexed(new_pats) } Pat::Slice { .. } => { todo!() -- cgit v1.2.3