14
14
use driver:: session;
15
15
use front:: config;
16
16
17
+ use std:: cell:: RefCell ;
17
18
use std:: vec;
18
19
use syntax:: ast_util:: * ;
19
20
use syntax:: attr:: AttrMetaMethods ;
@@ -38,7 +39,7 @@ struct Test {
38
39
39
40
struct TestCtxt {
40
41
sess : session:: Session ,
41
- path : ~[ ast:: Ident ] ,
42
+ path : RefCell < ~[ ast:: Ident ] > ,
42
43
ext_cx : @ExtCtxt ,
43
44
testfns : ~[ Test ] ,
44
45
is_extra : bool ,
@@ -78,9 +79,12 @@ impl fold::ast_fold for TestHarnessGenerator {
78
79
}
79
80
80
81
fn fold_item ( & self , i : @ast:: item ) -> SmallVector < @ast:: item > {
81
- self . cx . path . push ( i. ident ) ;
82
+ {
83
+ let mut path = self . cx . path . borrow_mut ( ) ;
84
+ path. get ( ) . push ( i. ident ) ;
85
+ }
82
86
debug ! ( "current path: {}" ,
83
- ast_util:: path_name_i( self . cx. path. clone ( ) ) ) ;
87
+ ast_util:: path_name_i( self . cx. path. get ( ) ) ) ;
84
88
85
89
if is_test_fn ( self . cx , i) || is_bench_fn ( i) {
86
90
match i. node {
@@ -95,7 +99,7 @@ impl fold::ast_fold for TestHarnessGenerator {
95
99
debug ! ( "this is a test function" ) ;
96
100
let test = Test {
97
101
span : i. span ,
98
- path : self . cx . path . clone ( ) ,
102
+ path : self . cx . path . get ( ) ,
99
103
bench : is_bench_fn ( i) ,
100
104
ignore : is_ignored ( self . cx , i) ,
101
105
should_fail : should_fail ( i)
@@ -108,7 +112,10 @@ impl fold::ast_fold for TestHarnessGenerator {
108
112
}
109
113
110
114
let res = fold:: noop_fold_item ( i, self ) ;
111
- self . cx . path . pop ( ) ;
115
+ {
116
+ let mut path = self . cx . path . borrow_mut ( ) ;
117
+ path. get ( ) . pop ( ) ;
118
+ }
112
119
res
113
120
}
114
121
@@ -147,7 +154,7 @@ fn generate_test_harness(sess: session::Session, crate: ast::Crate)
147
154
let cx: @mut TestCtxt = @mut TestCtxt {
148
155
sess : sess,
149
156
ext_cx : ExtCtxt :: new ( sess. parse_sess , sess. opts . cfg . clone ( ) ) ,
150
- path : ~[ ] ,
157
+ path : RefCell :: new ( ~[ ] ) ,
151
158
testfns : ~[ ] ,
152
159
is_extra : is_extra ( & crate ) ,
153
160
config : crate . config. clone ( ) ,
0 commit comments