Make utils::remove_blocks non-recursive

This commit is contained in:
Lzu Tao
2020-01-07 10:50:35 +07:00
parent 62ff63917c
commit 3801d216e2

View File

@@ -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 /// Ie. `x`, `{ x }` and `{{{{ x }}}}` all give `x`. `{ x; y }` and `{}` return
/// themselves. /// themselves.
pub fn remove_blocks<'tcx>(expr: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> { pub fn remove_blocks<'tcx>(mut expr: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> {
if let ExprKind::Block(ref block, _) = expr.kind { while let ExprKind::Block(ref block, ..) = expr.kind {
if block.stmts.is_empty() { match (block.stmts.is_empty(), block.expr.as_ref()) {
if let Some(ref expr) = block.expr { (true, Some(e)) => expr = e,
return remove_blocks(expr); _ => break,
}
} }
} }
expr expr