Skip to content

Commit 48499c7

Browse files
committed
auto merge of #9484 : alexcrichton/rust/fix-cfg-inner-item, r=pcwalton
If an item is skipped due to it being unreachable or for some optimization, then it shouldn't be encoded into the metadata (because it wasn't present in the first place).
2 parents f210a16 + daee1b4 commit 48499c7

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

src/librustc/middle/trans/controlflow.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use syntax::ast;
2525
use syntax::ast::Name;
2626
use syntax::ast_util;
2727
use syntax::codemap::Span;
28+
use syntax::visit::Visitor;
2829

2930
pub fn trans_block(bcx: @mut Block, b: &ast::Block, dest: expr::Dest) -> @mut Block {
3031
let _icx = push_ctxt("trans_block");
@@ -64,12 +65,22 @@ pub fn trans_if(bcx: @mut Block,
6465
// Drop branches that are known to be impossible
6566
if is_const(cond_val) && !is_undef(cond_val) {
6667
if const_to_uint(cond_val) == 1 {
68+
match els {
69+
Some(elexpr) => {
70+
let mut trans = TransItemVisitor { ccx: bcx.fcx.ccx };
71+
trans.visit_expr(elexpr, ());
72+
}
73+
None => {}
74+
}
6775
// if true { .. } [else { .. }]
6876
return do with_scope(bcx, thn.info(), "if_true_then") |bcx| {
6977
let bcx_out = trans_block(bcx, thn, dest);
7078
trans_block_cleanups(bcx_out, block_cleanups(bcx))
7179
}
7280
} else {
81+
let mut trans = TransItemVisitor { ccx: bcx.fcx.ccx } ;
82+
trans.visit_block(thn, ());
83+
7384
match els {
7485
// if false { .. } else { .. }
7586
Some(elexpr) => {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2013 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+
// this used to just ICE on compiling
12+
pub fn foo() {
13+
if cfg!(foo) {
14+
static a: int = 3;
15+
a
16+
} else { 3 };
17+
}

src/test/run-pass/cfg_inner_static.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2013 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+
// aux-build:cfg_inner_static.rs
12+
// xfail-fast
13+
14+
extern mod cfg_inner_static;
15+
16+
fn main() {
17+
cfg_inner_static::foo();
18+
}

0 commit comments

Comments
 (0)