File tree Expand file tree Collapse file tree 2 files changed +31
-6
lines changed Expand file tree Collapse file tree 2 files changed +31
-6
lines changed Original file line number Diff line number Diff line change @@ -366,13 +366,21 @@ impl<'a> InferenceContext<'a> {
366
366
for arm in arms {
367
367
self . diverges = Diverges :: Maybe ;
368
368
let _pat_ty = self . infer_pat ( arm. pat , & input_ty, BindingMode :: default ( ) ) ;
369
- if let Some ( MatchGuard :: If { expr : guard_expr } ) = arm. guard {
370
- self . infer_expr (
371
- guard_expr,
372
- & Expectation :: has_type ( TyKind :: Scalar ( Scalar :: Bool ) . intern ( & Interner ) ) ,
373
- ) ;
369
+ match arm. guard {
370
+ Some ( MatchGuard :: If { expr : guard_expr } ) => {
371
+ self . infer_expr (
372
+ guard_expr,
373
+ & Expectation :: has_type (
374
+ TyKind :: Scalar ( Scalar :: Bool ) . intern ( & Interner ) ,
375
+ ) ,
376
+ ) ;
377
+ }
378
+ Some ( MatchGuard :: IfLet { expr, pat } ) => {
379
+ let input_ty = self . infer_expr ( expr, & Expectation :: none ( ) ) ;
380
+ let _pat_ty = self . infer_pat ( pat, & input_ty, BindingMode :: default ( ) ) ;
381
+ }
382
+ _ => { }
374
383
}
375
- // FIXME: infer `if let` guard
376
384
377
385
let arm_ty = self . infer_expr_inner ( arm. expr , & expected) ;
378
386
all_arms_diverge &= self . diverges ;
Original file line number Diff line number Diff line change @@ -916,3 +916,20 @@ fn main() {
916
916
"# ,
917
917
) ;
918
918
}
919
+
920
+ #[ test]
921
+ fn if_let_guards ( ) {
922
+ check_types (
923
+ r#"
924
+ fn main() {
925
+ match (0,) {
926
+ opt if let (x,) = opt => {
927
+ x;
928
+ //^ i32
929
+ }
930
+ _ => {}
931
+ }
932
+ }
933
+ "# ,
934
+ ) ;
935
+ }
You can’t perform that action at this time.
0 commit comments