Skip to content

Commit 9c1e530

Browse files
committed
auto merge of #7826 : michaelwoerister/rust/end_of_spanned, r=cmr
This is the first of a series of refactorings to get rid of the `codemap::spanned<T>` struct (see this thread for more information: https://mail.mozilla.org/pipermail/rust-dev/2013-July/004798.html). The changes in this PR should not change any semantics, just rename `ast::blk_` to `ast::blk` and add a span field to it. 95% of the changes were of the form `block.node.id` -> `block.id`. Only some transformations in `libsyntax::fold` where not entirely trivial.
2 parents 93c270c + 0cc7074 commit 9c1e530

37 files changed

+190
-191
lines changed

src/librustc/driver/driver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ pub fn pretty_print_input(sess: Session, cfg: ast::crate_cfg, input: &input,
422422
pprust::node_block(s, ref blk) => {
423423
pp::space(s.s);
424424
pprust::synth_comment(
425-
s, ~"block " + int::to_str(blk.node.id));
425+
s, ~"block " + int::to_str(blk.id));
426426
}
427427
pprust::node_expr(s, expr) => {
428428
pp::space(s.s);

src/librustc/front/config.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn strip_items(crate: &ast::crate, in_cfg: in_cfg_pred)
3333

3434
let precursor = @fold::AstFoldFns {
3535
fold_mod: |a,b| fold_mod(ctxt, a, b),
36-
fold_block: fold::wrap(|a,b| fold_block(ctxt, a, b) ),
36+
fold_block: |a,b| fold_block(ctxt, a, b),
3737
fold_foreign_mod: |a,b| fold_foreign_mod(ctxt, a, b),
3838
fold_item_underscore: |a,b| {
3939
// Bad copy.
@@ -133,21 +133,22 @@ fn filter_stmt(cx: @Context, stmt: @ast::stmt) ->
133133

134134
fn fold_block(
135135
cx: @Context,
136-
b: &ast::blk_,
136+
b: &ast::blk,
137137
fld: @fold::ast_fold
138-
) -> ast::blk_ {
138+
) -> ast::blk {
139139
let resulting_stmts = do b.stmts.iter().filter_map |a| {
140140
filter_stmt(cx, *a).chain(|stmt| fld.fold_stmt(stmt))
141141
}.collect();
142142
let filtered_view_items = do b.view_items.iter().filter_map |a| {
143143
filter_view_item(cx, a).map(|&x| fld.fold_view_item(x))
144144
}.collect();
145-
ast::blk_ {
145+
ast::blk {
146146
view_items: filtered_view_items,
147147
stmts: resulting_stmts,
148148
expr: b.expr.map(|x| fld.fold_expr(*x)),
149149
id: b.id,
150150
rules: b.rules,
151+
span: b.span,
151152
}
152153
}
153154

src/librustc/middle/astencode.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ fn encode_ast(ebml_w: &mut writer::Encoder, item: ast::inlined_item) {
289289
// nested items, as otherwise it would get confused when translating
290290
// inlined items.
291291
fn simplify_ast(ii: &ast::inlined_item) -> ast::inlined_item {
292-
fn drop_nested_items(blk: &ast::blk_, fld: @fold::ast_fold) -> ast::blk_ {
292+
fn drop_nested_items(blk: &ast::blk, fld: @fold::ast_fold) -> ast::blk {
293293
let stmts_sans_items = do blk.stmts.iter().filter_map |stmt| {
294294
match stmt.node {
295295
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) |
@@ -300,19 +300,20 @@ fn simplify_ast(ii: &ast::inlined_item) -> ast::inlined_item {
300300
ast::stmt_mac(*) => fail!("unexpanded macro in astencode")
301301
}
302302
}.collect();
303-
let blk_sans_items = ast::blk_ {
303+
let blk_sans_items = ast::blk {
304304
view_items: ~[], // I don't know if we need the view_items here,
305305
// but it doesn't break tests!
306306
stmts: stmts_sans_items,
307307
expr: blk.expr,
308308
id: blk.id,
309-
rules: blk.rules
309+
rules: blk.rules,
310+
span: blk.span,
310311
};
311312
fold::noop_fold_block(&blk_sans_items, fld)
312313
}
313314

314315
let fld = fold::make_fold(@fold::AstFoldFns {
315-
fold_block: fold::wrap(drop_nested_items),
316+
fold_block: drop_nested_items,
316317
.. *fold::default_ast_fold()
317318
});
318319

src/librustc/middle/borrowck/check_loans.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn check_loans(bccx: @BorrowckCtxt,
4444
move_data: move_data::FlowedMoveData,
4545
all_loans: &[Loan],
4646
body: &ast::blk) {
47-
debug!("check_loans(body id=%?)", body.node.id);
47+
debug!("check_loans(body id=%?)", body.id);
4848

4949
let clcx = @mut CheckLoanCtxt {
5050
bccx: bccx,
@@ -751,5 +751,5 @@ fn check_loans_in_block<'a>(blk: &ast::blk,
751751
visit::vt<@mut CheckLoanCtxt<'a>>))
752752
{
753753
visit::visit_block(blk, (this, vt));
754-
this.check_for_conflicting_loans(blk.node.id);
754+
this.check_for_conflicting_loans(blk.id);
755755
}

src/librustc/middle/borrowck/gather_loans/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ pub fn gather_loans(bccx: @BorrowckCtxt,
8080
bccx: bccx,
8181
id_range: id_range::max(),
8282
all_loans: @mut ~[],
83-
item_ub: body.node.id,
84-
repeating_ids: ~[body.node.id],
83+
item_ub: body.id,
84+
repeating_ids: ~[body.id],
8585
move_data: @mut MoveData::new()
8686
};
8787
glcx.gather_fn_arg_patterns(decl, body);
@@ -123,9 +123,9 @@ fn gather_loans_in_fn(fk: &visit::fn_kind,
123123

124124
// Visit closures as part of the containing item.
125125
&visit::fk_anon(*) | &visit::fk_fn_block(*) => {
126-
this.push_repeating_id(body.node.id);
126+
this.push_repeating_id(body.id);
127127
visit::visit_fn(fk, decl, body, sp, id, (this, v));
128-
this.pop_repeating_id(body.node.id);
128+
this.pop_repeating_id(body.id);
129129
this.gather_fn_arg_patterns(decl, body);
130130
}
131131
}
@@ -134,7 +134,7 @@ fn gather_loans_in_fn(fk: &visit::fn_kind,
134134
fn gather_loans_in_block(blk: &ast::blk,
135135
(this, vt): (@mut GatherLoanCtxt,
136136
visit::vt<@mut GatherLoanCtxt>)) {
137-
this.id_range.add(blk.node.id);
137+
this.id_range.add(blk.id);
138138
visit::visit_block(blk, (this, vt));
139139
}
140140

@@ -240,7 +240,7 @@ fn gather_loans_in_expr(ex: @ast::expr,
240240
let cmt = this.bccx.cat_expr(ex_v);
241241
for arms.iter().advance |arm| {
242242
for arm.pats.iter().advance |pat| {
243-
this.gather_pat(cmt, *pat, Some((arm.body.node.id, ex.id)));
243+
this.gather_pat(cmt, *pat, Some((arm.body.id, ex.id)));
244244
}
245245
}
246246
visit::visit_expr(ex, (this, vt));
@@ -268,16 +268,16 @@ fn gather_loans_in_expr(ex: @ast::expr,
268268
this.pop_repeating_id(cond.id);
269269

270270
// during body, can only root for the body
271-
this.push_repeating_id(body.node.id);
271+
this.push_repeating_id(body.id);
272272
(vt.visit_block)(body, (this, vt));
273-
this.pop_repeating_id(body.node.id);
273+
this.pop_repeating_id(body.id);
274274
}
275275

276276
// see explanation attached to the `root_ub` field:
277277
ast::expr_loop(ref body, _) => {
278-
this.push_repeating_id(body.node.id);
278+
this.push_repeating_id(body.id);
279279
visit::visit_expr(ex, (this, vt));
280-
this.pop_repeating_id(body.node.id);
280+
this.pop_repeating_id(body.id);
281281
}
282282

283283
ast::expr_fn_block(*) => {
@@ -623,7 +623,7 @@ impl GatherLoanCtxt {
623623
let arg_cmt = mc_ctxt.cat_rvalue(
624624
arg.id,
625625
arg.pat.span,
626-
body.node.id, // Arguments live only as long as the fn body.
626+
body.id, // Arguments live only as long as the fn body.
627627
arg_ty);
628628

629629
self.gather_pat(arg_cmt, arg.pat, None);

src/librustc/middle/cfg/construct.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ pub fn construct(tcx: ty::ctxt,
5353
impl CFGBuilder {
5454
fn block(&mut self, blk: &ast::blk, pred: CFGIndex) -> CFGIndex {
5555
let mut stmts_exit = pred;
56-
for blk.node.stmts.iter().advance |&stmt| {
56+
for blk.stmts.iter().advance |&stmt| {
5757
stmts_exit = self.stmt(stmt, stmts_exit);
5858
}
5959

60-
let expr_exit = self.opt_expr(blk.node.expr, stmts_exit);
60+
let expr_exit = self.opt_expr(blk.expr, stmts_exit);
6161

62-
self.add_node(blk.node.id, [expr_exit])
62+
self.add_node(blk.id, [expr_exit])
6363
}
6464

6565
fn stmt(&mut self, stmt: @ast::stmt, pred: CFGIndex) -> CFGIndex {

src/librustc/middle/dataflow.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ impl<O:DataFlowOperator+Copy+'static> DataFlowContext<O> {
330330
let pre: @fn(pprust::ann_node) = |node| {
331331
let (ps, id) = match node {
332332
pprust::node_expr(ps, expr) => (ps, expr.id),
333-
pprust::node_block(ps, blk) => (ps, blk.node.id),
333+
pprust::node_block(ps, blk) => (ps, blk.id),
334334
pprust::node_item(ps, _) => (ps, 0),
335335
pprust::node_pat(ps, pat) => (ps, pat.id)
336336
};
@@ -383,18 +383,18 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> {
383383
blk: &ast::blk,
384384
in_out: &mut [uint],
385385
loop_scopes: &mut ~[LoopScope]) {
386-
debug!("DataFlowContext::walk_block(blk.node.id=%?, in_out=%s)",
387-
blk.node.id, bits_to_str(reslice(in_out)));
386+
debug!("DataFlowContext::walk_block(blk.id=%?, in_out=%s)",
387+
blk.id, bits_to_str(reslice(in_out)));
388388

389-
self.merge_with_entry_set(blk.node.id, in_out);
389+
self.merge_with_entry_set(blk.id, in_out);
390390

391-
for blk.node.stmts.iter().advance |&stmt| {
391+
for blk.stmts.iter().advance |&stmt| {
392392
self.walk_stmt(stmt, in_out, loop_scopes);
393393
}
394394

395-
self.walk_opt_expr(blk.node.expr, in_out, loop_scopes);
395+
self.walk_opt_expr(blk.expr, in_out, loop_scopes);
396396

397-
self.dfcx.apply_gen_kill(blk.node.id, in_out);
397+
self.dfcx.apply_gen_kill(blk.id, in_out);
398398
}
399399

400400
fn walk_stmt(&mut self,

src/librustc/middle/effect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ pub fn check_crate(tcx: ty::ctxt,
9999

100100
visit_block: |block, (_, visitor)| {
101101
let old_unsafe_context = context.unsafe_context;
102-
if block.node.rules == unsafe_blk &&
102+
if block.rules == unsafe_blk &&
103103
context.unsafe_context == SafeContext {
104-
context.unsafe_context = UnsafeBlock(block.node.id)
104+
context.unsafe_context = UnsafeBlock(block.id)
105105
}
106106

107107
visit::visit_block(block, ((), visitor));

src/librustc/middle/lint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -921,8 +921,8 @@ fn lint_unused_unsafe() -> visit::vt<@mut Context> {
921921
visit::mk_vt(@visit::Visitor {
922922
visit_expr: |e, (cx, vt): (@mut Context, visit::vt<@mut Context>)| {
923923
match e.node {
924-
ast::expr_block(ref blk) if blk.node.rules == ast::unsafe_blk => {
925-
if !cx.tcx.used_unsafe.contains(&blk.node.id) {
924+
ast::expr_block(ref blk) if blk.rules == ast::unsafe_blk => {
925+
if !cx.tcx.used_unsafe.contains(&blk.id) {
926926
cx.span_lint(unused_unsafe, blk.span,
927927
"unnecessary `unsafe` block");
928928
}

src/librustc/middle/liveness.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ impl Liveness {
886886
self.tcx.sess.intr()));
887887

888888
let entry_ln: LiveNode =
889-
self.with_loop_nodes(body.node.id, self.s.exit_ln, self.s.exit_ln,
889+
self.with_loop_nodes(body.id, self.s.exit_ln, self.s.exit_ln,
890890
|| { self.propagate_through_fn_block(decl, body) });
891891

892892
// hack to skip the loop unless debug! is enabled:
@@ -895,7 +895,7 @@ impl Liveness {
895895
for uint::range(0u, self.ir.num_live_nodes) |ln_idx| {
896896
debug!("%s", self.ln_str(LiveNode(ln_idx)));
897897
}
898-
body.node.id
898+
body.id
899899
},
900900
entry_ln.to_str());
901901

@@ -907,7 +907,7 @@ impl Liveness {
907907
// the fallthrough exit is only for those cases where we do not
908908
// explicitly return:
909909
self.init_from_succ(self.s.fallthrough_ln, self.s.exit_ln);
910-
if blk.node.expr.is_none() {
910+
if blk.expr.is_none() {
911911
self.acc(self.s.fallthrough_ln, self.s.no_ret_var, ACC_READ)
912912
}
913913

@@ -916,8 +916,8 @@ impl Liveness {
916916

917917
pub fn propagate_through_block(&self, blk: &blk, succ: LiveNode)
918918
-> LiveNode {
919-
let succ = self.propagate_through_opt_expr(blk.node.expr, succ);
920-
do blk.node.stmts.rev_iter().fold(succ) |succ, stmt| {
919+
let succ = self.propagate_through_opt_expr(blk.expr, succ);
920+
do blk.stmts.rev_iter().fold(succ) |succ, stmt| {
921921
self.propagate_through_stmt(*stmt, succ)
922922
}
923923
}
@@ -1009,7 +1009,7 @@ impl Liveness {
10091009
The next-node for a break is the successor of the entire
10101010
loop. The next-node for a continue is the top of this loop.
10111011
*/
1012-
self.with_loop_nodes(blk.node.id, succ,
1012+
self.with_loop_nodes(blk.id, succ,
10131013
self.live_node(expr.id, expr.span), || {
10141014

10151015
// the construction of a closure itself is not important,

src/librustc/middle/moves.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,13 @@ impl VisitContext {
285285
* meaning either copied or moved depending on its type.
286286
*/
287287

288-
debug!("consume_block(blk.id=%?)", blk.node.id);
288+
debug!("consume_block(blk.id=%?)", blk.id);
289289

290-
for blk.node.stmts.iter().advance |stmt| {
290+
for blk.stmts.iter().advance |stmt| {
291291
(visitor.visit_stmt)(*stmt, (*self, visitor));
292292
}
293293

294-
for blk.node.expr.iter().advance |tail_expr| {
294+
for blk.expr.iter().advance |tail_expr| {
295295
self.consume_expr(*tail_expr, visitor);
296296
}
297297
}

src/librustc/middle/privacy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt,
384384
visit_block: |block, (method_map, visitor)| {
385385
// Gather up all the privileged items.
386386
let mut n_added = 0;
387-
for block.node.stmts.iter().advance |stmt| {
387+
for block.stmts.iter().advance |stmt| {
388388
match stmt.node {
389389
stmt_decl(decl, _) => {
390390
match decl.node {

src/librustc/middle/region.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,11 @@ fn parent_to_expr(cx: Context, child_id: ast::node_id, sp: span) {
324324

325325
fn resolve_block(blk: &ast::blk, (cx, visitor): (Context, visit::vt<Context>)) {
326326
// Record the parent of this block.
327-
parent_to_expr(cx, blk.node.id, blk.span);
327+
parent_to_expr(cx, blk.id, blk.span);
328328

329329
// Descend.
330-
let new_cx = Context {var_parent: Some(blk.node.id),
331-
parent: Some(blk.node.id),
330+
let new_cx = Context {var_parent: Some(blk.id),
331+
parent: Some(blk.id),
332332
..cx};
333333
visit::visit_block(blk, (new_cx, visitor));
334334
}
@@ -420,20 +420,20 @@ fn resolve_fn(fk: &visit::fn_kind,
420420
visit::vt<Context>)) {
421421
debug!("region::resolve_fn(id=%?, \
422422
span=%?, \
423-
body.node.id=%?, \
423+
body.id=%?, \
424424
cx.parent=%?)",
425425
id,
426426
cx.sess.codemap.span_to_str(sp),
427-
body.node.id,
427+
body.id,
428428
cx.parent);
429429

430430
// The arguments and `self` are parented to the body of the fn.
431-
let decl_cx = Context {parent: Some(body.node.id),
432-
var_parent: Some(body.node.id),
431+
let decl_cx = Context {parent: Some(body.id),
432+
var_parent: Some(body.id),
433433
..cx};
434434
match *fk {
435435
visit::fk_method(_, _, method) => {
436-
cx.region_maps.record_parent(method.self_id, body.node.id);
436+
cx.region_maps.record_parent(method.self_id, body.id);
437437
}
438438
_ => {}
439439
}

src/librustc/middle/resolve.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,12 +1069,12 @@ impl Resolver {
10691069

10701070
pub fn block_needs_anonymous_module(@mut self, block: &blk) -> bool {
10711071
// If the block has view items, we need an anonymous module.
1072-
if block.node.view_items.len() > 0 {
1072+
if block.view_items.len() > 0 {
10731073
return true;
10741074
}
10751075

10761076
// Check each statement.
1077-
for block.node.stmts.iter().advance |statement| {
1077+
for block.stmts.iter().advance |statement| {
10781078
match statement.node {
10791079
stmt_decl(declaration, _) => {
10801080
match declaration.node {
@@ -1566,7 +1566,7 @@ impl Resolver {
15661566
vt<ReducedGraphParent>)) {
15671567
let new_parent;
15681568
if self.block_needs_anonymous_module(block) {
1569-
let block_id = block.node.id;
1569+
let block_id = block.id;
15701570

15711571
debug!("(building reduced graph for block) creating a new \
15721572
anonymous module for block %d",
@@ -4096,7 +4096,7 @@ impl Resolver {
40964096

40974097
// Move down in the graph, if there's an anonymous module rooted here.
40984098
let orig_module = self.current_module;
4099-
match self.current_module.anonymous_children.find(&block.node.id) {
4099+
match self.current_module.anonymous_children.find(&block.id) {
41004100
None => { /* Nothing to do. */ }
41014101
Some(&anonymous_module) => {
41024102
debug!("(resolving block) found anonymous module, moving \
@@ -4989,7 +4989,7 @@ impl Resolver {
49894989
}
49904990

49914991
expr_fn_block(ref fn_decl, ref block) => {
4992-
self.resolve_function(FunctionRibKind(expr.id, block.node.id),
4992+
self.resolve_function(FunctionRibKind(expr.id, block.id),
49934993
Some(fn_decl),
49944994
NoTypeParameters,
49954995
block,

0 commit comments

Comments
 (0)