@@ -3843,10 +3843,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3843
3843
let ctxt = BreakableCtxt {
3844
3844
// cannot use break with a value from a while loop
3845
3845
coerce : None ,
3846
- may_break : true ,
3846
+ may_break : false , // Will get updated if/when we find a `break`.
3847
3847
} ;
3848
3848
3849
- self . with_breakable_ctxt ( expr. id , ctxt, || {
3849
+ let ( ctxt , ( ) ) = self . with_breakable_ctxt ( expr. id , ctxt, || {
3850
3850
self . check_expr_has_type_or_error ( & cond, tcx. types . bool ) ;
3851
3851
let cond_diverging = self . diverges . get ( ) ;
3852
3852
self . check_block_no_value ( & body) ;
@@ -3855,6 +3855,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3855
3855
self . diverges . set ( cond_diverging) ;
3856
3856
} ) ;
3857
3857
3858
+ if ctxt. may_break {
3859
+ // No way to know whether it's diverging because
3860
+ // of a `break` or an outer `break` or `return`.
3861
+ self . diverges . set ( Diverges :: Maybe ) ;
3862
+ }
3863
+
3858
3864
self . tcx . mk_nil ( )
3859
3865
}
3860
3866
hir:: ExprLoop ( ref body, _, source) => {
@@ -3873,7 +3879,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3873
3879
3874
3880
let ctxt = BreakableCtxt {
3875
3881
coerce,
3876
- may_break : false , // will get updated if/when we find a `break`
3882
+ may_break : false , // Will get updated if/when we find a `break`.
3877
3883
} ;
3878
3884
3879
3885
let ( ctxt, ( ) ) = self . with_breakable_ctxt ( expr. id , ctxt, || {
@@ -3882,7 +3888,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3882
3888
3883
3889
if ctxt. may_break {
3884
3890
// No way to know whether it's diverging because
3885
- // of a `break` or an outer `break` or `return.
3891
+ // of a `break` or an outer `break` or `return` .
3886
3892
self . diverges . set ( Diverges :: Maybe ) ;
3887
3893
}
3888
3894
0 commit comments