aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/body.rs4
-rw-r--r--crates/ra_hir_def/src/body/lower.rs12
2 files changed, 10 insertions, 6 deletions
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs
index e60adc146..57ba45b45 100644
--- a/crates/ra_hir_def/src/body.rs
+++ b/crates/ra_hir_def/src/body.rs
@@ -151,7 +151,7 @@ pub struct BodySourceMap {
151 expr_map: FxHashMap<ExprSource, ExprId>, 151 expr_map: FxHashMap<ExprSource, ExprId>,
152 expr_map_back: ArenaMap<ExprId, Result<ExprSource, SyntheticSyntax>>, 152 expr_map_back: ArenaMap<ExprId, Result<ExprSource, SyntheticSyntax>>,
153 pat_map: FxHashMap<PatSource, PatId>, 153 pat_map: FxHashMap<PatSource, PatId>,
154 pat_map_back: ArenaMap<PatId, PatSource>, 154 pat_map_back: ArenaMap<PatId, Result<PatSource, SyntheticSyntax>>,
155 field_map: FxHashMap<(ExprId, usize), AstPtr<ast::RecordField>>, 155 field_map: FxHashMap<(ExprId, usize), AstPtr<ast::RecordField>>,
156 expansions: FxHashMap<InFile<AstPtr<ast::MacroCall>>, HirFileId>, 156 expansions: FxHashMap<InFile<AstPtr<ast::MacroCall>>, HirFileId>,
157} 157}
@@ -242,7 +242,7 @@ impl BodySourceMap {
242 } 242 }
243 243
244 pub fn pat_syntax(&self, pat: PatId) -> Result<PatSource, SyntheticSyntax> { 244 pub fn pat_syntax(&self, pat: PatId) -> Result<PatSource, SyntheticSyntax> {
245 self.pat_map_back.get(pat).copied().ok_or(SyntheticSyntax) 245 self.pat_map_back[pat]
246 } 246 }
247 247
248 pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> { 248 pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> {
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index 209907700..ec1b0c2e7 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::{
14}; 14};
15use test_utils::tested_by; 15use test_utils::tested_by;
16 16
17use super::ExprSource; 17use super::{ExprSource, PatSource};
18use crate::{ 18use crate::{
19 adt::StructKind, 19 adt::StructKind,
20 body::{Body, BodySourceMap, Expander, PatPtr, SyntheticSyntax}, 20 body::{Body, BodySourceMap, Expander, PatPtr, SyntheticSyntax},
@@ -133,14 +133,18 @@ where
133 } 133 }
134 134
135 fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId { 135 fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId {
136 let id = self.body.pats.alloc(pat);
137 let src = self.expander.to_source(ptr); 136 let src = self.expander.to_source(ptr);
137 let id = self.make_pat(pat, Ok(src));
138 self.source_map.pat_map.insert(src, id); 138 self.source_map.pat_map.insert(src, id);
139 self.source_map.pat_map_back.insert(id, src);
140 id 139 id
141 } 140 }
142 fn missing_pat(&mut self) -> PatId { 141 fn missing_pat(&mut self) -> PatId {
143 self.body.pats.alloc(Pat::Missing) 142 self.make_pat(Pat::Missing, Err(SyntheticSyntax))
143 }
144 fn make_pat(&mut self, pat: Pat, src: Result<PatSource, SyntheticSyntax>) -> PatId {
145 let id = self.body.pats.alloc(pat);
146 self.source_map.pat_map_back.insert(id, src);
147 id
144 } 148 }
145 149
146 fn collect_expr(&mut self, expr: ast::Expr) -> ExprId { 150 fn collect_expr(&mut self, expr: ast::Expr) -> ExprId {