diff options
author | Dawer <[email protected]> | 2021-05-06 09:15:40 +0100 |
---|---|---|
committer | Dawer <[email protected]> | 2021-05-31 20:03:46 +0100 |
commit | de6f430140a49e3ecf34dcb914326bb5b9789772 (patch) | |
tree | 1f493d2e613d3aaa03ae2f3b70b563937f476378 /crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs | |
parent | 975109051caf05de6d166779589e299d9aca9cd5 (diff) |
Fix panics on pattern_arena.borrow with ugly cloning
Diffstat (limited to 'crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs')
-rw-r--r-- | crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs b/crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs index 479e0dc73..ddf6b1198 100644 --- a/crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs +++ b/crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs | |||
@@ -837,20 +837,19 @@ impl Fields { | |||
837 | pat: PatId, | 837 | pat: PatId, |
838 | cx: &MatchCheckCtx<'_>, | 838 | cx: &MatchCheckCtx<'_>, |
839 | ) -> Self { | 839 | ) -> Self { |
840 | // TODO: these alocations are so unfortunate (+1 for switching to references) | 840 | // TODO: these alocations and clones are so unfortunate (+1 for switching to references) |
841 | match cx.pattern_arena.borrow()[pat].kind.as_ref() { | 841 | let mut arena = cx.pattern_arena.borrow_mut(); |
842 | match arena[pat].kind.as_ref() { | ||
842 | PatKind::Deref { subpattern } => { | 843 | PatKind::Deref { subpattern } => { |
843 | assert_eq!(self.len(), 1); | 844 | assert_eq!(self.len(), 1); |
844 | let subpattern = cx.pattern_arena.borrow_mut().alloc(subpattern.clone()); | 845 | let subpattern = subpattern.clone(); |
845 | Fields::from_single_pattern(subpattern) | 846 | Fields::from_single_pattern(arena.alloc(subpattern)) |
846 | } | 847 | } |
847 | PatKind::Leaf { subpatterns } | PatKind::Variant { subpatterns, .. } => { | 848 | PatKind::Leaf { subpatterns } | PatKind::Variant { subpatterns, .. } => { |
848 | let subpatterns = subpatterns.iter().map(|field_pat| { | 849 | let subpatterns = subpatterns.clone(); |
849 | ( | 850 | let subpatterns = subpatterns |
850 | field_pat.field, | 851 | .iter() |
851 | cx.pattern_arena.borrow_mut().alloc(field_pat.pattern.clone()), | 852 | .map(|field_pat| (field_pat.field, arena.alloc(field_pat.pattern.clone()))); |
852 | ) | ||
853 | }); | ||
854 | self.replace_with_fieldpats(subpatterns) | 853 | self.replace_with_fieldpats(subpatterns) |
855 | } | 854 | } |
856 | 855 | ||