From 7a98fd412425ed39e8737e63a35da96202e43e56 Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Sat, 22 May 2021 01:25:16 +0200 Subject: [PATCH] Small refactoring in `liveness.rs` --- compiler/rustc_passes/src/liveness.rs | 72 ++++++++------------------- 1 file changed, 21 insertions(+), 51 deletions(-) diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs index 80c1bd7a5f5..413fb32b70d 100644 --- a/compiler/rustc_passes/src/liveness.rs +++ b/compiler/rustc_passes/src/liveness.rs @@ -977,62 +977,13 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } hir::ExprKind::Call(ref f, ref args) => { - let m = self.ir.tcx.parent_module(expr.hir_id).to_def_id(); - let ty = self.typeck_results.expr_ty(expr); - let succ = if self.ir.tcx.is_ty_uninhabited_from(m, ty, self.param_env) { - if let LiveNodeKind::ExprNode(succ_span, succ_id) = self.ir.lnks[succ] { - self.warn_about_unreachable( - expr.span, - ty, - succ_span, - succ_id, - "expression", - ); - } else if let LiveNodeKind::VarDefNode(succ_span, succ_id) = self.ir.lnks[succ] - { - self.warn_about_unreachable( - expr.span, - ty, - succ_span, - succ_id, - "definition", - ); - } - self.exit_ln - } else { - succ - }; + let succ = self.check_is_ty_uninhabited(expr, succ); let succ = self.propagate_through_exprs(args, succ); self.propagate_through_expr(&f, succ) } hir::ExprKind::MethodCall(.., ref args, _) => { - let m = self.ir.tcx.parent_module(expr.hir_id).to_def_id(); - let ty = self.typeck_results.expr_ty(expr); - let succ = if self.ir.tcx.is_ty_uninhabited_from(m, ty, self.param_env) { - if let LiveNodeKind::ExprNode(succ_span, succ_id) = self.ir.lnks[succ] { - self.warn_about_unreachable( - expr.span, - ty, - succ_span, - succ_id, - "expression", - ); - } else if let LiveNodeKind::VarDefNode(succ_span, succ_id) = self.ir.lnks[succ] - { - self.warn_about_unreachable( - expr.span, - ty, - succ_span, - succ_id, - "definition", - ); - } - self.exit_ln - } else { - succ - }; - + let succ = self.check_is_ty_uninhabited(expr, succ); self.propagate_through_exprs(args, succ) } @@ -1305,6 +1256,25 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { ln } + fn check_is_ty_uninhabited(&mut self, expr: &Expr<'_>, succ: LiveNode) -> LiveNode { + let ty = self.typeck_results.expr_ty(expr); + let m = self.ir.tcx.parent_module(expr.hir_id).to_def_id(); + if self.ir.tcx.is_ty_uninhabited_from(m, ty, self.param_env) { + match self.ir.lnks[succ] { + LiveNodeKind::ExprNode(succ_span, succ_id) => { + self.warn_about_unreachable(expr.span, ty, succ_span, succ_id, "expression"); + } + LiveNodeKind::VarDefNode(succ_span, succ_id) => { + self.warn_about_unreachable(expr.span, ty, succ_span, succ_id, "definition"); + } + _ => {} + }; + self.exit_ln + } else { + succ + } + } + fn warn_about_unreachable( &mut self, orig_span: Span,