From 6620949caee25128416acf285590b0d5558e4597 Mon Sep 17 00:00:00 2001 From: Phil Ellison Date: Sat, 17 Aug 2019 06:31:53 +0100 Subject: Simplify checking return type, add new test --- crates/ra_hir/src/expr/validation.rs | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) (limited to 'crates/ra_hir/src/expr') diff --git a/crates/ra_hir/src/expr/validation.rs b/crates/ra_hir/src/expr/validation.rs index e35990d2e..5d9d59ff8 100644 --- a/crates/ra_hir/src/expr/validation.rs +++ b/crates/ra_hir/src/expr/validation.rs @@ -6,12 +6,11 @@ use ra_syntax::ast::{AstNode, RecordLit}; use super::{Expr, ExprId, RecordLitField}; use crate::{ adt::AdtDef, - code_model::Enum, diagnostics::{DiagnosticSink, MissingFields, MissingOkInTailExpr}, expr::AstPtr, name, path::{PathKind, PathSegment}, - ty::{InferenceResult, Ty, TypeCtor}, + ty::{ApplicationTy, InferenceResult, Ty, TypeCtor}, Function, HasSource, HirDatabase, ModuleDef, Name, Path, PerNs, Resolution, }; use ra_syntax::ast; @@ -120,28 +119,12 @@ impl<'a, 'b> ExprValidator<'a, 'b> { _ => return, }; - let std_result_type = std_result_enum.ty(db); - - fn enum_from_type(ty: &Ty) -> Option { - match ty { - Ty::Apply(t) => match t.ctor { - TypeCtor::Adt(AdtDef::Enum(e)) => Some(e), - _ => None, - }, - _ => None, - } - } - - if enum_from_type(&mismatch.expected) != enum_from_type(&std_result_type) { - return; - } - - let ret = match &mismatch.expected { - Ty::Apply(t) => t, + let std_result_ctor = TypeCtor::Adt(AdtDef::Enum(std_result_enum)); + let params = match &mismatch.expected { + Ty::Apply(ApplicationTy { ctor, parameters }) if ctor == &std_result_ctor => parameters, _ => return, }; - let params = &ret.parameters; if params.len() == 2 && ¶ms[0] == &mismatch.actual { let source_map = self.func.body_source_map(db); let file_id = self.func.source(db).file_id; -- cgit v1.2.3