mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 09:27:27 +00:00
Fix panics on pattern_arena.borrow with ugly cloning
This commit is contained in:
parent
975109051c
commit
de6f430140
2 changed files with 15 additions and 16 deletions
|
@ -837,20 +837,19 @@ impl Fields {
|
|||
pat: PatId,
|
||||
cx: &MatchCheckCtx<'_>,
|
||||
) -> Self {
|
||||
// TODO: these alocations are so unfortunate (+1 for switching to references)
|
||||
match cx.pattern_arena.borrow()[pat].kind.as_ref() {
|
||||
// TODO: these alocations and clones are so unfortunate (+1 for switching to references)
|
||||
let mut arena = cx.pattern_arena.borrow_mut();
|
||||
match arena[pat].kind.as_ref() {
|
||||
PatKind::Deref { subpattern } => {
|
||||
assert_eq!(self.len(), 1);
|
||||
let subpattern = cx.pattern_arena.borrow_mut().alloc(subpattern.clone());
|
||||
Fields::from_single_pattern(subpattern)
|
||||
let subpattern = subpattern.clone();
|
||||
Fields::from_single_pattern(arena.alloc(subpattern))
|
||||
}
|
||||
PatKind::Leaf { subpatterns } | PatKind::Variant { subpatterns, .. } => {
|
||||
let subpatterns = subpatterns.iter().map(|field_pat| {
|
||||
(
|
||||
field_pat.field,
|
||||
cx.pattern_arena.borrow_mut().alloc(field_pat.pattern.clone()),
|
||||
)
|
||||
});
|
||||
let subpatterns = subpatterns.clone();
|
||||
let subpatterns = subpatterns
|
||||
.iter()
|
||||
.map(|field_pat| (field_pat.field, arena.alloc(field_pat.pattern.clone())));
|
||||
self.replace_with_fieldpats(subpatterns)
|
||||
}
|
||||
|
||||
|
|
|
@ -94,12 +94,12 @@ impl PatIdExt for PatId {
|
|||
fn expand_or_pat(self, cx: &MatchCheckCtx<'_>) -> Vec<Self> {
|
||||
fn expand(pat: PatId, vec: &mut Vec<PatId>, mut pat_arena: &mut PatternArena) {
|
||||
if let PatKind::Or { pats } = pat_arena[pat].kind.as_ref() {
|
||||
// for pat in pats {
|
||||
// // TODO(iDawer): Ugh, I want to go back to references (PatId -> &Pat)
|
||||
// let pat = pat_arena.alloc(pat.clone());
|
||||
// expand(pat, vec, pat_arena);
|
||||
// }
|
||||
todo!()
|
||||
let pats = pats.clone();
|
||||
for pat in pats {
|
||||
// TODO(iDawer): Ugh, I want to go back to references (PatId -> &Pat)
|
||||
let pat = pat_arena.alloc(pat.clone());
|
||||
expand(pat, vec, pat_arena);
|
||||
}
|
||||
} else {
|
||||
vec.push(pat)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue