From 3801d216e2ed5284518a956f11019eb199ee909c Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Tue, 7 Jan 2020 10:50:35 +0700 Subject: [PATCH] Make utils::remove_blocks non-recursive --- clippy_lints/src/utils/mod.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 3c806cc7ea5..16ff010846f 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -873,12 +873,11 @@ pub fn is_automatically_derived(attrs: &[ast::Attribute]) -> bool { /// /// Ie. `x`, `{ x }` and `{{{{ x }}}}` all give `x`. `{ x; y }` and `{}` return /// themselves. -pub fn remove_blocks<'tcx>(expr: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> { - if let ExprKind::Block(ref block, _) = expr.kind { - if block.stmts.is_empty() { - if let Some(ref expr) = block.expr { - return remove_blocks(expr); - } +pub fn remove_blocks<'tcx>(mut expr: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> { + while let ExprKind::Block(ref block, ..) = expr.kind { + match (block.stmts.is_empty(), block.expr.as_ref()) { + (true, Some(e)) => expr = e, + _ => break, } } expr