@@ -11,7 +11,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11
11
pub fn check_match (
12
12
& self ,
13
13
expr : & ' tcx hir:: Expr < ' tcx > ,
14
- discrim : & ' tcx hir:: Expr < ' tcx > ,
14
+ scrut : & ' tcx hir:: Expr < ' tcx > ,
15
15
arms : & ' tcx [ hir:: Arm < ' tcx > ] ,
16
16
expected : Expectation < ' tcx > ,
17
17
match_src : hir:: MatchSource ,
@@ -27,7 +27,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
27
27
} ;
28
28
29
29
// Type check the descriminant and get its type.
30
- let discrim_ty = if force_scrutinee_bool {
30
+ let scrut_ty = if force_scrutinee_bool {
31
31
// Here we want to ensure:
32
32
//
33
33
// 1. That default match bindings are *not* accepted in the condition of an
@@ -36,9 +36,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
36
36
// 2. By expecting `bool` for `expr` we get nice diagnostics for e.g. `if x = y { .. }`.
37
37
//
38
38
// FIXME(60707): Consider removing hack with principled solution.
39
- self . check_expr_has_type_or_error ( discrim , self . tcx . types . bool , |_| { } )
39
+ self . check_expr_has_type_or_error ( scrut , self . tcx . types . bool , |_| { } )
40
40
} else {
41
- self . demand_discriminant_type ( arms, discrim )
41
+ self . demand_scrutinee_type ( arms, scrut )
42
42
} ;
43
43
44
44
// If there are no arms, that is a diverging match; a special case.
@@ -51,7 +51,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
51
51
52
52
// Otherwise, we have to union together the types that the
53
53
// arms produce and so forth.
54
- let discrim_diverges = self . diverges . get ( ) ;
54
+ let scrut_diverges = self . diverges . get ( ) ;
55
55
self . diverges . set ( Diverges :: Maybe ) ;
56
56
57
57
// rust-lang/rust#55810: Typecheck patterns first (via eager
@@ -61,7 +61,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
61
61
. map ( |arm| {
62
62
let mut all_pats_diverge = Diverges :: WarnedAlways ;
63
63
self . diverges . set ( Diverges :: Maybe ) ;
64
- self . check_pat_top ( & arm. pat , discrim_ty , Some ( discrim . span ) ) ;
64
+ self . check_pat_top ( & arm. pat , scrut_ty , Some ( scrut . span ) , true ) ;
65
65
all_pats_diverge &= self . diverges . get ( ) ;
66
66
67
67
// As discussed with @eddyb, this is for disabling unreachable_code
@@ -157,7 +157,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
157
157
source : match_src,
158
158
prior_arms : other_arms. clone ( ) ,
159
159
last_ty : prior_arm_ty. unwrap ( ) ,
160
- discrim_hir_id : discrim . hir_id ,
160
+ scrut_hir_id : scrut . hir_id ,
161
161
} ) ,
162
162
) ,
163
163
} ;
@@ -186,8 +186,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
186
186
} ;
187
187
}
188
188
189
- // We won't diverge unless the discriminant or all arms diverge.
190
- self . diverges . set ( discrim_diverges | all_arms_diverge) ;
189
+ // We won't diverge unless the scrutinee or all arms diverge.
190
+ self . diverges . set ( scrut_diverges | all_arms_diverge) ;
191
191
192
192
coercion. complete ( self )
193
193
}
@@ -388,14 +388,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
388
388
)
389
389
}
390
390
391
- fn demand_discriminant_type (
391
+ fn demand_scrutinee_type (
392
392
& self ,
393
393
arms : & ' tcx [ hir:: Arm < ' tcx > ] ,
394
- discrim : & ' tcx hir:: Expr < ' tcx > ,
394
+ scrut : & ' tcx hir:: Expr < ' tcx > ,
395
395
) -> Ty < ' tcx > {
396
396
// Not entirely obvious: if matches may create ref bindings, we want to
397
- // use the *precise* type of the discriminant , *not* some supertype, as
398
- // the "discriminant type" (issue #23116).
397
+ // use the *precise* type of the scrutinee , *not* some supertype, as
398
+ // the "scrutinee type" (issue #23116).
399
399
//
400
400
// arielb1 [writes here in this comment thread][c] that there
401
401
// is certainly *some* potential danger, e.g., for an example
@@ -454,17 +454,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
454
454
} ) ;
455
455
456
456
if let Some ( m) = contains_ref_bindings {
457
- self . check_expr_with_needs ( discrim , Needs :: maybe_mut_place ( m) )
457
+ self . check_expr_with_needs ( scrut , Needs :: maybe_mut_place ( m) )
458
458
} else {
459
459
// ...but otherwise we want to use any supertype of the
460
- // discriminant . This is sort of a workaround, see note (*) in
460
+ // scrutinee . This is sort of a workaround, see note (*) in
461
461
// `check_pat` for some details.
462
- let discrim_ty = self . next_ty_var ( TypeVariableOrigin {
462
+ let scrut_ty = self . next_ty_var ( TypeVariableOrigin {
463
463
kind : TypeVariableOriginKind :: TypeInference ,
464
- span : discrim . span ,
464
+ span : scrut . span ,
465
465
} ) ;
466
- self . check_expr_has_type_or_error ( discrim , discrim_ty , |_| { } ) ;
467
- discrim_ty
466
+ self . check_expr_has_type_or_error ( scrut , scrut_ty , |_| { } ) ;
467
+ scrut_ty
468
468
}
469
469
}
470
470
}
0 commit comments