Skip to content

Commit 0f847ba

Browse files
committed
more consistent handling of inner items
1 parent 428d5ac commit 0f847ba

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed

src/librustc/middle/trans/base.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2070,12 +2070,12 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
20702070
item.id,
20712071
item.attrs.as_slice());
20722072
}
2073-
} else {
2074-
// Be sure to travel more than just one layer deep to catch nested
2075-
// items in blocks and such.
2076-
let mut v = TransItemVisitor{ ccx: ccx };
2077-
v.visit_block(&**body, ());
20782073
}
2074+
2075+
// Be sure to travel more than just one layer deep to catch nested
2076+
// items in blocks and such.
2077+
let mut v = TransItemVisitor{ ccx: ccx };
2078+
v.visit_block(&**body, ());
20792079
}
20802080
ast::ItemImpl(ref generics, _, _, ref ms) => {
20812081
meth::trans_impl(ccx, item.ident, ms.as_slice(), generics, item.id);

src/librustc/middle/trans/controlflow.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ pub fn trans_stmt<'a>(cx: &'a Block<'a>,
6969
debuginfo::create_local_var_metadata(bcx, &**local);
7070
}
7171
}
72-
ast::DeclItem(ref i) => trans_item(cx.fcx.ccx, &**i)
72+
// Inner items are visited by `trans_item`/`trans_meth`.
73+
ast::DeclItem(_) => {},
7374
}
7475
}
7576
ast::StmtMac(..) => cx.tcx().sess.bug("unexpanded macro")

src/librustc/middle/trans/meth.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,9 @@ pub fn trans_impl(ccx: &CrateContext,
7676
&param_substs::empty(),
7777
method.id,
7878
[]);
79-
} else {
80-
let mut v = TransItemVisitor{ ccx: ccx };
81-
visit::walk_method_helper(&mut v, &**method, ());
8279
}
80+
let mut v = TransItemVisitor{ ccx: ccx };
81+
visit::walk_method_helper(&mut v, &**method, ());
8382
}
8483
}
8584

src/test/run-make/issue-7349/Makefile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-include ../tools.mk
2+
3+
# Test to make sure that inner functions within a polymorphic outer function
4+
# don't get re-translated when the outer function is monomorphized. The test
5+
# code monomorphizes the outer functions several times, but the magic constants
6+
# used in the inner functions should each appear only once in the generated IR.
7+
8+
all:
9+
$(RUSTC) foo.rs --emit=ir
10+
[ "$$(grep -c 8675309 "$(TMPDIR)/foo.ll")" -eq "1" ]
11+
[ "$$(grep -c 11235813 "$(TMPDIR)/foo.ll")" -eq "1" ]

src/test/run-make/issue-7349/foo.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2014 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 outer<T>() {
12+
#[allow(dead_code)]
13+
fn inner() -> uint {
14+
8675309
15+
}
16+
}
17+
18+
extern "C" fn outer_foreign<T>() {
19+
#[allow(dead_code)]
20+
fn inner() -> uint {
21+
11235813
22+
}
23+
}
24+
25+
fn main() {
26+
outer::<int>();
27+
outer::<uint>();
28+
outer_foreign::<int>();
29+
outer_foreign::<uint>();
30+
}

0 commit comments

Comments
 (0)