aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorDawer <[email protected]>2021-05-06 09:15:40 +0100
committerDawer <[email protected]>2021-05-31 20:03:46 +0100
commitde6f430140a49e3ecf34dcb914326bb5b9789772 (patch)
tree1f493d2e613d3aaa03ae2f3b70b563937f476378 /crates
parent975109051caf05de6d166779589e299d9aca9cd5 (diff)
Fix panics on pattern_arena.borrow with ugly cloning
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs19
-rw-r--r--crates/hir_ty/src/diagnostics/pattern/usefulness.rs12
2 files changed, 15 insertions, 16 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
diff --git a/crates/hir_ty/src/diagnostics/pattern/usefulness.rs b/crates/hir_ty/src/diagnostics/pattern/usefulness.rs
index 28b9e71f8..3bfb7afed 100644
--- a/crates/hir_ty/src/diagnostics/pattern/usefulness.rs
+++ b/crates/hir_ty/src/diagnostics/pattern/usefulness.rs
@@ -94,12 +94,12 @@ impl PatIdExt for PatId {
94 fn expand_or_pat(self, cx: &MatchCheckCtx<'_>) -> Vec<Self> { 94 fn expand_or_pat(self, cx: &MatchCheckCtx<'_>) -> Vec<Self> {
95 fn expand(pat: PatId, vec: &mut Vec<PatId>, mut pat_arena: &mut PatternArena) { 95 fn expand(pat: PatId, vec: &mut Vec<PatId>, mut pat_arena: &mut PatternArena) {
96 if let PatKind::Or { pats } = pat_arena[pat].kind.as_ref() { 96 if let PatKind::Or { pats } = pat_arena[pat].kind.as_ref() {
97 // for pat in pats { 97 let pats = pats.clone();
98 // // TODO(iDawer): Ugh, I want to go back to references (PatId -> &Pat) 98 for pat in pats {
99 // let pat = pat_arena.alloc(pat.clone()); 99 // TODO(iDawer): Ugh, I want to go back to references (PatId -> &Pat)
100 // expand(pat, vec, pat_arena); 100 let pat = pat_arena.alloc(pat.clone());
101 // } 101 expand(pat, vec, pat_arena);
102 todo!() 102 }
103 } else { 103 } else {
104 vec.push(pat) 104 vec.push(pat)
105 } 105 }