From 899aae465eb4ef295dc1eeb2603f744568e0768c Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Fri, 29 Jan 2021 01:44:15 +0900 Subject: [PATCH] Simplify base_expr Co-authored-by: Oli Scherer --- compiler/rustc_passes/src/dead.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index a4798b9ae1f..3902557e9b5 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -37,17 +37,13 @@ fn should_explore(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool { ) } -fn base_expr<'a>(expr: &'a hir::Expr<'a>) -> &'a hir::Expr<'a> { - let mut current = expr; +fn base_expr<'a>(mut expr: &'a hir::Expr<'a>) -> &'a hir::Expr<'a> loop { - match current.kind { - hir::ExprKind::Field(base, ..) => { - current = base; - } - _ => break, + match expr.kind { + hir::ExprKind::Field(base, ..) => expr = base, + _ => return expr, } } - current } struct MarkSymbolVisitor<'tcx> {