From 62ba8355736a9e20f5850be2a940a02bfa4c2cbd Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 13 Sep 2013 01:42:44 -0700 Subject: [PATCH] Translate nested items in default methods Closes #9123 --- src/librustc/middle/trans/base.rs | 9 +++++++++ src/test/auxiliary/issue_9123.rs | 19 +++++++++++++++++++ src/test/run-pass/issue-9123.rs | 16 ++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 src/test/auxiliary/issue_9123.rs create mode 100644 src/test/run-pass/issue-9123.rs diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 94771d6f519..a79063c9c9a 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -87,6 +87,7 @@ use syntax::parse::token::{special_idents}; use syntax::print::pprust::stmt_to_str; use syntax::{ast, ast_util, codemap, ast_map}; use syntax::abi::{X86, X86_64, Arm, Mips}; +use syntax::visit; use syntax::visit::Visitor; pub use middle::trans::context::task_llcx; @@ -2239,6 +2240,14 @@ pub fn trans_item(ccx: @mut CrateContext, item: &ast::item) { trans_struct_def(ccx, struct_def); } } + ast::item_trait(*) => { + // Inside of this trait definition, we won't be actually translating any + // functions, but the trait still needs to be walked. Otherwise default + // methods with items will not get translated and will cause ICE's when + // metadata time comes around. + let mut v = TransItemVisitor; + visit::walk_item(&mut v, item, ccx); + } _ => {/* fall through */ } } } diff --git a/src/test/auxiliary/issue_9123.rs b/src/test/auxiliary/issue_9123.rs new file mode 100644 index 00000000000..066909d42b8 --- /dev/null +++ b/src/test/auxiliary/issue_9123.rs @@ -0,0 +1,19 @@ +// Copyright 2013 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. + +#[crate_type = "lib"]; + +pub trait X { + fn x() { + fn f() { } + f(); + } +} + diff --git a/src/test/run-pass/issue-9123.rs b/src/test/run-pass/issue-9123.rs new file mode 100644 index 00000000000..73a14de10bf --- /dev/null +++ b/src/test/run-pass/issue-9123.rs @@ -0,0 +1,16 @@ +// Copyright 2013 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. + +// xfail-fast windows doesn't like aux-build +// aux-build:issue_9123.rs + +extern mod issue_9123; + +pub fn main() {}