about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-07-25 23:49:40 -0700
committerbors <bors@rust-lang.org>2013-07-25 23:49:40 -0700
commit5109ce691c5b8cc6c4ef189bec33e9131e2899bf (patch)
tree45fa9ffad1f5f8d87718fecec6f63675dd194841
parent0012b5008b32543cf61a2beba36160c42f36d704 (diff)
parent09e49a8e6c11e57142a0f628745142d94fc87444 (diff)
downloadrust-5109ce691c5b8cc6c4ef189bec33e9131e2899bf.tar.gz
rust-5109ce691c5b8cc6c4ef189bec33e9131e2899bf.zip
auto merge of #7924 : alexcrichton/rust/opt-lang-xcrate2, r=thestinger
This is a reopening of #7874
-rw-r--r--src/librustc/metadata/encoder.rs3
-rw-r--r--src/librustc/middle/lang_items.rs4
-rw-r--r--src/test/auxiliary/no_std_crate.rs3
-rw-r--r--src/test/run-pass/no-std-xcrate.rs21
-rw-r--r--src/test/run-pass/no-std-xcrate2.rs35
5 files changed, 64 insertions, 2 deletions
diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs
index c216e8d2386..d6287d457c1 100644
--- a/src/librustc/metadata/encoder.rs
+++ b/src/librustc/metadata/encoder.rs
@@ -1455,6 +1455,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 6bc4564bb13..54e7a2fd7e7 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<def_id>, 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/test/auxiliary/no_std_crate.rs b/src/test/auxiliary/no_std_crate.rs
new file mode 100644
index 00000000000..70f1b76e246
--- /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 00000000000..104e33b7488
--- /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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 00000000000..e393eb3a5c9
--- /dev/null
+++ b/src/test/run-pass/no-std-xcrate2.rs
@@ -0,0 +1,35 @@
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// xfail-test: this has weird linking problems on linux, and it probably needs a
+//             solution along the lines of disabling segmented stacks and/or the
+//             stack checks.
+// 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
+}