Skip to content

Commit

Permalink
Make liveness analysis respect privacy
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Dec 11, 2018
1 parent 20415af commit 210e234
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/librustc/middle/liveness.rs
Expand Up @@ -1197,7 +1197,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}

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
Expand All @@ -1207,7 +1208,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}

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
Expand Down
5 changes: 3 additions & 2 deletions src/test/ui/uninhabited/privately-uninhabited-dead-code.rs
@@ -1,6 +1,6 @@
// compile-pass

#![deny(unreachable_code)]
#![deny(unused_variables)]

mod foo {
enum Bar {}
Expand All @@ -14,6 +14,7 @@ mod foo {
}

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
}

0 comments on commit 210e234

Please sign in to comment.