@@ -13,6 +13,7 @@ use hir_def::{
1313 ArithOp , Array , BinaryOp , ClosureKind , Expr , ExprId , LabelId , Literal , Statement , UnaryOp ,
1414 } ,
1515 generics:: TypeOrConstParamData ,
16+ lang_item:: LangItem ,
1617 path:: { GenericArg , GenericArgs } ,
1718 resolver:: resolver_for_expr,
1819 ConstParamId , FieldId , ItemContainerId , Lookup ,
@@ -157,7 +158,8 @@ impl<'a> InferenceContext<'a> {
157158 }
158159
159160 // The ok-ish type that is expected from the last expression
160- let ok_ty = self . resolve_associated_type ( try_ty. clone ( ) , self . resolve_ops_try_ok ( ) ) ;
161+ let ok_ty =
162+ self . resolve_associated_type ( try_ty. clone ( ) , self . resolve_ops_try_output ( ) ) ;
161163
162164 self . with_breakable_ctx ( BreakableKind :: Block , ok_ty. clone ( ) , None , |this| {
163165 this. infer_expr ( * body, & Expectation :: has_type ( ok_ty) ) ;
@@ -593,9 +595,19 @@ impl<'a> InferenceContext<'a> {
593595 self . resolve_associated_type ( inner_ty, self . resolve_future_future_output ( ) )
594596 }
595597 Expr :: Try { expr } => {
596- // FIXME: Note down method resolution her
597598 let inner_ty = self . infer_expr_inner ( * expr, & Expectation :: none ( ) ) ;
598- self . resolve_associated_type ( inner_ty, self . resolve_ops_try_ok ( ) )
599+ if let Some ( trait_) = self . resolve_lang_trait ( LangItem :: Try ) {
600+ if let Some ( func) = self . db . trait_data ( trait_) . method_by_name ( & name ! ( branch) ) {
601+ let subst = TyBuilder :: subst_for_def ( self . db , trait_, None )
602+ . push ( inner_ty. clone ( ) )
603+ . build ( ) ;
604+ self . write_method_resolution ( tgt_expr, func, subst. clone ( ) ) ;
605+ }
606+ let try_output = self . resolve_output_on ( trait_) ;
607+ self . resolve_associated_type ( inner_ty, try_output)
608+ } else {
609+ self . err_ty ( )
610+ }
599611 }
600612 Expr :: Cast { expr, type_ref } => {
601613 // FIXME: propagate the "castable to" expectation (and find a test case that shows this is necessary)
@@ -744,7 +756,7 @@ impl<'a> InferenceContext<'a> {
744756 let base_ty = self . infer_expr_inner ( * base, & Expectation :: none ( ) ) ;
745757 let index_ty = self . infer_expr ( * index, & Expectation :: none ( ) ) ;
746758
747- if let Some ( index_trait) = self . resolve_ops_index ( ) {
759+ if let Some ( index_trait) = self . resolve_lang_trait ( LangItem :: Index ) {
748760 let canonicalized = self . canonicalize ( base_ty. clone ( ) ) ;
749761 let receiver_adjustments = method_resolution:: resolve_indexing_op (
750762 self . db ,
0 commit comments