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_ty/src/infer.rs | 6 +++--- crates/hir_ty/src/infer/expr.rs | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'crates/hir_ty/src') 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 { #[derive(Debug, PartialEq, Eq, Clone)] pub(super) enum InferenceDiagnostic { - NoSuchField { expr: ExprId, field: usize }, + NoSuchField { expr: ExprId }, BreakOutsideOfLoop { expr: ExprId }, } @@ -796,9 +796,9 @@ mod diagnostics { sink: &mut DiagnosticSink, ) { match self { - InferenceDiagnostic::NoSuchField { expr, field } => { + InferenceDiagnostic::NoSuchField { expr } => { let (_, source_map) = db.body_with_source_map(owner); - let field = source_map.field_syntax(*expr, *field); + let field = source_map.field_syntax(*expr); sink.push(NoSuchField { file: field.file_id, field: field.value }) } 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> { let substs = ty.substs().cloned().unwrap_or_else(Substs::empty); let field_types = def_id.map(|it| self.db.field_types(it)).unwrap_or_default(); let variant_data = def_id.map(|it| variant_data(self.db.upcast(), it)); - for (field_idx, field) in fields.iter().enumerate() { + for field in fields.iter() { let field_def = variant_data.as_ref().and_then(|it| match it.field(&field.name) { Some(local_id) => Some(FieldId { parent: def_id.unwrap(), local_id }), None => { self.push_diagnostic(InferenceDiagnostic::NoSuchField { - expr: tgt_expr, - field: field_idx, + expr: field.expr, }); None } -- cgit v1.2.3