1
1
// helper for transmutation, shown below.
2
2
type RustClosure = ( int , int ) ;
3
3
4
- struct Condition {
5
- key : task:: local_data:: LocalDataKey < Handler >
4
+ struct Condition < T , U : Copy > {
5
+ key : task:: local_data:: LocalDataKey < Handler < T , U > >
6
6
}
7
7
8
- struct Handler {
8
+ struct Handler < T , U : Copy > {
9
9
handle : RustClosure ,
10
- prev : Option < @Handler >
10
+ prev : Option < @Handler < T , U > >
11
11
}
12
12
13
13
14
- struct ProtectBlock {
15
- cond : & Condition ,
14
+ struct ProtectBlock < T , U : Copy > {
15
+ cond : & Condition < T , U > ,
16
16
inner : RustClosure
17
17
}
18
18
19
- struct PopHandler {
20
- cond : & Condition ,
19
+ struct PopHandler < T , U : Copy > {
20
+ cond : & Condition < T , U > ,
21
21
drop {
22
22
unsafe {
23
23
debug!( "PopHandler : popping handler from TLS ") ;
@@ -35,9 +35,9 @@ struct PopHandler {
35
35
}
36
36
}
37
37
38
- struct HandleBlock {
39
- pb : & ProtectBlock ,
40
- handler : @Handler ,
38
+ struct HandleBlock < T , U : Copy > {
39
+ pb : & ProtectBlock < T , U > ,
40
+ handler : @Handler < T , U > ,
41
41
drop {
42
42
unsafe {
43
43
debug!( "HandleBlock : pushing handler to TLS ") ;
@@ -54,8 +54,8 @@ struct HandleBlock {
54
54
}
55
55
}
56
56
57
- impl ProtectBlock {
58
- fn handle < T , U : Copy > ( & self , h : & self /fn ( & T ) ->U ) -> HandleBlock /& self {
57
+ impl < T , U : Copy > ProtectBlock < T , U > {
58
+ fn handle ( & self , h : & self /fn ( & T ) ->U ) -> HandleBlock /& self < T , U > {
59
59
unsafe {
60
60
debug ! ( "ProtectBlock.handle: setting up handler block" ) ;
61
61
let p : * RustClosure = :: cast:: transmute ( & h) ;
@@ -67,9 +67,9 @@ impl ProtectBlock {
67
67
}
68
68
69
69
70
- impl Condition {
70
+ impl < T , U : Copy > Condition < T , U > {
71
71
72
- fn protect ( & self , inner : & self /fn ( ) ) -> ProtectBlock /& self {
72
+ fn protect ( & self , inner : & self /fn ( ) ) -> ProtectBlock /& self < T , U > {
73
73
unsafe {
74
74
// transmutation to avoid copying non-copyable, should
75
75
// be fixable by tracking closure pointees in regionck.
@@ -80,7 +80,7 @@ impl Condition {
80
80
}
81
81
}
82
82
83
- fn raise < T , U : Copy > ( t : & T ) -> U {
83
+ fn raise ( t : & T ) -> U {
84
84
unsafe {
85
85
match task:: local_data:: local_data_get ( self . key ) {
86
86
None => {
@@ -100,15 +100,13 @@ impl Condition {
100
100
101
101
102
102
#[ cfg( test) ]
103
- fn happiness_key ( _x : @Handler ) { }
104
-
105
- #[ cfg( test) ]
106
- fn sadness_key ( _x : @Handler ) { }
103
+ fn sadness_key ( _x : @Handler < int , int > ) { }
107
104
108
105
#[ cfg( test) ]
109
106
fn trouble ( i : int ) {
110
107
// Condition should work as a const, just limitations in consts.
111
- let sadness_condition : Condition = Condition { key : sadness_key } ;
108
+ let sadness_condition : Condition < int , int > =
109
+ Condition { key : sadness_key } ;
112
110
debug ! ( "trouble: raising conition" ) ;
113
111
let j = sadness_condition. raise ( & i) ;
114
112
debug ! ( "trouble: handler recovered with %d" , j) ;
@@ -117,7 +115,8 @@ fn trouble(i: int) {
117
115
#[ test]
118
116
fn test1 ( ) {
119
117
120
- let sadness_condition : Condition = Condition { key : sadness_key } ;
118
+ let sadness_condition : Condition < int , int > =
119
+ Condition { key : sadness_key } ;
121
120
122
121
let mut i = 10 ;
123
122
@@ -138,7 +137,8 @@ fn test1() {
138
137
}
139
138
#[ cfg( test) ]
140
139
fn nested_test_inner ( ) {
141
- let sadness_condition : Condition = Condition { key : sadness_key } ;
140
+ let sadness_condition : Condition < int , int > =
141
+ Condition { key : sadness_key } ;
142
142
143
143
let mut inner_trapped = false ;
144
144
@@ -159,7 +159,8 @@ fn nested_test_inner() {
159
159
#[ test]
160
160
fn nested_test_outer ( ) {
161
161
162
- let sadness_condition : Condition = Condition { key : sadness_key } ;
162
+ let sadness_condition : Condition < int , int > =
163
+ Condition { key : sadness_key } ;
163
164
164
165
let mut outer_trapped = false ;
165
166
0 commit comments