@@ -542,7 +542,7 @@ pub struct FnCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
542
542
/// you get indicates whether any subexpression that was
543
543
/// evaluating up to and including `X` diverged.
544
544
///
545
- /// We use this flag for two purposes:
545
+ /// We currently use this flag only for diagnostic purposes:
546
546
///
547
547
/// - To warn about unreachable code: if, after processing a
548
548
/// sub-expression but before we have applied the effects of the
@@ -556,16 +556,8 @@ pub struct FnCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
556
556
/// foo();}` or `{return; 22}`, where we would warn on the
557
557
/// `foo()` or `22`.
558
558
///
559
- /// - To permit assignment into a local variable or other place
560
- /// (including the "return slot") of type `!`. This is allowed
561
- /// if **either** the type of value being assigned is `!`, which
562
- /// means the current code is dead, **or** the expression's
563
- /// diverging flag is true, which means that a diverging value was
564
- /// wrapped (e.g., `let x: ! = foo(return)`).
565
- ///
566
- /// To repeat the last point: an expression represents dead-code
567
- /// if, after checking it, **either** its type is `!` OR the
568
- /// diverges flag is set to something other than `Maybe`.
559
+ /// An expression represents dead-code if, after checking it,
560
+ /// the diverges flag is set to something other than `Maybe`.
569
561
diverges : Cell < Diverges > ,
570
562
571
563
/// Whether any child nodes have any type errors.
@@ -3002,8 +2994,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3002
2994
& self . cause ( return_expr. span ,
3003
2995
ObligationCauseCode :: ReturnType ( return_expr. id ) ) ,
3004
2996
return_expr,
3005
- return_expr_ty,
3006
- self . diverges . get ( ) ) ;
2997
+ return_expr_ty) ;
3007
2998
}
3008
2999
3009
3000
@@ -3034,13 +3025,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3034
3025
let mut coerce: DynamicCoerceMany = CoerceMany :: new ( coerce_to_ty) ;
3035
3026
3036
3027
let if_cause = self . cause ( sp, ObligationCauseCode :: IfExpression ) ;
3037
- coerce. coerce ( self , & if_cause, then_expr, then_ty, then_diverges ) ;
3028
+ coerce. coerce ( self , & if_cause, then_expr, then_ty) ;
3038
3029
3039
3030
if let Some ( else_expr) = opt_else_expr {
3040
3031
let else_ty = self . check_expr_with_expectation ( else_expr, expected) ;
3041
3032
let else_diverges = self . diverges . get ( ) ;
3042
3033
3043
- coerce. coerce ( self , & if_cause, else_expr, else_ty, else_diverges ) ;
3034
+ coerce. coerce ( self , & if_cause, else_expr, else_ty) ;
3044
3035
3045
3036
// We won't diverge unless both branches do (or the condition does).
3046
3037
self . diverges . set ( cond_diverges | then_diverges & else_diverges) ;
@@ -3733,7 +3724,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3733
3724
}
3734
3725
hir:: ExprBreak ( destination, ref expr_opt) => {
3735
3726
if let Some ( target_id) = destination. target_id . opt_id ( ) {
3736
- let ( e_ty, e_diverges , cause) ;
3727
+ let ( e_ty, cause) ;
3737
3728
if let Some ( ref e) = * expr_opt {
3738
3729
// If this is a break with a value, we need to type-check
3739
3730
// the expression. Get an expected type from the loop context.
@@ -3752,13 +3743,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3752
3743
3753
3744
// Recurse without `enclosing_breakables` borrowed.
3754
3745
e_ty = self . check_expr_with_hint ( e, coerce_to) ;
3755
- e_diverges = self . diverges . get ( ) ;
3756
3746
cause = self . misc ( e. span ) ;
3757
3747
} else {
3758
3748
// Otherwise, this is a break *without* a value. That's
3759
3749
// always legal, and is equivalent to `break ()`.
3760
3750
e_ty = tcx. mk_nil ( ) ;
3761
- e_diverges = Diverges :: Maybe ;
3762
3751
cause = self . misc ( expr. span ) ;
3763
3752
}
3764
3753
@@ -3769,7 +3758,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3769
3758
let ctxt = enclosing_breakables. find_breakable ( target_id) ;
3770
3759
if let Some ( ref mut coerce) = ctxt. coerce {
3771
3760
if let Some ( ref e) = * expr_opt {
3772
- coerce. coerce ( self , & cause, e, e_ty, e_diverges ) ;
3761
+ coerce. coerce ( self , & cause, e, e_ty) ;
3773
3762
} else {
3774
3763
assert ! ( e_ty. is_nil( ) ) ;
3775
3764
coerce. coerce_forced_unit ( self , & cause, & mut |_| ( ) , true ) ;
@@ -3975,7 +3964,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3975
3964
for e in args {
3976
3965
let e_ty = self . check_expr_with_hint ( e, coerce_to) ;
3977
3966
let cause = self . misc ( e. span ) ;
3978
- coerce. coerce ( self , & cause, e, e_ty, self . diverges . get ( ) ) ;
3967
+ coerce. coerce ( self , & cause, e, e_ty) ;
3979
3968
}
3980
3969
coerce. complete ( self )
3981
3970
} else {
@@ -4386,8 +4375,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
4386
4375
coerce. coerce ( self ,
4387
4376
& cause,
4388
4377
tail_expr,
4389
- tail_expr_ty,
4390
- self . diverges . get ( ) ) ;
4378
+ tail_expr_ty) ;
4391
4379
} else {
4392
4380
// Subtle: if there is no explicit tail expression,
4393
4381
// that is typically equivalent to a tail expression
0 commit comments