From de1fc70ccd3bf7a0850e036a12cf866a80d46458 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 13 Jun 2021 20:32:54 +0300 Subject: internal: refactor find_map diagnostic --- crates/hir/src/diagnostics.rs | 19 +------------------ crates/hir/src/lib.rs | 11 +++++++---- 2 files changed, 8 insertions(+), 22 deletions(-) (limited to 'crates/hir') diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index 9afee0b90..c294a803b 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs @@ -41,6 +41,7 @@ diagnostics![ MissingUnsafe, NoSuchField, RemoveThisSemicolon, + ReplaceFilterMapNextWithFindMap, UnimplementedBuiltinMacro, UnresolvedExternCrate, UnresolvedImport, @@ -121,9 +122,6 @@ pub struct MissingFields { pub missed_fields: Vec, } -// Diagnostic: replace-filter-map-next-with-find-map -// -// This diagnostic is triggered when `.filter_map(..).next()` is used, rather than the more concise `.find_map(..)`. #[derive(Debug)] pub struct ReplaceFilterMapNextWithFindMap { pub file: HirFileId, @@ -131,21 +129,6 @@ pub struct ReplaceFilterMapNextWithFindMap { pub next_expr: AstPtr, } -impl Diagnostic for ReplaceFilterMapNextWithFindMap { - fn code(&self) -> DiagnosticCode { - DiagnosticCode("replace-filter-map-next-with-find-map") - } - fn message(&self) -> String { - "replace filter_map(..).next() with find_map(..)".to_string() - } - fn display_source(&self) -> InFile { - InFile { file_id: self.file, value: self.next_expr.clone().into() } - } - fn as_any(&self) -> &(dyn Any + Send + 'static) { - self - } -} - #[derive(Debug)] pub struct MismatchedArgCount { pub call_expr: InFile>, diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index aaab5336a..b2731b62f 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -1168,10 +1168,13 @@ impl Function { } BodyValidationDiagnostic::ReplaceFilterMapNextWithFindMap { method_call_expr } => { if let Ok(next_source_ptr) = source_map.expr_syntax(method_call_expr) { - sink.push(ReplaceFilterMapNextWithFindMap { - file: next_source_ptr.file_id, - next_expr: next_source_ptr.value, - }); + acc.push( + ReplaceFilterMapNextWithFindMap { + file: next_source_ptr.file_id, + next_expr: next_source_ptr.value, + } + .into(), + ); } } BodyValidationDiagnostic::MismatchedArgCount { call_expr, expected, found } => { -- cgit v1.2.3