@@ -793,11 +793,12 @@ impl InferenceContext<'_> {
793793 . trait_data ( index_trait)
794794 . method_by_name ( & Name :: new_symbol_root ( sym:: index. clone ( ) ) )
795795 {
796- let substs = TyBuilder :: subst_for_def ( self . db , index_trait, None )
797- . push ( self_ty. clone ( ) )
798- . push ( index_ty. clone ( ) )
799- . build ( ) ;
800- self . write_method_resolution ( tgt_expr, func, substs) ;
796+ let subst = TyBuilder :: subst_for_def ( self . db , index_trait, None ) ;
797+ if subst. remaining ( ) != 2 {
798+ return self . err_ty ( ) ;
799+ }
800+ let subst = subst. push ( self_ty. clone ( ) ) . push ( index_ty. clone ( ) ) . build ( ) ;
801+ self . write_method_resolution ( tgt_expr, func, subst) ;
801802 }
802803 let assoc = self . resolve_ops_index_output ( ) ;
803804 let res = self . resolve_associated_type_with_params (
@@ -1295,10 +1296,12 @@ impl InferenceContext<'_> {
12951296
12961297 // HACK: We can use this substitution for the function because the function itself doesn't
12971298 // have its own generic parameters.
1298- let subst = TyBuilder :: subst_for_def ( self . db , trait_, None )
1299- . push ( lhs_ty. clone ( ) )
1300- . push ( rhs_ty. clone ( ) )
1301- . build ( ) ;
1299+ let subst = TyBuilder :: subst_for_def ( self . db , trait_, None ) ;
1300+ if subst. remaining ( ) != 2 {
1301+ return Ty :: new ( Interner , TyKind :: Error ) ;
1302+ }
1303+ let subst = subst. push ( lhs_ty. clone ( ) ) . push ( rhs_ty. clone ( ) ) . build ( ) ;
1304+
13021305 self . write_method_resolution ( tgt_expr, func, subst. clone ( ) ) ;
13031306
13041307 let method_ty = self . db . value_ty ( func. into ( ) ) . unwrap ( ) . substitute ( Interner , & subst) ;
0 commit comments