Skip to content

Commit 3965ddd

Browse files
committed
Make ast_fold take &mut self
1 parent 933def4 commit 3965ddd

File tree

10 files changed

+131
-130
lines changed

10 files changed

+131
-130
lines changed

src/librustc/front/assign_node_ids.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ struct NodeIdAssigner {
1818
}
1919

2020
impl ast_fold for NodeIdAssigner {
21-
fn new_id(&self, old_id: ast::NodeId) -> ast::NodeId {
21+
fn new_id(&mut self, old_id: ast::NodeId) -> ast::NodeId {
2222
assert_eq!(old_id, ast::DUMMY_NODE_ID);
2323
self.sess.next_node_id()
2424
}
2525
}
2626

2727
pub fn assign_node_ids(sess: Session, crate: ast::Crate) -> ast::Crate {
28-
let fold = NodeIdAssigner {
28+
let mut fold = NodeIdAssigner {
2929
sess: sess,
3030
};
3131
fold.fold_crate(crate)

src/librustc/front/config.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ pub fn strip_unconfigured_items(crate: ast::Crate) -> ast::Crate {
2424
}
2525

2626
impl<'a> fold::ast_fold for Context<'a> {
27-
fn fold_mod(&self, module: &ast::_mod) -> ast::_mod {
27+
fn fold_mod(&mut self, module: &ast::_mod) -> ast::_mod {
2828
fold_mod(self, module)
2929
}
30-
fn fold_block(&self, block: ast::P<ast::Block>) -> ast::P<ast::Block> {
30+
fn fold_block(&mut self, block: ast::P<ast::Block>) -> ast::P<ast::Block> {
3131
fold_block(self, block)
3232
}
33-
fn fold_foreign_mod(&self, foreign_module: &ast::foreign_mod)
33+
fn fold_foreign_mod(&mut self, foreign_module: &ast::foreign_mod)
3434
-> ast::foreign_mod {
3535
fold_foreign_mod(self, foreign_module)
3636
}
37-
fn fold_item_underscore(&self, item: &ast::item_) -> ast::item_ {
37+
fn fold_item_underscore(&mut self, item: &ast::item_) -> ast::item_ {
3838
fold_item_underscore(self, item)
3939
}
4040
}
4141

4242
pub fn strip_items(crate: ast::Crate,
4343
in_cfg: |attrs: &[ast::Attribute]| -> bool)
4444
-> ast::Crate {
45-
let ctxt = Context {
45+
let mut ctxt = Context {
4646
in_cfg: in_cfg,
4747
};
4848
ctxt.fold_crate(crate)
@@ -57,7 +57,7 @@ fn filter_view_item<'r>(cx: &Context, view_item: &'r ast::view_item)
5757
}
5858
}
5959

60-
fn fold_mod(cx: &Context, m: &ast::_mod) -> ast::_mod {
60+
fn fold_mod(cx: &mut Context, m: &ast::_mod) -> ast::_mod {
6161
let filtered_items = m.items.iter()
6262
.filter(|&a| item_in_cfg(cx, *a))
6363
.flat_map(|&x| cx.fold_item(x).move_iter())
@@ -80,7 +80,7 @@ fn filter_foreign_item(cx: &Context, item: @ast::foreign_item)
8080
}
8181
}
8282

83-
fn fold_foreign_mod(cx: &Context, nm: &ast::foreign_mod) -> ast::foreign_mod {
83+
fn fold_foreign_mod(cx: &mut Context, nm: &ast::foreign_mod) -> ast::foreign_mod {
8484
let filtered_items = nm.items
8585
.iter()
8686
.filter_map(|a| filter_foreign_item(cx, *a))
@@ -95,7 +95,7 @@ fn fold_foreign_mod(cx: &Context, nm: &ast::foreign_mod) -> ast::foreign_mod {
9595
}
9696
}
9797

98-
fn fold_item_underscore(cx: &Context, item: &ast::item_) -> ast::item_ {
98+
fn fold_item_underscore(cx: &mut Context, item: &ast::item_) -> ast::item_ {
9999
let item = match *item {
100100
ast::item_impl(ref a, ref b, c, ref methods) => {
101101
let methods = methods.iter().filter(|m| method_in_cfg(cx, **m))
@@ -129,7 +129,7 @@ fn retain_stmt(cx: &Context, stmt: @ast::Stmt) -> bool {
129129
}
130130
}
131131

132-
fn fold_block(cx: &Context, b: ast::P<ast::Block>) -> ast::P<ast::Block> {
132+
fn fold_block(cx: &mut Context, b: ast::P<ast::Block>) -> ast::P<ast::Block> {
133133
let resulting_stmts = b.stmts.iter()
134134
.filter(|&a| retain_stmt(cx, *a))
135135
.flat_map(|&stmt| cx.fold_stmt(stmt).move_iter())

src/librustc/front/std_inject.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct StandardLibraryInjector {
5656
}
5757

5858
impl fold::ast_fold for StandardLibraryInjector {
59-
fn fold_crate(&self, crate: ast::Crate) -> ast::Crate {
59+
fn fold_crate(&mut self, crate: ast::Crate) -> ast::Crate {
6060
let version = STD_VERSION.to_managed();
6161
let vers_item = attr::mk_name_value_item_str(@"vers", version);
6262
let mut vis = ~[ast::view_item {
@@ -108,7 +108,7 @@ impl fold::ast_fold for StandardLibraryInjector {
108108
}
109109
}
110110

111-
fn fold_item(&self, item: @ast::item) -> SmallVector<@ast::item> {
111+
fn fold_item(&mut self, item: @ast::item) -> SmallVector<@ast::item> {
112112
if !no_prelude(item.attrs) {
113113
// only recur if there wasn't `#[no_implicit_prelude];`
114114
// on this item, i.e. this means that the prelude is not
@@ -119,7 +119,7 @@ impl fold::ast_fold for StandardLibraryInjector {
119119
}
120120
}
121121

122-
fn fold_mod(&self, module: &ast::_mod) -> ast::_mod {
122+
fn fold_mod(&mut self, module: &ast::_mod) -> ast::_mod {
123123
let prelude_path = ast::Path {
124124
span: dummy_sp(),
125125
global: false,
@@ -158,7 +158,7 @@ impl fold::ast_fold for StandardLibraryInjector {
158158
}
159159

160160
fn inject_libstd_ref(sess: Session, crate: ast::Crate) -> ast::Crate {
161-
let fold = StandardLibraryInjector {
161+
let mut fold = StandardLibraryInjector {
162162
sess: sess,
163163
};
164164
fold.fold_crate(crate)

src/librustc/front/test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct TestHarnessGenerator {
6767
}
6868

6969
impl fold::ast_fold for TestHarnessGenerator {
70-
fn fold_crate(&self, c: ast::Crate) -> ast::Crate {
70+
fn fold_crate(&mut self, c: ast::Crate) -> ast::Crate {
7171
let folded = fold::noop_fold_crate(c, self);
7272

7373
// Add a special __test module to the crate that will contain code
@@ -78,7 +78,7 @@ impl fold::ast_fold for TestHarnessGenerator {
7878
}
7979
}
8080

81-
fn fold_item(&self, i: @ast::item) -> SmallVector<@ast::item> {
81+
fn fold_item(&mut self, i: @ast::item) -> SmallVector<@ast::item> {
8282
{
8383
let mut path = self.cx.path.borrow_mut();
8484
path.get().push(i.ident);
@@ -122,7 +122,7 @@ impl fold::ast_fold for TestHarnessGenerator {
122122
res
123123
}
124124

125-
fn fold_mod(&self, m: &ast::_mod) -> ast::_mod {
125+
fn fold_mod(&mut self, m: &ast::_mod) -> ast::_mod {
126126
// Remove any #[main] from the AST so it doesn't clash with
127127
// the one we're going to add. Only if compiling an executable.
128128

@@ -172,7 +172,7 @@ fn generate_test_harness(sess: session::Session, crate: ast::Crate)
172172
}
173173
});
174174

175-
let fold = TestHarnessGenerator {
175+
let mut fold = TestHarnessGenerator {
176176
cx: cx
177177
};
178178
let res = fold.fold_crate(crate);

src/librustc/middle/astencode.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ struct NestedItemsDropper {
301301
}
302302

303303
impl fold::ast_fold for NestedItemsDropper {
304-
fn fold_block(&self, blk: ast::P<ast::Block>) -> ast::P<ast::Block> {
304+
fn fold_block(&mut self, blk: ast::P<ast::Block>) -> ast::P<ast::Block> {
305305
let stmts_sans_items = blk.stmts.iter().filter_map(|stmt| {
306306
match stmt.node {
307307
ast::StmtExpr(_, _) | ast::StmtSemi(_, _) |
@@ -340,7 +340,7 @@ impl fold::ast_fold for NestedItemsDropper {
340340
// nested items, as otherwise it would get confused when translating
341341
// inlined items.
342342
fn simplify_ast(ii: &ast::inlined_item) -> ast::inlined_item {
343-
let fld = NestedItemsDropper {
343+
let mut fld = NestedItemsDropper {
344344
contents: (),
345345
};
346346

@@ -365,17 +365,17 @@ struct AstRenumberer {
365365
}
366366

367367
impl fold::ast_fold for AstRenumberer {
368-
fn new_id(&self, id: ast::NodeId) -> ast::NodeId {
368+
fn new_id(&mut self, id: ast::NodeId) -> ast::NodeId {
369369
self.xcx.tr_id(id)
370370
}
371-
fn new_span(&self, span: Span) -> Span {
371+
fn new_span(&mut self, span: Span) -> Span {
372372
self.xcx.tr_span(span)
373373
}
374374
}
375375

376376
fn renumber_ast(xcx: @ExtendedDecodeContext, ii: ast::inlined_item)
377377
-> ast::inlined_item {
378-
let fld = AstRenumberer {
378+
let mut fld = AstRenumberer {
379379
xcx: xcx,
380380
};
381381
match ii {

src/librustpkg/util.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct ReadyCtx {
8080
fns: ~[ListenerFn]
8181
}
8282

83-
fn fold_mod(_ctx: @mut ReadyCtx, m: &ast::_mod, fold: &CrateSetup)
83+
fn fold_mod(_ctx: @mut ReadyCtx, m: &ast::_mod, fold: &mut CrateSetup)
8484
-> ast::_mod {
8585
fn strip_main(item: @ast::item) -> @ast::item {
8686
@ast::item {
@@ -101,7 +101,7 @@ fn fold_mod(_ctx: @mut ReadyCtx, m: &ast::_mod, fold: &CrateSetup)
101101
}, fold)
102102
}
103103

104-
fn fold_item(ctx: @mut ReadyCtx, item: @ast::item, fold: &CrateSetup)
104+
fn fold_item(ctx: @mut ReadyCtx, item: @ast::item, fold: &mut CrateSetup)
105105
-> SmallVector<@ast::item> {
106106
ctx.path.push(item.ident);
107107

@@ -145,10 +145,10 @@ struct CrateSetup {
145145
}
146146

147147
impl fold::ast_fold for CrateSetup {
148-
fn fold_item(&self, item: @ast::item) -> SmallVector<@ast::item> {
148+
fn fold_item(&mut self, item: @ast::item) -> SmallVector<@ast::item> {
149149
fold_item(self.ctx, item, self)
150150
}
151-
fn fold_mod(&self, module: &ast::_mod) -> ast::_mod {
151+
fn fold_mod(&mut self, module: &ast::_mod) -> ast::_mod {
152152
fold_mod(self.ctx, module, self)
153153
}
154154
}
@@ -162,7 +162,7 @@ pub fn ready_crate(sess: session::Session,
162162
path: ~[],
163163
fns: ~[]
164164
};
165-
let fold = CrateSetup {
165+
let mut fold = CrateSetup {
166166
ctx: ctx,
167167
};
168168
fold.fold_crate(crate)

src/libsyntax/ext/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,11 @@ impl ExtCtxt {
324324
loop {
325325
match e.node {
326326
ast::ExprMac(..) => {
327-
let expander = expand::MacroExpander {
327+
let mut expander = expand::MacroExpander {
328328
extsbox: @mut syntax_expander_table(),
329329
cx: self,
330330
};
331-
e = expand::expand_expr(e, &expander);
331+
e = expand::expand_expr(e, &mut expander);
332332
}
333333
_ => return e
334334
}

src/libsyntax/ext/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ struct Duplicator<'a> {
908908
}
909909

910910
impl<'a> ast_fold for Duplicator<'a> {
911-
fn new_id(&self, _: NodeId) -> NodeId {
911+
fn new_id(&mut self, _: NodeId) -> NodeId {
912912
ast::DUMMY_NODE_ID
913913
}
914914
}
@@ -925,7 +925,7 @@ pub trait Duplicate {
925925

926926
impl Duplicate for @ast::Expr {
927927
fn duplicate(&self, cx: &ExtCtxt) -> @ast::Expr {
928-
let folder = Duplicator {
928+
let mut folder = Duplicator {
929929
cx: cx,
930930
};
931931
folder.fold_expr(*self)

0 commit comments

Comments
 (0)