Skip to content

Commit 609552e

Browse files
author
Keegan McAllister
committed
Run lint passes using the Option dance instead of RefCells
1 parent c1898b9 commit 609552e

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/librustc/lint/context.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ pub struct LintStore {
5656
lints: Vec<(&'static Lint, bool)>,
5757

5858
/// 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>>,
6062

6163
/// Lints indexed by name.
6264
by_name: HashMap<&'static str, LintId>,
@@ -84,7 +86,7 @@ impl LintStore {
8486
pub fn new() -> LintStore {
8587
LintStore {
8688
lints: vec!(),
87-
passes: vec!(),
89+
passes: Some(vec!()),
8890
by_name: HashMap::new(),
8991
levels: HashMap::new(),
9092
}
@@ -117,7 +119,7 @@ impl LintStore {
117119
self.levels.insert(id, (lint.default_level, Default));
118120
}
119121
}
120-
self.passes.push(RefCell::new(pass));
122+
self.passes.get_mut_ref().push(pass);
121123
}
122124

123125
pub fn register_builtin(&mut self, sess: Option<&Session>) {
@@ -181,11 +183,15 @@ pub struct Context<'a> {
181183
}
182184

183185
/// 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+
}))
189195

190196
/// Emit a lint as a warning or an error (or not at all)
191197
/// according to `level`.

0 commit comments

Comments
 (0)