From 5722410f72d0698f6ad9ba668e2282ff0bac5043 Mon Sep 17 00:00:00 2001 From: James Miller Date: Thu, 18 Dec 2014 17:43:50 +1300 Subject: [PATCH] Fix logic error and add unreachable after returns --- src/librustc/middle/graph.rs | 2 +- src/librustc_trans/trans/expr.rs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/librustc/middle/graph.rs b/src/librustc/middle/graph.rs index 3ba72801e2b..45bdf1c89cf 100644 --- a/src/librustc/middle/graph.rs +++ b/src/librustc/middle/graph.rs @@ -314,7 +314,7 @@ pub struct DepthFirstTraversal<'g, N:'g, E:'g> { impl<'g, N, E> Iterator<&'g N> for DepthFirstTraversal<'g, N, E> { fn next(&mut self) -> Option<&'g N> { while let Some(idx) = self.stack.pop() { - if self.visited.insert(idx.node_id()) { + if !self.visited.insert(idx.node_id()) { continue; } self.graph.each_outgoing_edge(idx, |_, e| -> bool { diff --git a/src/librustc_trans/trans/expr.rs b/src/librustc_trans/trans/expr.rs index 6cefda59737..b185e8098e4 100644 --- a/src/librustc_trans/trans/expr.rs +++ b/src/librustc_trans/trans/expr.rs @@ -945,6 +945,10 @@ fn trans_rvalue_stmt_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, if let &Some(ref x) = ex { bcx = trans_into(bcx, &**x, Ignore); } + // Mark the end of the block as unreachable. Once we get to + // a return expression, there's no more we should be doing + // after this. + Unreachable(bcx); bcx } }