@@ -13,6 +13,7 @@ use hir_def::{
13
13
ArithOp , Array , BinaryOp , ClosureKind , Expr , ExprId , LabelId , Literal , Statement , UnaryOp ,
14
14
} ,
15
15
generics:: TypeOrConstParamData ,
16
+ lang_item:: LangItem ,
16
17
path:: { GenericArg , GenericArgs } ,
17
18
resolver:: resolver_for_expr,
18
19
ConstParamId , FieldId , ItemContainerId , Lookup ,
@@ -157,7 +158,8 @@ impl<'a> InferenceContext<'a> {
157
158
}
158
159
159
160
// 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 ( ) ) ;
161
163
162
164
self . with_breakable_ctx ( BreakableKind :: Block , ok_ty. clone ( ) , None , |this| {
163
165
this. infer_expr ( * body, & Expectation :: has_type ( ok_ty) ) ;
@@ -593,9 +595,19 @@ impl<'a> InferenceContext<'a> {
593
595
self . resolve_associated_type ( inner_ty, self . resolve_future_future_output ( ) )
594
596
}
595
597
Expr :: Try { expr } => {
596
- // FIXME: Note down method resolution her
597
598
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
+ }
599
611
}
600
612
Expr :: Cast { expr, type_ref } => {
601
613
// FIXME: propagate the "castable to" expectation (and find a test case that shows this is necessary)
@@ -744,7 +756,7 @@ impl<'a> InferenceContext<'a> {
744
756
let base_ty = self . infer_expr_inner ( * base, & Expectation :: none ( ) ) ;
745
757
let index_ty = self . infer_expr ( * index, & Expectation :: none ( ) ) ;
746
758
747
- if let Some ( index_trait) = self . resolve_ops_index ( ) {
759
+ if let Some ( index_trait) = self . resolve_lang_trait ( LangItem :: Index ) {
748
760
let canonicalized = self . canonicalize ( base_ty. clone ( ) ) ;
749
761
let receiver_adjustments = method_resolution:: resolve_indexing_op (
750
762
self . db ,
0 commit comments