Make liveness analysis respect privacy

This commit is contained in:
varkor
2018-11-06 19:38:01 +00:00
parent 20415af142
commit 210e234733
2 changed files with 7 additions and 4 deletions
+4 -2
View File
@@ -1197,7 +1197,8 @@ fn propagate_through_expr(&mut self, expr: &Expr, succ: LiveNode)
}
hir::ExprKind::Call(ref f, ref args) => {
let succ = if self.tables.expr_ty(expr).conservative_is_uninhabited(self.ir.tcx) {
let m = self.ir.tcx.hir.get_module_parent(expr.id);
let succ = if self.ir.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(expr)) {
self.s.exit_ln
} else {
succ
@@ -1207,7 +1208,8 @@ fn propagate_through_expr(&mut self, expr: &Expr, succ: LiveNode)
}
hir::ExprKind::MethodCall(.., ref args) => {
let succ = if self.tables.expr_ty(expr).conservative_is_uninhabited(self.ir.tcx) {
let m = self.ir.tcx.hir.get_module_parent(expr.id);
let succ = if self.ir.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(expr)) {
self.s.exit_ln
} else {
succ
@@ -1,6 +1,6 @@
// compile-pass
#![deny(unreachable_code)]
#![deny(unused_variables)]
mod foo {
enum Bar {}
@@ -14,6 +14,7 @@ pub fn give_foo() -> Foo { panic!() }
}
fn main() {
let a = 42;
foo::give_foo();
println!("Hello, world!"); // ok: we can't tell that this code is dead
println!("Hello, {}", a); // ok: we can't tell that this code is dead
}