- if let hir::StmtKind::Decl(ref decl, _) = let_stmt.node;
- if let hir::DeclKind::Local(ref decl) = decl.node;
- if let hir::StmtKind::Expr(ref expr, _) = body.node;
+ if let hir::StmtKind::Local(ref local) = let_stmt.kind;
+ if let hir::StmtKind::Expr(ref expr) = body.kind;
+ then {
+ return Some((&*local.pat, &iterargs[0], expr));
+ }
+ }
+ None
+}
+
+/// Recover the essential nodes of a desugared while loop:
+/// `while cond { body }` becomes `(cond, body)`.
+pub fn while_loop(expr: &hir::Expr) -> Option<(&hir::Expr, &hir::Expr)> {
+ if_chain! {
+ if let hir::ExprKind::Loop(block, _, hir::LoopSource::While) = &expr.kind;
+ if let hir::Block { expr: Some(expr), .. } = &**block;
+ if let hir::ExprKind::Match(cond, arms, hir::MatchSource::WhileDesugar) = &expr.kind;
+ if let hir::ExprKind::DropTemps(cond) = &cond.kind;
+ if let [arm, ..] = &arms[..];
+ if let hir::Arm { body, .. } = arm;