Skip to content

Commit 5109ce6

Browse files
committed
auto merge of #7924 : alexcrichton/rust/opt-lang-xcrate2, r=thestinger
This is a reopening of #7874
2 parents 0012b50 + 09e49a8 commit 5109ce6

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

src/librustc/metadata/encoder.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,9 @@ fn encode_lang_items(ecx: &EncodeContext, ebml_w: &mut writer::Encoder) {
14551455
ebml_w.start_tag(tag_lang_items);
14561456

14571457
for ecx.tcx.lang_items.each_item |def_id, i| {
1458+
let def_id = match def_id {
1459+
Some(id) => id, None => { loop }
1460+
};
14581461
if def_id.crate != local_crate {
14591462
loop;
14601463
}

src/librustc/middle/lang_items.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ impl LanguageItems {
9292
}
9393
}
9494

95-
pub fn each_item(&self, f: &fn(def_id: def_id, i: uint) -> bool) -> bool {
96-
self.items.iter().enumerate().advance(|(i, &item)| f(item.get(), i))
95+
pub fn each_item(&self, f: &fn(Option<def_id>, uint) -> bool) -> bool {
96+
self.items.iter().enumerate().advance(|(i, &item)| f(item, i))
9797
}
9898

9999
pub fn item_name(index: uint) -> &'static str {

src/test/auxiliary/no_std_crate.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#[no_std];
2+
3+
pub fn foo() {}

src/test/run-pass/no-std-xcrate.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2013 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+
// xfail-fast
12+
// aux-build:no_std_crate.rs
13+
14+
// This tests that crates which link to std can also be linked to crates with
15+
// #[no_std] that have no lang items.
16+
17+
extern mod no_std_crate;
18+
19+
fn main() {
20+
no_std_crate::foo();
21+
}

src/test/run-pass/no-std-xcrate2.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2013 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+
// xfail-test: this has weird linking problems on linux, and it probably needs a
12+
// solution along the lines of disabling segmented stacks and/or the
13+
// stack checks.
14+
// aux-build:no_std_crate.rs
15+
16+
// This tests that libraries built with #[no_std] can be linked to crates with
17+
// #[no_std] and actually run.
18+
19+
#[no_std];
20+
21+
extern mod no_std_crate;
22+
23+
// This is an unfortunate thing to have to do on linux :(
24+
#[cfg(target_os = "linux")]
25+
#[doc(hidden)]
26+
pub mod linkhack {
27+
#[link_args="-lrustrt -lrt"]
28+
extern {}
29+
}
30+
31+
#[start]
32+
fn main(_: int, _: **u8, _: *u8) -> int {
33+
no_std_crate::foo();
34+
0
35+
}

0 commit comments

Comments
 (0)