Skip to content

Commit

Permalink
Auto merge of rust-lang#5010 - lzutao:recurse-remove_blocks, r=phansch
Browse files Browse the repository at this point in the history
Make utils::remove_blocks non-recursive

changelog: none
  • Loading branch information
bors committed Jan 7, 2020
2 parents 79509be + 3801d21 commit cdd1347
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cdd1347

Please sign in to comment.