aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/infer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty/infer.rs')
-rw-r--r--crates/ra_hir/src/ty/infer.rs39
1 files changed, 37 insertions, 2 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index 52a49070a..2f1c50355 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -1140,8 +1140,23 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1140 self.insert_type_vars(ty) 1140 self.insert_type_vars(ty)
1141 } 1141 }
1142 Expr::Try { expr } => { 1142 Expr::Try { expr } => {
1143 let _inner_ty = self.infer_expr(*expr, &Expectation::none()); 1143 let inner_ty = self.infer_expr(*expr, &Expectation::none());
1144 Ty::Unknown 1144 let ty = match self.resolve_ops_try_ok() {
1145 Some(ops_try_ok_alias) => {
1146 let ty = self.new_type_var();
1147 let projection = ProjectionPredicate {
1148 ty: ty.clone(),
1149 projection_ty: ProjectionTy {
1150 associated_ty: ops_try_ok_alias,
1151 parameters: vec![inner_ty].into(),
1152 },
1153 };
1154 self.obligations.push(Obligation::Projection(projection));
1155 self.resolve_ty_as_possible(&mut vec![], ty)
1156 }
1157 None => Ty::Unknown,
1158 };
1159 ty
1145 } 1160 }
1146 Expr::Cast { expr, type_ref } => { 1161 Expr::Cast { expr, type_ref } => {
1147 let _inner_ty = self.infer_expr(*expr, &Expectation::none()); 1162 let _inner_ty = self.infer_expr(*expr, &Expectation::none());
@@ -1360,6 +1375,26 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1360 _ => None, 1375 _ => None,
1361 } 1376 }
1362 } 1377 }
1378
1379 fn resolve_ops_try_ok(&self) -> Option<TypeAlias> {
1380 use crate::name::{OK, OPS, TRY};
1381
1382 let ops_try_path = Path {
1383 kind: PathKind::Abs,
1384 segments: vec![
1385 PathSegment { name: STD, args_and_bindings: None },
1386 PathSegment { name: OPS, args_and_bindings: None },
1387 PathSegment { name: TRY, args_and_bindings: None },
1388 ],
1389 };
1390
1391 match self.resolver.resolve_path_segments(self.db, &ops_try_path).into_fully_resolved() {
1392 PerNs { types: Some(Def(Trait(trait_))), .. } => {
1393 Some(trait_.associated_type_by_name(self.db, OK)?)
1394 }
1395 _ => None,
1396 }
1397 }
1363} 1398}
1364 1399
1365/// The ID of a type variable. 1400/// The ID of a type variable.