diff options
Diffstat (limited to 'crates/ra_hir_ty/src/diagnostics/expr.rs')
-rw-r--r-- | crates/ra_hir_ty/src/diagnostics/expr.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/crates/ra_hir_ty/src/diagnostics/expr.rs b/crates/ra_hir_ty/src/diagnostics/expr.rs index 51c97f801..239be779f 100644 --- a/crates/ra_hir_ty/src/diagnostics/expr.rs +++ b/crates/ra_hir_ty/src/diagnostics/expr.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | use std::sync::Arc; | 3 | use std::sync::Arc; |
4 | 4 | ||
5 | use hir_def::{path::path, resolver::HasResolver, AdtId, FunctionId}; | 5 | use hir_def::{path::path, resolver::HasResolver, AdtId, DefWithBodyId}; |
6 | use hir_expand::diagnostics::DiagnosticSink; | 6 | use hir_expand::diagnostics::DiagnosticSink; |
7 | use ra_syntax::{ast, AstPtr}; | 7 | use ra_syntax::{ast, AstPtr}; |
8 | use rustc_hash::FxHashSet; | 8 | use rustc_hash::FxHashSet; |
@@ -30,23 +30,23 @@ pub use hir_def::{ | |||
30 | LocalFieldId, Lookup, VariantId, | 30 | LocalFieldId, Lookup, VariantId, |
31 | }; | 31 | }; |
32 | 32 | ||
33 | pub struct ExprValidator<'a, 'b: 'a> { | 33 | pub(super) struct ExprValidator<'a, 'b: 'a> { |
34 | func: FunctionId, | 34 | owner: DefWithBodyId, |
35 | infer: Arc<InferenceResult>, | 35 | infer: Arc<InferenceResult>, |
36 | sink: &'a mut DiagnosticSink<'b>, | 36 | sink: &'a mut DiagnosticSink<'b>, |
37 | } | 37 | } |
38 | 38 | ||
39 | impl<'a, 'b> ExprValidator<'a, 'b> { | 39 | impl<'a, 'b> ExprValidator<'a, 'b> { |
40 | pub fn new( | 40 | pub(super) fn new( |
41 | func: FunctionId, | 41 | owner: DefWithBodyId, |
42 | infer: Arc<InferenceResult>, | 42 | infer: Arc<InferenceResult>, |
43 | sink: &'a mut DiagnosticSink<'b>, | 43 | sink: &'a mut DiagnosticSink<'b>, |
44 | ) -> ExprValidator<'a, 'b> { | 44 | ) -> ExprValidator<'a, 'b> { |
45 | ExprValidator { func, infer, sink } | 45 | ExprValidator { owner, infer, sink } |
46 | } | 46 | } |
47 | 47 | ||
48 | pub fn validate_body(&mut self, db: &dyn HirDatabase) { | 48 | pub(super) fn validate_body(&mut self, db: &dyn HirDatabase) { |
49 | let body = db.body(self.func.into()); | 49 | let body = db.body(self.owner.into()); |
50 | 50 | ||
51 | for (id, expr) in body.exprs.iter() { | 51 | for (id, expr) in body.exprs.iter() { |
52 | if let Some((variant_def, missed_fields, true)) = | 52 | if let Some((variant_def, missed_fields, true)) = |
@@ -96,7 +96,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
96 | missed_fields: Vec<LocalFieldId>, | 96 | missed_fields: Vec<LocalFieldId>, |
97 | ) { | 97 | ) { |
98 | // XXX: only look at source_map if we do have missing fields | 98 | // XXX: only look at source_map if we do have missing fields |
99 | let (_, source_map) = db.body_with_source_map(self.func.into()); | 99 | let (_, source_map) = db.body_with_source_map(self.owner.into()); |
100 | 100 | ||
101 | if let Ok(source_ptr) = source_map.expr_syntax(id) { | 101 | if let Ok(source_ptr) = source_map.expr_syntax(id) { |
102 | let root = source_ptr.file_syntax(db.upcast()); | 102 | let root = source_ptr.file_syntax(db.upcast()); |
@@ -125,7 +125,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
125 | missed_fields: Vec<LocalFieldId>, | 125 | missed_fields: Vec<LocalFieldId>, |
126 | ) { | 126 | ) { |
127 | // XXX: only look at source_map if we do have missing fields | 127 | // XXX: only look at source_map if we do have missing fields |
128 | let (_, source_map) = db.body_with_source_map(self.func.into()); | 128 | let (_, source_map) = db.body_with_source_map(self.owner.into()); |
129 | 129 | ||
130 | if let Ok(source_ptr) = source_map.pat_syntax(id) { | 130 | if let Ok(source_ptr) = source_map.pat_syntax(id) { |
131 | if let Some(expr) = source_ptr.value.as_ref().left() { | 131 | if let Some(expr) = source_ptr.value.as_ref().left() { |
@@ -181,7 +181,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
181 | let mut arg_count = args.len(); | 181 | let mut arg_count = args.len(); |
182 | 182 | ||
183 | if arg_count != param_count { | 183 | if arg_count != param_count { |
184 | let (_, source_map) = db.body_with_source_map(self.func.into()); | 184 | let (_, source_map) = db.body_with_source_map(self.owner.into()); |
185 | if let Ok(source_ptr) = source_map.expr_syntax(call_id) { | 185 | if let Ok(source_ptr) = source_map.expr_syntax(call_id) { |
186 | if is_method_call { | 186 | if is_method_call { |
187 | param_count -= 1; | 187 | param_count -= 1; |
@@ -208,7 +208,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
208 | infer: Arc<InferenceResult>, | 208 | infer: Arc<InferenceResult>, |
209 | ) { | 209 | ) { |
210 | let (body, source_map): (Arc<Body>, Arc<BodySourceMap>) = | 210 | let (body, source_map): (Arc<Body>, Arc<BodySourceMap>) = |
211 | db.body_with_source_map(self.func.into()); | 211 | db.body_with_source_map(self.owner.into()); |
212 | 212 | ||
213 | let match_expr_ty = match infer.type_of_expr.get(match_expr) { | 213 | let match_expr_ty = match infer.type_of_expr.get(match_expr) { |
214 | Some(ty) => ty, | 214 | Some(ty) => ty, |
@@ -289,7 +289,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
289 | 289 | ||
290 | let core_result_path = path![core::result::Result]; | 290 | let core_result_path = path![core::result::Result]; |
291 | 291 | ||
292 | let resolver = self.func.resolver(db.upcast()); | 292 | let resolver = self.owner.resolver(db.upcast()); |
293 | let core_result_enum = match resolver.resolve_known_enum(db.upcast(), &core_result_path) { | 293 | let core_result_enum = match resolver.resolve_known_enum(db.upcast(), &core_result_path) { |
294 | Some(it) => it, | 294 | Some(it) => it, |
295 | _ => return, | 295 | _ => return, |
@@ -304,7 +304,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
304 | }; | 304 | }; |
305 | 305 | ||
306 | if params.len() == 2 && params[0] == mismatch.actual { | 306 | if params.len() == 2 && params[0] == mismatch.actual { |
307 | let (_, source_map) = db.body_with_source_map(self.func.into()); | 307 | let (_, source_map) = db.body_with_source_map(self.owner.into()); |
308 | 308 | ||
309 | if let Ok(source_ptr) = source_map.expr_syntax(id) { | 309 | if let Ok(source_ptr) = source_map.expr_syntax(id) { |
310 | self.sink | 310 | self.sink |