@@ -3843,10 +3843,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
38433843 let ctxt = BreakableCtxt {
38443844 // cannot use break with a value from a while loop
38453845 coerce : None ,
3846- may_break : true ,
3846+ may_break : false , // Will get updated if/when we find a `break`.
38473847 } ;
38483848
3849- self . with_breakable_ctxt ( expr. id , ctxt, || {
3849+ let ( ctxt , ( ) ) = self . with_breakable_ctxt ( expr. id , ctxt, || {
38503850 self . check_expr_has_type_or_error ( & cond, tcx. types . bool ) ;
38513851 let cond_diverging = self . diverges . get ( ) ;
38523852 self . check_block_no_value ( & body) ;
@@ -3855,6 +3855,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
38553855 self . diverges . set ( cond_diverging) ;
38563856 } ) ;
38573857
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+
38583864 self . tcx . mk_nil ( )
38593865 }
38603866 hir:: ExprLoop ( ref body, _, source) => {
@@ -3873,7 +3879,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
38733879
38743880 let ctxt = BreakableCtxt {
38753881 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`.
38773883 } ;
38783884
38793885 let ( ctxt, ( ) ) = self . with_breakable_ctxt ( expr. id , ctxt, || {
@@ -3882,7 +3888,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
38823888
38833889 if ctxt. may_break {
38843890 // 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` .
38863892 self . diverges . set ( Diverges :: Maybe ) ;
38873893 }
38883894
0 commit comments