diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 0c224a440ff6f..35d32d9952506 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -2070,12 +2070,12 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) { item.id, item.attrs.as_slice()); } - } else { - // Be sure to travel more than just one layer deep to catch nested - // items in blocks and such. - let mut v = TransItemVisitor{ ccx: ccx }; - v.visit_block(&**body, ()); } + + // Be sure to travel more than just one layer deep to catch nested + // items in blocks and such. + let mut v = TransItemVisitor{ ccx: ccx }; + v.visit_block(&**body, ()); } ast::ItemImpl(ref generics, _, _, ref ms) => { meth::trans_impl(ccx, item.ident, ms.as_slice(), generics, item.id); diff --git a/src/librustc/middle/trans/controlflow.rs b/src/librustc/middle/trans/controlflow.rs index 6ea85f83d25ac..a481f92db3391 100644 --- a/src/librustc/middle/trans/controlflow.rs +++ b/src/librustc/middle/trans/controlflow.rs @@ -69,7 +69,8 @@ pub fn trans_stmt<'a>(cx: &'a Block<'a>, debuginfo::create_local_var_metadata(bcx, &**local); } } - ast::DeclItem(ref i) => trans_item(cx.fcx.ccx, &**i) + // Inner items are visited by `trans_item`/`trans_meth`. + ast::DeclItem(_) => {}, } } ast::StmtMac(..) => cx.tcx().sess.bug("unexpanded macro") diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index 9e45b294a37b3..3578b25c83957 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -76,10 +76,9 @@ pub fn trans_impl(ccx: &CrateContext, ¶m_substs::empty(), method.id, []); - } else { - let mut v = TransItemVisitor{ ccx: ccx }; - visit::walk_method_helper(&mut v, &**method, ()); } + let mut v = TransItemVisitor{ ccx: ccx }; + visit::walk_method_helper(&mut v, &**method, ()); } } diff --git a/src/test/run-make/issue-7349/Makefile b/src/test/run-make/issue-7349/Makefile new file mode 100644 index 0000000000000..7f715a475bead --- /dev/null +++ b/src/test/run-make/issue-7349/Makefile @@ -0,0 +1,11 @@ +-include ../tools.mk + +# Test to make sure that inner functions within a polymorphic outer function +# don't get re-translated when the outer function is monomorphized. The test +# code monomorphizes the outer functions several times, but the magic constants +# used in the inner functions should each appear only once in the generated IR. + +all: + $(RUSTC) foo.rs --emit=ir + [ "$$(grep -c 8675309 "$(TMPDIR)/foo.ll")" -eq "1" ] + [ "$$(grep -c 11235813 "$(TMPDIR)/foo.ll")" -eq "1" ] diff --git a/src/test/run-make/issue-7349/foo.rs b/src/test/run-make/issue-7349/foo.rs new file mode 100644 index 0000000000000..870d1749278d7 --- /dev/null +++ b/src/test/run-make/issue-7349/foo.rs @@ -0,0 +1,30 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn outer() { + #[allow(dead_code)] + fn inner() -> uint { + 8675309 + } +} + +extern "C" fn outer_foreign() { + #[allow(dead_code)] + fn inner() -> uint { + 11235813 + } +} + +fn main() { + outer::(); + outer::(); + outer_foreign::(); + outer_foreign::(); +}