diff options
author | Aleksey Kladov <[email protected]> | 2021-03-15 12:38:50 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-03-15 12:38:50 +0000 |
commit | f7156cb0aeaba8fe32c381a2d676b35d2c86f46f (patch) | |
tree | 2ee4aa8e66b3371f8cbf65b2c4951d5e2c227cb4 /crates/hir_ty | |
parent | af2366acdf1321702e54e01c88052ed5a674716c (diff) |
Simplify source maps for fields
Diffstat (limited to 'crates/hir_ty')
-rw-r--r-- | crates/hir_ty/src/infer.rs | 6 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/expr.rs | 5 |
2 files changed, 5 insertions, 6 deletions
diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index fbfedb4e6..9f29098ee 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs | |||
@@ -784,7 +784,7 @@ mod diagnostics { | |||
784 | 784 | ||
785 | #[derive(Debug, PartialEq, Eq, Clone)] | 785 | #[derive(Debug, PartialEq, Eq, Clone)] |
786 | pub(super) enum InferenceDiagnostic { | 786 | pub(super) enum InferenceDiagnostic { |
787 | NoSuchField { expr: ExprId, field: usize }, | 787 | NoSuchField { expr: ExprId }, |
788 | BreakOutsideOfLoop { expr: ExprId }, | 788 | BreakOutsideOfLoop { expr: ExprId }, |
789 | } | 789 | } |
790 | 790 | ||
@@ -796,9 +796,9 @@ mod diagnostics { | |||
796 | sink: &mut DiagnosticSink, | 796 | sink: &mut DiagnosticSink, |
797 | ) { | 797 | ) { |
798 | match self { | 798 | match self { |
799 | InferenceDiagnostic::NoSuchField { expr, field } => { | 799 | InferenceDiagnostic::NoSuchField { expr } => { |
800 | let (_, source_map) = db.body_with_source_map(owner); | 800 | let (_, source_map) = db.body_with_source_map(owner); |
801 | let field = source_map.field_syntax(*expr, *field); | 801 | let field = source_map.field_syntax(*expr); |
802 | sink.push(NoSuchField { file: field.file_id, field: field.value }) | 802 | sink.push(NoSuchField { file: field.file_id, field: field.value }) |
803 | } | 803 | } |
804 | InferenceDiagnostic::BreakOutsideOfLoop { expr } => { | 804 | InferenceDiagnostic::BreakOutsideOfLoop { expr } => { |
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index 55163c963..1a11b146a 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs | |||
@@ -405,14 +405,13 @@ impl<'a> InferenceContext<'a> { | |||
405 | let substs = ty.substs().cloned().unwrap_or_else(Substs::empty); | 405 | let substs = ty.substs().cloned().unwrap_or_else(Substs::empty); |
406 | let field_types = def_id.map(|it| self.db.field_types(it)).unwrap_or_default(); | 406 | let field_types = def_id.map(|it| self.db.field_types(it)).unwrap_or_default(); |
407 | let variant_data = def_id.map(|it| variant_data(self.db.upcast(), it)); | 407 | let variant_data = def_id.map(|it| variant_data(self.db.upcast(), it)); |
408 | for (field_idx, field) in fields.iter().enumerate() { | 408 | for field in fields.iter() { |
409 | let field_def = | 409 | let field_def = |
410 | variant_data.as_ref().and_then(|it| match it.field(&field.name) { | 410 | variant_data.as_ref().and_then(|it| match it.field(&field.name) { |
411 | Some(local_id) => Some(FieldId { parent: def_id.unwrap(), local_id }), | 411 | Some(local_id) => Some(FieldId { parent: def_id.unwrap(), local_id }), |
412 | None => { | 412 | None => { |
413 | self.push_diagnostic(InferenceDiagnostic::NoSuchField { | 413 | self.push_diagnostic(InferenceDiagnostic::NoSuchField { |
414 | expr: tgt_expr, | 414 | expr: field.expr, |
415 | field: field_idx, | ||
416 | }); | 415 | }); |
417 | None | 416 | None |
418 | } | 417 | } |