Explicitly remember desugard pats

This commit is contained in:
Aleksey Kladov 2020-03-06 15:17:48 +01:00
parent 5ffddc4b92
commit 57da3df99a
2 changed files with 10 additions and 6 deletions

View file

@ -151,7 +151,7 @@ pub struct BodySourceMap {
expr_map: FxHashMap<ExprSource, ExprId>,
expr_map_back: ArenaMap<ExprId, Result<ExprSource, SyntheticSyntax>>,
pat_map: FxHashMap<PatSource, PatId>,
pat_map_back: ArenaMap<PatId, PatSource>,
pat_map_back: ArenaMap<PatId, Result<PatSource, SyntheticSyntax>>,
field_map: FxHashMap<(ExprId, usize), AstPtr<ast::RecordField>>,
expansions: FxHashMap<InFile<AstPtr<ast::MacroCall>>, HirFileId>,
}
@ -242,7 +242,7 @@ impl BodySourceMap {
}
pub fn pat_syntax(&self, pat: PatId) -> Result<PatSource, SyntheticSyntax> {
self.pat_map_back.get(pat).copied().ok_or(SyntheticSyntax)
self.pat_map_back[pat]
}
pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> {

View file

@ -14,7 +14,7 @@ use ra_syntax::{
};
use test_utils::tested_by;
use super::ExprSource;
use super::{ExprSource, PatSource};
use crate::{
adt::StructKind,
body::{Body, BodySourceMap, Expander, PatPtr, SyntheticSyntax},
@ -133,14 +133,18 @@ where
}
fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId {
let id = self.body.pats.alloc(pat);
let src = self.expander.to_source(ptr);
let id = self.make_pat(pat, Ok(src));
self.source_map.pat_map.insert(src, id);
self.source_map.pat_map_back.insert(id, src);
id
}
fn missing_pat(&mut self) -> PatId {
self.body.pats.alloc(Pat::Missing)
self.make_pat(Pat::Missing, Err(SyntheticSyntax))
}
fn make_pat(&mut self, pat: Pat, src: Result<PatSource, SyntheticSyntax>) -> PatId {
let id = self.body.pats.alloc(pat);
self.source_map.pat_map_back.insert(id, src);
id
}
fn collect_expr(&mut self, expr: ast::Expr) -> ExprId {