File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
branches/incoming/src/libcore Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8
8
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9
- refs/heads/incoming: ec9c68c1df2ab657e630993d34c859d8bcb3f18e
9
+ refs/heads/incoming: 6e20ffeb8d6be059ee717993fc7ad2bcd86a0b13
10
10
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
11
11
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
12
12
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
Original file line number Diff line number Diff line change @@ -16,6 +16,12 @@ enum TypeDesc = {
16
16
// Remaining fields not listed
17
17
} ;
18
18
19
+ /// The representation of a Rust closure
20
+ struct Closure {
21
+ code : * ( ) ;
22
+ env : * ( ) ;
23
+ }
24
+
19
25
#[ abi = "cdecl" ]
20
26
extern mod rustrt {
21
27
pure fn shape_log_str ( t : * sys:: TypeDesc , data : * ( ) ) -> ~str ;
@@ -138,6 +144,27 @@ mod tests {
138
144
assert pref_align_of :: < uint > ( ) == 8 u;
139
145
assert pref_align_of :: < * uint > ( ) == 8 u;
140
146
}
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
+ }
141
168
}
142
169
143
170
// Local Variables:
You can’t perform that action at this time.
0 commit comments