diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index e60adc1460..57ba45b455 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs @@ -151,7 +151,7 @@ pub struct BodySourceMap { expr_map: FxHashMap, expr_map_back: ArenaMap>, pat_map: FxHashMap, - pat_map_back: ArenaMap, + pat_map_back: ArenaMap>, field_map: FxHashMap<(ExprId, usize), AstPtr>, expansions: FxHashMap>, HirFileId>, } @@ -242,7 +242,7 @@ impl BodySourceMap { } pub fn pat_syntax(&self, pat: PatId) -> Result { - 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 { diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 2099077003..ec1b0c2e70 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -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) -> 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 {