aboutsummaryrefslogtreecommitdiff
path: root/crates/hir
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-03-15 12:39:24 +0000
committerGitHub <[email protected]>2021-03-15 12:39:24 +0000
commita8b319cf28c0985d964ef6624c3ee6e7f09afb2d (patch)
tree2ee4aa8e66b3371f8cbf65b2c4951d5e2c227cb4 /crates/hir
parentb4446cdd06caa32e1e9e255312a15feb770d4935 (diff)
parentf7156cb0aeaba8fe32c381a2d676b35d2c86f46f (diff)
Merge #8026
8026: Simplify source maps for fields r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/hir')
-rw-r--r--crates/hir/src/source_analyzer.rs24
1 files changed, 3 insertions, 21 deletions
diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs
index 055a3e5d0..4d59293e9 100644
--- a/crates/hir/src/source_analyzer.rs
+++ b/crates/hir/src/source_analyzer.rs
@@ -24,7 +24,7 @@ use hir_ty::{
24}; 24};
25use syntax::{ 25use syntax::{
26 ast::{self, AstNode}, 26 ast::{self, AstNode},
27 AstPtr, SyntaxNode, TextRange, TextSize, 27 SyntaxNode, TextRange, TextSize,
28}; 28};
29 29
30use crate::{ 30use crate::{
@@ -161,26 +161,8 @@ impl SourceAnalyzer {
161 db: &dyn HirDatabase, 161 db: &dyn HirDatabase,
162 field: &ast::RecordExprField, 162 field: &ast::RecordExprField,
163 ) -> Option<(Field, Option<Local>)> { 163 ) -> Option<(Field, Option<Local>)> {
164 let expr_id = { 164 let expr_id =
165 let record_lit = field.parent_record_lit(); 165 self.body_source_map.as_ref()?.node_field(InFile::new(self.file_id, field))?;
166 let record_lit_expr = self.expr_id(db, &ast::Expr::from(record_lit))?;
167 let body = self.body.as_ref()?;
168 let body_source_map = self.body_source_map.as_ref()?;
169 match &body[record_lit_expr] {
170 hir_def::expr::Expr::RecordLit { fields, .. } => {
171 let field_ptr = InFile::new(self.file_id, AstPtr::new(field));
172 fields.iter().enumerate().find_map(|(i, f)| {
173 let ptr = body_source_map.field_syntax(record_lit_expr, i);
174 if ptr == field_ptr {
175 Some(f.expr)
176 } else {
177 None
178 }
179 })?
180 }
181 _ => return None,
182 }
183 };
184 166
185 let local = if field.name_ref().is_some() { 167 let local = if field.name_ref().is_some() {
186 None 168 None