From 7166e8549bad95b05f66acd508d07a6cd97d3dc0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 13 Jun 2021 19:45:16 +0300 Subject: internal: refactor NoSuchField diagnostic --- crates/hir/src/diagnostics.rs | 25 ++----------------------- crates/hir/src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 24 deletions(-) (limited to 'crates/hir') diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index 3908e67a2..c7702e09f 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs @@ -35,6 +35,7 @@ diagnostics![ InactiveCode, MacroError, MissingFields, + NoSuchField, UnimplementedBuiltinMacro, UnresolvedExternCrate, UnresolvedImport, @@ -92,31 +93,9 @@ pub struct UnimplementedBuiltinMacro { pub node: InFile, } -// Diagnostic: no-such-field -// -// This diagnostic is triggered if created structure does not have field provided in record. #[derive(Debug)] pub struct NoSuchField { - pub file: HirFileId, - pub field: AstPtr, -} - -impl Diagnostic for NoSuchField { - fn code(&self) -> DiagnosticCode { - DiagnosticCode("no-such-field") - } - - fn message(&self) -> String { - "no such field".to_string() - } - - fn display_source(&self) -> InFile { - InFile::new(self.file, self.field.clone().into()) - } - - fn as_any(&self) -> &(dyn Any + Send + 'static) { - self - } + pub field: InFile>, } // Diagnostic: break-outside-of-loop diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index a361158e0..7faf6ec1f 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -1077,7 +1077,7 @@ impl Function { match d { hir_ty::InferenceDiagnostic::NoSuchField { expr } => { let field = source_map.field_syntax(*expr); - sink.push(NoSuchField { file: field.file_id, field: field.value }) + acc.push(NoSuchField { field }.into()) } hir_ty::InferenceDiagnostic::BreakOutsideOfLoop { expr } => { let ptr = source_map -- cgit v1.2.3