aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/expr
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/expr')
-rw-r--r--crates/ra_hir/src/expr/validation.rs25
1 files changed, 4 insertions, 21 deletions
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};
6use super::{Expr, ExprId, RecordLitField}; 6use super::{Expr, ExprId, RecordLitField};
7use crate::{ 7use crate::{
8 adt::AdtDef, 8 adt::AdtDef,
9 code_model::Enum,
10 diagnostics::{DiagnosticSink, MissingFields, MissingOkInTailExpr}, 9 diagnostics::{DiagnosticSink, MissingFields, MissingOkInTailExpr},
11 expr::AstPtr, 10 expr::AstPtr,
12 name, 11 name,
13 path::{PathKind, PathSegment}, 12 path::{PathKind, PathSegment},
14 ty::{InferenceResult, Ty, TypeCtor}, 13 ty::{ApplicationTy, InferenceResult, Ty, TypeCtor},
15 Function, HasSource, HirDatabase, ModuleDef, Name, Path, PerNs, Resolution, 14 Function, HasSource, HirDatabase, ModuleDef, Name, Path, PerNs, Resolution,
16}; 15};
17use ra_syntax::ast; 16use ra_syntax::ast;
@@ -120,28 +119,12 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
120 _ => return, 119 _ => return,
121 }; 120 };
122 121
123 let std_result_type = std_result_enum.ty(db); 122 let std_result_ctor = TypeCtor::Adt(AdtDef::Enum(std_result_enum));
124 123 let params = match &mismatch.expected {
125 fn enum_from_type(ty: &Ty) -> Option<Enum> { 124 Ty::Apply(ApplicationTy { ctor, parameters }) if ctor == &std_result_ctor => parameters,
126 match ty {
127 Ty::Apply(t) => match t.ctor {
128 TypeCtor::Adt(AdtDef::Enum(e)) => Some(e),
129 _ => None,
130 },
131 _ => None,
132 }
133 }
134
135 if enum_from_type(&mismatch.expected) != enum_from_type(&std_result_type) {
136 return;
137 }
138
139 let ret = match &mismatch.expected {
140 Ty::Apply(t) => t,
141 _ => return, 125 _ => return,
142 }; 126 };
143 127
144 let params = &ret.parameters;
145 if params.len() == 2 && &params[0] == &mismatch.actual { 128 if params.len() == 2 && &params[0] == &mismatch.actual {
146 let source_map = self.func.body_source_map(db); 129 let source_map = self.func.body_source_map(db);
147 let file_id = self.func.source(db).file_id; 130 let file_id = self.func.source(db).file_id;