From 5ffddc4b921685ebd5f9525f7e33913a1d08c04e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 6 Mar 2020 15:11:05 +0100 Subject: Explicitly remember desugard exprs --- crates/ra_hir_def/src/body/lower.rs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'crates/ra_hir_def/src/body') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index c18e6879b..209907700 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -14,9 +14,10 @@ use ra_syntax::{ }; use test_utils::tested_by; +use super::ExprSource; use crate::{ adt::StructKind, - body::{Body, BodySourceMap, Expander, PatPtr}, + body::{Body, BodySourceMap, Expander, PatPtr, SyntheticSyntax}, builtin_type::{BuiltinFloat, BuiltinInt}, db::DefDatabase, expr::{ @@ -102,25 +103,35 @@ where fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr) -> ExprId { let ptr = Either::Left(ptr); - let id = self.body.exprs.alloc(expr); let src = self.expander.to_source(ptr); + let id = self.make_expr(expr, Ok(src)); self.source_map.expr_map.insert(src, id); - self.source_map.expr_map_back.insert(id, src); id } // desugared exprs don't have ptr, that's wrong and should be fixed // somehow. fn alloc_expr_desugared(&mut self, expr: Expr) -> ExprId { - self.body.exprs.alloc(expr) + self.make_expr(expr, Err(SyntheticSyntax)) } fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr) -> ExprId { let ptr = Either::Right(ptr); - let id = self.body.exprs.alloc(expr); let src = self.expander.to_source(ptr); + let id = self.make_expr(expr, Ok(src)); self.source_map.expr_map.insert(src, id); + id + } + fn empty_block(&mut self) -> ExprId { + self.alloc_expr_desugared(Expr::Block { statements: Vec::new(), tail: None }) + } + fn missing_expr(&mut self) -> ExprId { + self.alloc_expr_desugared(Expr::Missing) + } + fn make_expr(&mut self, expr: Expr, src: Result) -> ExprId { + let id = self.body.exprs.alloc(expr); self.source_map.expr_map_back.insert(id, src); id } + fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId { let id = self.body.pats.alloc(pat); let src = self.expander.to_source(ptr); @@ -128,16 +139,6 @@ where self.source_map.pat_map_back.insert(id, src); id } - - fn empty_block(&mut self) -> ExprId { - let block = Expr::Block { statements: Vec::new(), tail: None }; - self.body.exprs.alloc(block) - } - - fn missing_expr(&mut self) -> ExprId { - self.body.exprs.alloc(Expr::Missing) - } - fn missing_pat(&mut self) -> PatId { self.body.pats.alloc(Pat::Missing) } -- cgit v1.2.3 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/lower.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'crates/ra_hir_def/src/body') 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