aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/expr/validation.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-09-03 09:04:38 +0100
committerAleksey Kladov <[email protected]>2019-09-03 09:04:38 +0100
commit9c3b25177e3c8d609dd24d2c2e01cbb82cab665f (patch)
treedf19e2603745c348e2e5d8289be80c2f511b0b0d /crates/ra_hir/src/expr/validation.rs
parent4b51c92feeda0078033508ceee7345c6ac1a97e6 (diff)
Correctly build BodySourceMap for macro-expanded expressions
Diffstat (limited to 'crates/ra_hir/src/expr/validation.rs')
-rw-r--r--crates/ra_hir/src/expr/validation.rs47
1 files changed, 22 insertions, 25 deletions
diff --git a/crates/ra_hir/src/expr/validation.rs b/crates/ra_hir/src/expr/validation.rs
index 6fdaf1fce..1202913e2 100644
--- a/crates/ra_hir/src/expr/validation.rs
+++ b/crates/ra_hir/src/expr/validation.rs
@@ -1,9 +1,8 @@
1use std::sync::Arc; 1use std::sync::Arc;
2 2
3use ra_syntax::ast::{self, AstNode}; 3use ra_syntax::ast;
4use rustc_hash::FxHashSet; 4use rustc_hash::FxHashSet;
5 5
6use super::{Expr, ExprId, RecordLitField};
7use crate::{ 6use crate::{
8 adt::AdtDef, 7 adt::AdtDef,
9 diagnostics::{DiagnosticSink, MissingFields, MissingOkInTailExpr}, 8 diagnostics::{DiagnosticSink, MissingFields, MissingOkInTailExpr},
@@ -11,9 +10,11 @@ use crate::{
11 name, 10 name,
12 path::{PathKind, PathSegment}, 11 path::{PathKind, PathSegment},
13 ty::{ApplicationTy, InferenceResult, Ty, TypeCtor}, 12 ty::{ApplicationTy, InferenceResult, Ty, TypeCtor},
14 Function, HasSource, HirDatabase, ModuleDef, Name, Path, PerNs, Resolution, 13 Function, HirDatabase, ModuleDef, Name, Path, PerNs, Resolution,
15}; 14};
16 15
16use super::{Expr, ExprId, RecordLitField};
17
17pub(crate) struct ExprValidator<'a, 'b: 'a> { 18pub(crate) struct ExprValidator<'a, 'b: 'a> {
18 func: Function, 19 func: Function,
19 infer: Arc<InferenceResult>, 20 infer: Arc<InferenceResult>,
@@ -78,25 +79,20 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
78 return; 79 return;
79 } 80 }
80 let source_map = self.func.body_source_map(db); 81 let source_map = self.func.body_source_map(db);
81 let file_id = self.func.source(db).file_id; 82
82 let parse = db.parse(file_id.original_file(db)); 83 if let Some(source_ptr) = source_map.expr_syntax(id) {
83 let source_file = parse.tree(); 84 if let Some(expr) = source_ptr.ast.a() {
84 if let Some(field_list_node) = source_map 85 let root = source_ptr.file_syntax(db);
85 .expr_syntax(id) 86 if let ast::Expr::RecordLit(record_lit) = expr.to_node(&root) {
86 .and_then(|ptr| ptr.a()) 87 if let Some(field_list) = record_lit.record_field_list() {
87 .map(|ptr| ptr.to_node(source_file.syntax())) 88 self.sink.push(MissingFields {
88 .and_then(|expr| match expr { 89 file: source_ptr.file_id,
89 ast::Expr::RecordLit(it) => Some(it), 90 field_list: AstPtr::new(&field_list),
90 _ => None, 91 missed_fields,
91 }) 92 })
92 .and_then(|lit| lit.record_field_list()) 93 }
93 { 94 }
94 let field_list_ptr = AstPtr::new(&field_list_node); 95 }
95 self.sink.push(MissingFields {
96 file: file_id,
97 field_list: field_list_ptr,
98 missed_fields,
99 })
100 } 96 }
101 } 97 }
102 98
@@ -136,10 +132,11 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
136 132
137 if params.len() == 2 && &params[0] == &mismatch.actual { 133 if params.len() == 2 && &params[0] == &mismatch.actual {
138 let source_map = self.func.body_source_map(db); 134 let source_map = self.func.body_source_map(db);
139 let file_id = self.func.source(db).file_id;
140 135
141 if let Some(expr) = source_map.expr_syntax(id).and_then(|n| n.a()) { 136 if let Some(source_ptr) = source_map.expr_syntax(id) {
142 self.sink.push(MissingOkInTailExpr { file: file_id, expr }); 137 if let Some(expr) = source_ptr.ast.a() {
138 self.sink.push(MissingOkInTailExpr { file: source_ptr.file_id, expr });
139 }
143 } 140 }
144 } 141 }
145 } 142 }