From f7156cb0aeaba8fe32c381a2d676b35d2c86f46f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 15 Mar 2021 15:38:50 +0300 Subject: Simplify source maps for fields --- crates/hir/src/source_analyzer.rs | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) (limited to 'crates/hir') 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::{ }; use syntax::{ ast::{self, AstNode}, - AstPtr, SyntaxNode, TextRange, TextSize, + SyntaxNode, TextRange, TextSize, }; use crate::{ @@ -161,26 +161,8 @@ impl SourceAnalyzer { db: &dyn HirDatabase, field: &ast::RecordExprField, ) -> Option<(Field, Option)> { - let expr_id = { - let record_lit = field.parent_record_lit(); - let record_lit_expr = self.expr_id(db, &ast::Expr::from(record_lit))?; - let body = self.body.as_ref()?; - let body_source_map = self.body_source_map.as_ref()?; - match &body[record_lit_expr] { - hir_def::expr::Expr::RecordLit { fields, .. } => { - let field_ptr = InFile::new(self.file_id, AstPtr::new(field)); - fields.iter().enumerate().find_map(|(i, f)| { - let ptr = body_source_map.field_syntax(record_lit_expr, i); - if ptr == field_ptr { - Some(f.expr) - } else { - None - } - })? - } - _ => return None, - } - }; + let expr_id = + self.body_source_map.as_ref()?.node_field(InFile::new(self.file_id, field))?; let local = if field.name_ref().is_some() { None -- cgit v1.2.3