diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index ab42e84e2acfe..3c25cd7bfcf3f 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -1460,6 +1460,9 @@ fn encode_lang_items(ecx: &EncodeContext, ebml_w: &mut writer::Encoder) { ebml_w.start_tag(tag_lang_items); for ecx.tcx.lang_items.each_item |def_id, i| { + let def_id = match def_id { + Some(id) => id, None => { loop } + }; if def_id.crate != local_crate { loop; } diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index a49e50d5c38d7..93d375ef6ebf4 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -92,8 +92,8 @@ impl LanguageItems { } } - pub fn each_item(&self, f: &fn(def_id: def_id, i: uint) -> bool) -> bool { - self.items.iter().enumerate().advance(|(i, &item)| f(item.get(), i)) + pub fn each_item(&self, f: &fn(Option, uint) -> bool) -> bool { + self.items.iter().enumerate().advance(|(i, &item)| f(item, i)) } pub fn item_name(index: uint) -> &'static str { diff --git a/src/rt/rust_crate_map.h b/src/rt/rust_crate_map.h index a57840ffe0955..64d17ebc3ad26 100644 --- a/src/rt/rust_crate_map.h +++ b/src/rt/rust_crate_map.h @@ -68,7 +68,7 @@ class cratemap { return &reinterpret_cast(this)-> m_children[0]; case 1: - return &m_children[1]; + return &m_children[0]; default: assert(false && "Unknown crate map version!"); return NULL; // Appease -Werror=return-type } diff --git a/src/test/auxiliary/no_std_crate.rs b/src/test/auxiliary/no_std_crate.rs new file mode 100644 index 0000000000000..70f1b76e246ce --- /dev/null +++ b/src/test/auxiliary/no_std_crate.rs @@ -0,0 +1,3 @@ +#[no_std]; + +pub fn foo() {} diff --git a/src/test/run-pass/no-std-xcrate.rs b/src/test/run-pass/no-std-xcrate.rs new file mode 100644 index 0000000000000..104e33b7488e0 --- /dev/null +++ b/src/test/run-pass/no-std-xcrate.rs @@ -0,0 +1,21 @@ +// 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 +// aux-build:no_std_crate.rs + +// This tests that crates which link to std can also be linked to crates with +// #[no_std] that have no lang items. + +extern mod no_std_crate; + +fn main() { + no_std_crate::foo(); +} diff --git a/src/test/run-pass/no-std-xcrate2.rs b/src/test/run-pass/no-std-xcrate2.rs new file mode 100644 index 0000000000000..843184ac4fbd7 --- /dev/null +++ b/src/test/run-pass/no-std-xcrate2.rs @@ -0,0 +1,33 @@ +// 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 +// aux-build:no_std_crate.rs + +// This tests that libraries built with #[no_std] can be linked to crates with +// #[no_std] and actually run. + +#[no_std]; + +extern mod no_std_crate; + +// This is an unfortunate thing to have to do on linux :( +#[cfg(target_os = "linux")] +#[doc(hidden)] +pub mod linkhack { + #[link_args="-lrustrt -lrt"] + extern {} +} + +#[start] +fn main(_: int, _: **u8, _: *u8) -> int { + no_std_crate::foo(); + 0 +}