Skip to content

Commit c4c89dd

Browse files
committed
rustc: Translate the value of crust functions
1 parent 0a50322 commit c4c89dd

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/comp/middle/trans/base.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,6 +2338,19 @@ fn lval_static_fn(bcx: @block_ctxt, fn_id: ast::def_id, id: ast::node_id,
23382338
// External reference.
23392339
trans_external_path(bcx, fn_id, tpt)
23402340
};
2341+
2342+
// FIXME: Need to support external crust functions
2343+
if fn_id.crate == ast::local_crate {
2344+
alt bcx_tcx(bcx).def_map.find(id) {
2345+
some(ast::def_fn(_, ast::crust_fn)) {
2346+
// Crust functions are just opaque pointers
2347+
let val = PointerCast(bcx, val, T_ptr(T_i8()));
2348+
ret lval_no_env(bcx, val, owned_imm);
2349+
}
2350+
_ { }
2351+
}
2352+
}
2353+
23412354
let gen = generic_none, bcx = bcx;
23422355
if tys.len() > 0u {
23432356
let tydescs = [], tis = [];

src/test/run-pass/crust-take-value.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
crust fn f() {
22
}
33

4+
crust fn g() {
5+
}
6+
47
fn main() {
58
// Crust functions are *u8 types
6-
let _x: *u8 = f;
7-
}
9+
let a: *u8 = f;
10+
let b: *u8 = f;
11+
let c: *u8 = g;
12+
13+
assert a == b;
14+
assert a != c;
15+
}

0 commit comments

Comments
 (0)