Skip to content

Commit

Permalink
Small refactoring in liveness.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianWolff committed May 21, 2021
1 parent 2bcc759 commit 7a98fd4
Showing 1 changed file with 21 additions and 51 deletions.
72 changes: 21 additions & 51 deletions compiler/rustc_passes/src/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7a98fd4

Please sign in to comment.