From b2dbe6e43a28a22be2b5d8631dff83b644520f59 Mon Sep 17 00:00:00 2001 From: Phil Ellison Date: Wed, 30 Dec 2020 17:23:00 +0000 Subject: Add fix to wrap return expression in Some --- crates/hir_ty/src/diagnostics.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'crates/hir_ty/src/diagnostics.rs') diff --git a/crates/hir_ty/src/diagnostics.rs b/crates/hir_ty/src/diagnostics.rs index 14e18f5a1..c67a289f2 100644 --- a/crates/hir_ty/src/diagnostics.rs +++ b/crates/hir_ty/src/diagnostics.rs @@ -186,9 +186,10 @@ impl Diagnostic for MissingMatchArms { } } -// Diagnostic: missing-ok-in-tail-expr +// Diagnostic: missing-ok-or-some-in-tail-expr // -// This diagnostic is triggered if block that should return `Result` returns a value not wrapped in `Ok`. +// 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: // @@ -198,17 +199,19 @@ impl Diagnostic for MissingMatchArms { // } // ``` #[derive(Debug)] -pub struct MissingOkInTailExpr { +pub struct MissingOkOrSomeInTailExpr { pub file: HirFileId, pub expr: AstPtr, + // `Some` or `Ok` depending on whether the return type is Result or Option + pub required: String, } -impl Diagnostic for MissingOkInTailExpr { +impl Diagnostic for MissingOkOrSomeInTailExpr { fn code(&self) -> DiagnosticCode { - DiagnosticCode("missing-ok-in-tail-expr") + DiagnosticCode("missing-ok-or-some-in-tail-expr") } fn message(&self) -> String { - "wrap return expression in Ok".to_string() + format!("wrap return expression in {}", self.required) } fn display_source(&self) -> InFile { InFile { file_id: self.file, value: self.expr.clone().into() } -- cgit v1.2.3