@@ -56,7 +56,9 @@ pub struct LintStore {
56
56
lints : Vec < ( & ' static Lint , bool ) > ,
57
57
58
58
/// Trait objects for each lint pass.
59
- passes : Vec < RefCell < LintPassObject > > ,
59
+ /// This is only `None` while iterating over the objects. See the definition
60
+ /// of run_lints.
61
+ passes : Option < Vec < LintPassObject > > ,
60
62
61
63
/// Lints indexed by name.
62
64
by_name : HashMap < & ' static str , LintId > ,
@@ -84,7 +86,7 @@ impl LintStore {
84
86
pub fn new ( ) -> LintStore {
85
87
LintStore {
86
88
lints : vec ! ( ) ,
87
- passes : vec ! ( ) ,
89
+ passes : Some ( vec ! ( ) ) ,
88
90
by_name : HashMap :: new ( ) ,
89
91
levels : HashMap :: new ( ) ,
90
92
}
@@ -117,7 +119,7 @@ impl LintStore {
117
119
self . levels . insert ( id, ( lint. default_level , Default ) ) ;
118
120
}
119
121
}
120
- self . passes . push ( RefCell :: new ( pass) ) ;
122
+ self . passes . get_mut_ref ( ) . push ( pass) ;
121
123
}
122
124
123
125
pub fn register_builtin ( & mut self , sess : Option < & Session > ) {
@@ -181,11 +183,15 @@ pub struct Context<'a> {
181
183
}
182
184
183
185
/// Convenience macro for calling a `LintPass` method on every pass in the context.
184
- macro_rules! run_lints ( ( $cx: expr, $f: ident, $( $args: expr) ,* ) => (
185
- for obj in $cx. lints. passes. iter( ) {
186
- obj. borrow_mut( ) . $f( $cx, $( $args) ,* ) ;
187
- }
188
- ) )
186
+ macro_rules! run_lints ( ( $cx: expr, $f: ident, $( $args: expr) ,* ) => ( {
187
+ // Move the vector of passes out of `$cx` so that we can
188
+ // iterate over it mutably while passing `$cx` to the methods.
189
+ let mut passes = $cx. lints. passes. take_unwrap( ) ;
190
+ for obj in passes. mut_iter( ) {
191
+ obj. $f( $cx, $( $args) ,* ) ;
192
+ }
193
+ $cx. lints. passes = Some ( passes) ;
194
+ } ) )
189
195
190
196
/// Emit a lint as a warning or an error (or not at all)
191
197
/// according to `level`.
0 commit comments