Skip to content

Commit 0a50322

Browse files
committed
rustc: Typecheck crust functions as *u8
1 parent 305cbf9 commit 0a50322

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

src/comp/middle/typeck.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
107107
}
108108
}
109109
}
110+
ast::def_fn(id, ast::crust_fn) {
111+
// Crust functions are just u8 pointers
112+
ret {
113+
bounds: @[],
114+
ty: ty::mk_ptr(
115+
fcx.ccx.tcx,
116+
{
117+
ty: ty::mk_mach_uint(fcx.ccx.tcx, ast::ty_u8),
118+
mut: ast::imm
119+
})
120+
};
121+
}
110122
ast::def_fn(id, _) | ast::def_const(id) |
111123
ast::def_variant(_, id) | ast::def_class(id)
112124
| ast::def_class_method(_, id) | ast::def_class_field(_, id)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// error-pattern:expected function or native function but found *u8
2+
crust fn f() {
3+
}
4+
5+
fn main() {
6+
let x = bind f();
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// error-pattern:expected function or native function but found *u8
2+
crust fn f() {
3+
}
4+
5+
fn main() {
6+
f();
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// error-pattern:expected `fn()` but found `*u8`
2+
crust fn f() {
3+
}
4+
5+
fn main() {
6+
// Crust functions are *u8 types
7+
let _x: fn() = f;
8+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
crust fn f() {
2+
}
3+
4+
fn main() {
5+
// Crust functions are *u8 types
6+
let _x: *u8 = f;
7+
}

0 commit comments

Comments
 (0)