From 949a6ec469507db5e79578da94e17cb63cb54d19 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 13 Jun 2021 20:19:11 +0300 Subject: internal: refactor missing or or some diagnostic --- crates/hir/src/diagnostics.rs | 31 ++----------------------------- crates/hir/src/lib.rs | 6 +----- 2 files changed, 3 insertions(+), 34 deletions(-) (limited to 'crates/hir/src') diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index b144bb335..9afee0b90 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs @@ -37,6 +37,7 @@ diagnostics![ MacroError, MismatchedArgCount, MissingFields, + MissingOkOrSomeInTailExpr, MissingUnsafe, NoSuchField, RemoveThisSemicolon, @@ -157,41 +158,13 @@ pub struct RemoveThisSemicolon { pub expr: InFile>, } -// Diagnostic: missing-ok-or-some-in-tail-expr -// -// This diagnostic is triggered if a block that should return `Result` returns a value not wrapped in `Ok`, -// or if a block that should return `Option` returns a value not wrapped in `Some`. -// -// Example: -// -// ```rust -// fn foo() -> Result { -// 10 -// } -// ``` #[derive(Debug)] pub struct MissingOkOrSomeInTailExpr { - pub file: HirFileId, - pub expr: AstPtr, + pub expr: InFile>, // `Some` or `Ok` depending on whether the return type is Result or Option pub required: String, } -impl Diagnostic for MissingOkOrSomeInTailExpr { - fn code(&self) -> DiagnosticCode { - DiagnosticCode("missing-ok-or-some-in-tail-expr") - } - fn message(&self) -> String { - format!("wrap return expression in {}", self.required) - } - fn display_source(&self) -> InFile { - InFile { file_id: self.file, value: self.expr.clone().into() } - } - fn as_any(&self) -> &(dyn Any + Send + 'static) { - self - } -} - // Diagnostic: missing-match-arm // // This diagnostic is triggered if `match` block is missing one or more match arms. diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index cb9bf60b8..aaab5336a 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -1190,11 +1190,7 @@ impl Function { } BodyValidationDiagnostic::MissingOkOrSomeInTailExpr { expr, required } => { match source_map.expr_syntax(expr) { - Ok(source_ptr) => sink.push(MissingOkOrSomeInTailExpr { - file: source_ptr.file_id, - expr: source_ptr.value, - required, - }), + Ok(expr) => acc.push(MissingOkOrSomeInTailExpr { expr, required }.into()), Err(SyntheticSyntax) => (), } } -- cgit v1.2.3