Skip to content

Commit e891f29

Browse files
committed
Fix ICE when returning a variable whose declaration is unreachable
Fixes rust-lang#24353
1 parent 49798c5 commit e891f29

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/librustc_trans/trans/controlflow.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ pub fn trans_block<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
131131

132132
match b.expr {
133133
Some(ref e) => {
134-
bcx = expr::trans_into(bcx, &**e, dest);
134+
if !bcx.unreachable.get() {
135+
bcx = expr::trans_into(bcx, &**e, dest);
136+
}
135137
}
136138
None => {
137139
assert!(dest == expr::Ignore || bcx.unreachable.get());

src/test/run-pass/issue24353.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
return ();
13+
14+
let x = ();
15+
x
16+
}

0 commit comments

Comments
 (0)