diff options
author | Dawer <[email protected]> | 2021-05-02 20:09:21 +0100 |
---|---|---|
committer | Dawer <[email protected]> | 2021-05-31 20:03:46 +0100 |
commit | 2431ff5987ee1f802ede0db5eedc863ce9a8e70f (patch) | |
tree | b8fac9a1b9cc1d373e89b1454070ccd27b235576 /crates/hir_ty/src/diagnostics | |
parent | 3ffcb2658cc2199271d3a22f9747517d8e2892d6 (diff) |
Handle unordered fields in struct patterns
Diffstat (limited to 'crates/hir_ty/src/diagnostics')
-rw-r--r-- | crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs | 14 |
1 files 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 { | |||
857 | self.replace_with_fieldpats(args.iter().copied()) | 857 | self.replace_with_fieldpats(args.iter().copied()) |
858 | } | 858 | } |
859 | Pat::Record { args, ellipsis, .. } => { | 859 | Pat::Record { args, ellipsis, .. } => { |
860 | // FIXME(iDawer) handle ellipsis. | 860 | let variant_id = |
861 | self.replace_with_fieldpats(args.iter().map(|field_pat| field_pat.pat)) | 861 | cx.infer.variant_resolution_for_pat(pat).unwrap_or_else(|| todo!()); |
862 | let variant_data = variant_id.variant_data(cx.db.upcast()); | ||
863 | |||
864 | let new_pats = args.iter().map(|field_pat| { | ||
865 | // TODO: field lookup is inefficient | ||
866 | let raw = | ||
867 | variant_data.field(&field_pat.name).unwrap_or_else(|| todo!()).into_raw(); | ||
868 | let idx = u32::from(raw) as usize; | ||
869 | (idx, field_pat.pat) | ||
870 | }); | ||
871 | self.replace_fields_indexed(new_pats) | ||
862 | } | 872 | } |
863 | Pat::Slice { .. } => { | 873 | Pat::Slice { .. } => { |
864 | todo!() | 874 | todo!() |