Skip to content

Commit cdd1347

Browse files
committed
Auto merge of #5010 - lzutao:recurse-remove_blocks, r=phansch
Make utils::remove_blocks non-recursive changelog: none
2 parents 79509be + 3801d21 commit cdd1347

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

clippy_lints/src/utils/mod.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -873,12 +873,11 @@ pub fn is_automatically_derived(attrs: &[ast::Attribute]) -> bool {
873873
///
874874
/// Ie. `x`, `{ x }` and `{{{{ x }}}}` all give `x`. `{ x; y }` and `{}` return
875875
/// themselves.
876-
pub fn remove_blocks<'tcx>(expr: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> {
877-
if let ExprKind::Block(ref block, _) = expr.kind {
878-
if block.stmts.is_empty() {
879-
if let Some(ref expr) = block.expr {
880-
return remove_blocks(expr);
881-
}
876+
pub fn remove_blocks<'tcx>(mut expr: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> {
877+
while let ExprKind::Block(ref block, ..) = expr.kind {
878+
match (block.stmts.is_empty(), block.expr.as_ref()) {
879+
(true, Some(e)) => expr = e,
880+
_ => break,
882881
}
883882
}
884883
expr

0 commit comments

Comments
 (0)