9393//! It is the responsibility of typeck to ensure that there are no
9494//! `return` expressions in a function declared as diverging.
9595
96- use self :: LoopKind :: * ;
9796use self :: LiveNodeKind :: * ;
9897use self :: VarKind :: * ;
9998
@@ -120,14 +119,6 @@ use crate::hir::{Expr, HirId};
120119use crate :: hir:: def_id:: DefId ;
121120use crate :: hir:: intravisit:: { self , Visitor , FnKind , NestedVisitorMap } ;
122121
123- /// For use with `propagate_through_loop`.
124- enum LoopKind < ' a > {
125- /// An endless `loop` loop.
126- LoopLoop ,
127- /// A `while` loop, with the given expression as condition.
128- WhileLoop ( & ' a Expr ) ,
129- }
130-
131122#[ derive( Copy , Clone , PartialEq ) ]
132123struct Variable ( u32 ) ;
133124
@@ -517,7 +508,6 @@ fn visit_expr<'tcx>(ir: &mut IrMaps<'tcx>, expr: &'tcx Expr) {
517508
518509 // live nodes required for interesting control flow:
519510 hir:: ExprKind :: Match ( ..) |
520- hir:: ExprKind :: While ( ..) |
521511 hir:: ExprKind :: Loop ( ..) => {
522512 ir. add_live_node_for_node ( expr. hir_id , ExprNode ( expr. span ) ) ;
523513 intravisit:: walk_expr ( ir, expr) ;
@@ -1055,14 +1045,10 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
10551045 } )
10561046 }
10571047
1058- hir:: ExprKind :: While ( ref cond, ref blk, _) => {
1059- self . propagate_through_loop ( expr, WhileLoop ( & cond) , & blk, succ)
1060- }
1061-
10621048 // Note that labels have been resolved, so we don't need to look
10631049 // at the label ident
10641050 hir:: ExprKind :: Loop ( ref blk, _, _) => {
1065- self . propagate_through_loop ( expr, LoopLoop , & blk, succ)
1051+ self . propagate_through_loop ( expr, & blk, succ)
10661052 }
10671053
10681054 hir:: ExprKind :: Match ( ref e, ref arms, _) => {
@@ -1353,13 +1339,14 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
13531339 }
13541340 }
13551341
1356- fn propagate_through_loop ( & mut self ,
1357- expr : & Expr ,
1358- kind : LoopKind < ' _ > ,
1359- body : & hir:: Block ,
1360- succ : LiveNode )
1361- -> LiveNode {
1342+ fn propagate_through_loop (
1343+ & mut self ,
1344+ expr : & Expr ,
1345+ body : & hir:: Block ,
1346+ succ : LiveNode
1347+ ) -> LiveNode {
13621348 /*
1349+ FIXME: clean up this description.
13631350
13641351 We model control flow like this:
13651352
@@ -1377,50 +1364,26 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
13771364
13781365 */
13791366
1380-
13811367 // first iteration:
13821368 let mut first_merge = true ;
13831369 let ln = self . live_node ( expr. hir_id , expr. span ) ;
13841370 self . init_empty ( ln, succ) ;
1385- match kind {
1386- LoopLoop => { }
1387- _ => {
1388- // If this is not a `loop` loop, then it's possible we bypass
1389- // the body altogether. Otherwise, the only way is via a `break`
1390- // in the loop body.
1391- self . merge_from_succ ( ln, succ, first_merge) ;
1392- first_merge = false ;
1393- }
1394- }
13951371 debug ! ( "propagate_through_loop: using id for loop body {} {}" ,
13961372 expr. hir_id, self . ir. tcx. hir( ) . hir_to_pretty_string( body. hir_id) ) ;
13971373
13981374 self . break_ln . insert ( expr. hir_id , succ) ;
13991375
1400- let cond_ln = match kind {
1401- LoopLoop => ln,
1402- WhileLoop ( ref cond) => self . propagate_through_expr ( & cond, ln) ,
1403- } ;
1404-
1405- self . cont_ln . insert ( expr. hir_id , cond_ln) ;
1376+ self . cont_ln . insert ( expr. hir_id , ln) ;
14061377
1407- let body_ln = self . propagate_through_block ( body, cond_ln ) ;
1378+ let body_ln = self . propagate_through_block ( body, ln ) ;
14081379
14091380 // repeat until fixed point is reached:
14101381 while self . merge_from_succ ( ln, body_ln, first_merge) {
14111382 first_merge = false ;
1412-
1413- let new_cond_ln = match kind {
1414- LoopLoop => ln,
1415- WhileLoop ( ref cond) => {
1416- self . propagate_through_expr ( & cond, ln)
1417- }
1418- } ;
1419- assert_eq ! ( cond_ln, new_cond_ln) ;
1420- assert_eq ! ( body_ln, self . propagate_through_block( body, cond_ln) ) ;
1383+ assert_eq ! ( body_ln, self . propagate_through_block( body, ln) ) ;
14211384 }
14221385
1423- cond_ln
1386+ ln
14241387 }
14251388}
14261389
@@ -1520,7 +1483,7 @@ fn check_expr<'a, 'tcx>(this: &mut Liveness<'a, 'tcx>, expr: &'tcx Expr) {
15201483
15211484 // no correctness conditions related to liveness
15221485 hir:: ExprKind :: Call ( ..) | hir:: ExprKind :: MethodCall ( ..) |
1523- hir:: ExprKind :: Match ( ..) | hir:: ExprKind :: While ( .. ) | hir :: ExprKind :: Loop ( ..) |
1486+ hir:: ExprKind :: Match ( ..) | hir:: ExprKind :: Loop ( ..) |
15241487 hir:: ExprKind :: Index ( ..) | hir:: ExprKind :: Field ( ..) |
15251488 hir:: ExprKind :: Array ( ..) | hir:: ExprKind :: Tup ( ..) | hir:: ExprKind :: Binary ( ..) |
15261489 hir:: ExprKind :: Cast ( ..) | hir:: ExprKind :: DropTemps ( ..) | hir:: ExprKind :: Unary ( ..) |
0 commit comments