@@ -93,28 +93,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
93
93
self . check_expr_assign ( expr, expected, lhs, rhs)
94
94
}
95
95
ExprKind :: While ( ref cond, ref body, _) => {
96
- let ctxt = BreakableCtxt {
97
- // cannot use break with a value from a while loop
98
- coerce : None ,
99
- may_break : false , // Will get updated if/when we find a `break`.
100
- } ;
101
-
102
- let ( ctxt, ( ) ) = self . with_breakable_ctxt ( expr. hir_id , ctxt, || {
103
- self . check_expr_has_type_or_error ( & cond, tcx. types . bool ) ;
104
- let cond_diverging = self . diverges . get ( ) ;
105
- self . check_block_no_value ( & body) ;
106
-
107
- // We may never reach the body so it diverging means nothing.
108
- self . diverges . set ( cond_diverging) ;
109
- } ) ;
110
-
111
- if ctxt. may_break {
112
- // No way to know whether it's diverging because
113
- // of a `break` or an outer `break` or `return`.
114
- self . diverges . set ( Diverges :: Maybe ) ;
115
- }
116
-
117
- self . tcx . mk_unit ( )
96
+ self . check_expr_while ( cond, body, expr)
118
97
}
119
98
ExprKind :: Loop ( ref body, _, source) => {
120
99
let coerce = match source {
@@ -787,4 +766,34 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
787
766
self . tcx . mk_unit ( )
788
767
}
789
768
}
769
+
770
+ fn check_expr_while (
771
+ & self ,
772
+ cond : & ' tcx hir:: Expr ,
773
+ body : & ' tcx hir:: Block ,
774
+ expr : & ' tcx hir:: Expr
775
+ ) -> Ty < ' tcx > {
776
+ let ctxt = BreakableCtxt {
777
+ // Cannot use break with a value from a while loop.
778
+ coerce : None ,
779
+ may_break : false , // Will get updated if/when we find a `break`.
780
+ } ;
781
+
782
+ let ( ctxt, ( ) ) = self . with_breakable_ctxt ( expr. hir_id , ctxt, || {
783
+ self . check_expr_has_type_or_error ( & cond, self . tcx . types . bool ) ;
784
+ let cond_diverging = self . diverges . get ( ) ;
785
+ self . check_block_no_value ( & body) ;
786
+
787
+ // We may never reach the body so it diverging means nothing.
788
+ self . diverges . set ( cond_diverging) ;
789
+ } ) ;
790
+
791
+ if ctxt. may_break {
792
+ // No way to know whether it's diverging because
793
+ // of a `break` or an outer `break` or `return`.
794
+ self . diverges . set ( Diverges :: Maybe ) ;
795
+ }
796
+
797
+ self . tcx . mk_unit ( )
798
+ }
790
799
}
0 commit comments