Skip to content

Commit 2af8f1b

Browse files
committed
---
yaml --- r: 23574 b: refs/heads/master c: 6e20ffe h: refs/heads/master v: v3
1 parent 672a51e commit 2af8f1b

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: ec9c68c1df2ab657e630993d34c859d8bcb3f18e
2+
refs/heads/master: 6e20ffeb8d6be059ee717993fc7ad2bcd86a0b13
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/libcore/sys.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ enum TypeDesc = {
1616
// Remaining fields not listed
1717
};
1818

19+
/// The representation of a Rust closure
20+
struct Closure {
21+
code: *();
22+
env: *();
23+
}
24+
1925
#[abi = "cdecl"]
2026
extern mod rustrt {
2127
pure fn shape_log_str(t: *sys::TypeDesc, data: *()) -> ~str;
@@ -138,6 +144,27 @@ mod tests {
138144
assert pref_align_of::<uint>() == 8u;
139145
assert pref_align_of::<*uint>() == 8u;
140146
}
147+
148+
#[test]
149+
fn synthesize_closure() unsafe {
150+
let x = 10;
151+
let f: fn(int) -> int = |y| x + y;
152+
153+
assert f(20) == 30;
154+
155+
let original_closure: Closure = unsafe::transmute(f);
156+
157+
let actual_function_pointer = original_closure.code;
158+
let environment = original_closure.env;
159+
160+
let new_closure = Closure {
161+
code: actual_function_pointer,
162+
env: environment
163+
};
164+
165+
let new_f: fn(int) -> int = unsafe::transmute(new_closure);
166+
assert new_f(20) == 30;
167+
}
141168
}
142169

143170
// Local Variables:

0 commit comments

Comments
 (0)