From 57da3df99a52ccedd7a684d2053db766e5681a61 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 6 Mar 2020 15:17:48 +0100 Subject: Explicitly remember desugard pats --- crates/ra_hir_def/src/body.rs | 4 ++-- crates/ra_hir_def/src/body/lower.rs | 12 ++++++++---- 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 { 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 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::{ }; 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 { -- cgit v1.2.3