@@ -3841,10 +3841,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
38413841 let ctxt = BreakableCtxt {
38423842 // cannot use break with a value from a while loop
38433843 coerce : None ,
3844- may_break : true ,
3844+ may_break : false , // Will get updated if/when we find a `break`.
38453845 } ;
38463846
3847- self . with_breakable_ctxt ( expr. id , ctxt, || {
3847+ let ( ctxt , ( ) ) = self . with_breakable_ctxt ( expr. id , ctxt, || {
38483848 self . check_expr_has_type_or_error ( & cond, tcx. types . bool ) ;
38493849 let cond_diverging = self . diverges . get ( ) ;
38503850 self . check_block_no_value ( & body) ;
@@ -3853,6 +3853,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
38533853 self . diverges . set ( cond_diverging) ;
38543854 } ) ;
38553855
3856+ if ctxt. may_break {
3857+ // No way to know whether it's diverging because
3858+ // of a `break` or an outer `break` or `return`.
3859+ self . diverges . set ( Diverges :: Maybe ) ;
3860+ }
3861+
38563862 self . tcx . mk_nil ( )
38573863 }
38583864 hir:: ExprLoop ( ref body, _, source) => {
@@ -3871,7 +3877,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
38713877
38723878 let ctxt = BreakableCtxt {
38733879 coerce,
3874- may_break : false , // will get updated if/when we find a `break`
3880+ may_break : false , // Will get updated if/when we find a `break`.
38753881 } ;
38763882
38773883 let ( ctxt, ( ) ) = self . with_breakable_ctxt ( expr. id , ctxt, || {
@@ -3880,7 +3886,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
38803886
38813887 if ctxt. may_break {
38823888 // No way to know whether it's diverging because
3883- // of a `break` or an outer `break` or `return.
3889+ // of a `break` or an outer `break` or `return` .
38843890 self . diverges . set ( Diverges :: Maybe ) ;
38853891 }
38863892
0 commit comments