Skip to content

Commit 93c2ebf

Browse files
committed
syntax: convert ast::spanned into a struct
1 parent b75550a commit 93c2ebf

31 files changed

+245
-210
lines changed

src/libcargo/cargo.rc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ fn load_link(mis: ~[@ast::meta_item]) -> (Option<~str>,
294294
let mut uuid = None;
295295
for mis.each |a| {
296296
match a.node {
297-
ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) => {
297+
ast::meta_name_value(v, ast::spanned { node: ast::lit_str(s),
298+
_ }) => {
298299
match v {
299300
~"name" => name = Some(*s),
300301
~"vers" => vers = Some(*s),
@@ -321,7 +322,8 @@ fn load_crate(filename: &Path) -> Option<Crate> {
321322

322323
for c.node.attrs.each |a| {
323324
match a.node.value.node {
324-
ast::meta_name_value(v, {node: ast::lit_str(_), span: _}) => {
325+
ast::meta_name_value(v, ast::spanned { node: ast::lit_str(_),
326+
_ }) => {
325327
match v {
326328
~"desc" => desc = Some(v),
327329
~"sigs" => sigs = Some(v),

src/libfuzzer/fuzzer.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fn common_exprs() -> ~[ast::expr] {
8181
}
8282

8383
fn dsl(l: ast::lit_) -> ast::lit {
84-
{ node: l, span: ast_util::dummy_sp() }
84+
ast::spanned { node: l, span: ast_util::dummy_sp() }
8585
}
8686

8787
~[dse(ast::expr_break(option::None)),

src/librustc/front/core_inject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn use_core(crate: @ast::crate) -> bool {
3939
fn inject_libcore_ref(sess: Session,
4040
crate: @ast::crate) -> @ast::crate {
4141
fn spanned<T: Copy>(x: T) -> ast::spanned<T> {
42-
return {node: x, span: dummy_sp()};
42+
ast::spanned { node: x, span: dummy_sp() }
4343
}
4444

4545
let precursor = @{

src/librustc/front/intrinsic_inject.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ fn inject_intrinsic(sess: Session, crate: @ast::crate) -> @ast::crate {
3636

3737
let items = vec::append(~[item], crate.node.module.items);
3838

39-
return @{node: {module: { items: items ,.. /*bad*/copy crate.node.module }
40-
,.. /*bad*/copy crate.node} ,.. /*bad*/copy *crate }
39+
@ast::spanned {
40+
node: { module: { items: items ,.. /*bad*/copy crate.node.module },
41+
.. /*bad*/copy crate.node},
42+
.. /*bad*/copy *crate
43+
}
4144
}

src/librustc/front/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ fn mk_test_module(cx: test_ctxt) -> @ast::item {
242242
}
243243

244244
fn nospan<T: Copy>(t: T) -> ast::spanned<T> {
245-
return {node: t, span: dummy_sp()};
245+
ast::spanned { node: t, span: dummy_sp() }
246246
}
247247

248248
fn path_node(+ids: ~[ast::ident]) -> @ast::path {
@@ -489,7 +489,7 @@ fn mk_main(cx: test_ctxt) -> @ast::item {
489489
let body_: ast::blk_ =
490490
default_block(~[], option::Some(test_main_call_expr),
491491
cx.sess.next_node_id());
492-
let body = {node: body_, span: dummy_sp()};
492+
let body = ast::spanned { node: body_, span: dummy_sp() };
493493

494494
let item_ = ast::item_fn(decl, ast::impure_fn, ~[], body);
495495
let item: ast::item =

src/librustc/metadata/decoder.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,9 +1031,10 @@ fn get_attributes(md: ebml::Doc) -> ~[ast::attribute] {
10311031
assert (vec::len(meta_items) == 1u);
10321032
let meta_item = meta_items[0];
10331033
attrs.push(
1034-
{node: {style: ast::attr_outer, value: /*bad*/copy *meta_item,
1035-
is_sugared_doc: false},
1036-
span: ast_util::dummy_sp()});
1034+
ast::spanned { node: { style: ast::attr_outer,
1035+
value: /*bad*/copy *meta_item,
1036+
is_sugared_doc: false },
1037+
span: ast_util::dummy_sp()});
10371038
};
10381039
}
10391040
option::None => ()

src/librustc/middle/astencode.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,10 @@ fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item {
259259
let stmts_sans_items = do vec::filter(blk.stmts) |stmt| {
260260
match stmt.node {
261261
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) |
262-
ast::stmt_decl(@{node: ast::decl_local(_), span: _}, _) => true,
263-
ast::stmt_decl(@{node: ast::decl_item(_), span: _}, _) => false,
262+
ast::stmt_decl(@ast::spanned { node: ast::decl_local(_),
263+
span: _}, _) => true,
264+
ast::stmt_decl(@ast::spanned { node: ast::decl_item(_),
265+
span: _}, _) => false,
264266
ast::stmt_mac(*) => fail ~"unexpanded macro in astencode"
265267
}
266268
};
@@ -286,9 +288,10 @@ fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item {
286288
}
287289
ast::ii_dtor(ref dtor, nm, ref tps, parent_id) => {
288290
let dtor_body = fld.fold_block((*dtor).node.body);
289-
ast::ii_dtor({node: {body: dtor_body,
290-
.. /*bad*/copy (*dtor).node},
291-
.. (/*bad*/copy *dtor)}, nm, /*bad*/copy *tps, parent_id)
291+
ast::ii_dtor(ast::spanned { node: { body: dtor_body,
292+
.. /*bad*/copy (*dtor).node },
293+
.. (/*bad*/copy *dtor) },
294+
nm, /*bad*/copy *tps, parent_id)
292295
}
293296
}
294297
}
@@ -324,9 +327,11 @@ fn renumber_ast(xcx: extended_decode_ctxt, ii: ast::inlined_item)
324327
let dtor_id = fld.new_id((*dtor).node.id);
325328
let new_parent = xcx.tr_def_id(parent_id);
326329
let new_self = fld.new_id((*dtor).node.self_id);
327-
ast::ii_dtor({node: {id: dtor_id, attrs: dtor_attrs,
328-
self_id: new_self, body: dtor_body},
329-
.. (/*bad*/copy *dtor)},
330+
ast::ii_dtor(ast::spanned { node: { id: dtor_id,
331+
attrs: dtor_attrs,
332+
self_id: new_self,
333+
body: dtor_body },
334+
.. (/*bad*/copy *dtor)},
330335
nm, new_params, new_parent)
331336
}
332337
}

src/librustc/middle/check_const.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ fn check_item(sess: Session, ast_map: ast_map::map,
5757
fn check_pat(p: @pat, &&_is_const: bool, v: visit::vt<bool>) {
5858
fn is_str(e: @expr) -> bool {
5959
match e.node {
60-
expr_vstore(@{node: expr_lit(@{node: lit_str(_), _}), _},
60+
expr_vstore(@{node: expr_lit(@spanned { node: lit_str(_),
61+
_}), _},
6162
expr_vstore_uniq) => true,
6263
_ => false
6364
}
@@ -84,7 +85,7 @@ fn check_expr(sess: Session, def_map: resolve::DefMap,
8485
~"disallowed operator in constant expression");
8586
return;
8687
}
87-
expr_lit(@{node: lit_str(_), _}) => { }
88+
expr_lit(@spanned {node: lit_str(_), _}) => { }
8889
expr_binary(_, _, _) | expr_unary(_, _) => {
8990
if method_map.contains_key(e.id) {
9091
sess.span_err(e.span, ~"user-defined operators are not \
@@ -170,15 +171,15 @@ fn check_expr(sess: Session, def_map: resolve::DefMap,
170171
}
171172
}
172173
match e.node {
173-
expr_lit(@{node: lit_int(v, t), _}) => {
174+
expr_lit(@spanned {node: lit_int(v, t), _}) => {
174175
if t != ty_char {
175176
if (v as u64) > ast_util::int_ty_max(
176177
if t == ty_i { sess.targ_cfg.int_type } else { t }) {
177178
sess.span_err(e.span, ~"literal out of range for its type");
178179
}
179180
}
180181
}
181-
expr_lit(@{node: lit_uint(v, t), _}) => {
182+
expr_lit(@spanned {node: lit_uint(v, t), _}) => {
182183
if v > ast_util::uint_ty_max(
183184
if t == ty_u { sess.targ_cfg.uint_type } else { t }) {
184185
sess.span_err(e.span, ~"literal out of range for its type");

src/librustc/middle/check_match.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,10 @@ fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool {
692692
is_refutable(cx, sub)
693693
}
694694
pat_wild | pat_ident(_, _, None) => { false }
695-
pat_lit(@{node: expr_lit(@{node: lit_nil, _}), _}) => { false } // "()"
695+
pat_lit(@{node: expr_lit(@spanned { node: lit_nil, _}), _}) => {
696+
// "()"
697+
false
698+
}
696699
pat_lit(_) | pat_range(_, _) => { true }
697700
pat_rec(fields, _) => {
698701
fields.any(|f| is_refutable(cx, f.pat))

src/librustc/middle/kind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
409409

410410
fn check_stmt(stmt: @stmt, cx: ctx, v: visit::vt<ctx>) {
411411
match stmt.node {
412-
stmt_decl(@{node: decl_local(ref locals), _}, _) => {
412+
stmt_decl(@spanned {node: decl_local(ref locals), _}, _) => {
413413
for locals.each |local| {
414414
match local.node.init {
415415
Some(expr) =>

src/librustc/middle/lint.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,8 @@ fn check_item_while_true(cx: ty::ctxt, it: @ast::item) {
467467
match e.node {
468468
ast::expr_while(cond, _) => {
469469
match cond.node {
470-
ast::expr_lit(@{node: ast::lit_bool(true),_}) => {
470+
ast::expr_lit(@ast::spanned { node: ast::lit_bool(true),
471+
_}) => {
471472
cx.sess.span_lint(
472473
while_true, e.id, it.id,
473474
e.span,

src/librustc/middle/trans/base.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,8 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
19381938
} else {
19391939
for vec::each((*body).node.stmts) |stmt| {
19401940
match stmt.node {
1941-
ast::stmt_decl(@{node: ast::decl_item(i), _}, _) => {
1941+
ast::stmt_decl(@ast::spanned { node: ast::decl_item(i),
1942+
_ }, _) => {
19421943
trans_item(ccx, *i);
19431944
}
19441945
_ => ()

src/librustc/middle/trans/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr,
545545
ast::expr_tup(args) => {
546546
return trans_tup(bcx, args, dest);
547547
}
548-
ast::expr_lit(@{node: ast::lit_str(s), _}) => {
548+
ast::expr_lit(@ast::spanned {node: ast::lit_str(s), _}) => {
549549
return tvec::trans_lit_str(bcx, expr, s, dest);
550550
}
551551
ast::expr_vstore(contents, ast::expr_vstore_slice) |

src/librustc/middle/trans/tvec.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ fn trans_slice_vstore(bcx: block,
197197

198198
// Handle the &"..." case:
199199
match content_expr.node {
200-
ast::expr_lit(@{node: ast::lit_str(s), span: _}) => {
200+
ast::expr_lit(@ast::spanned {node: ast::lit_str(s), span: _}) => {
201201
return trans_lit_str(bcx, content_expr, s, dest);
202202
}
203203
_ => {}
@@ -316,7 +316,7 @@ fn write_content(bcx: block,
316316
let _indenter = indenter();
317317

318318
match /*bad*/copy content_expr.node {
319-
ast::expr_lit(@{node: ast::lit_str(s), span: _}) => {
319+
ast::expr_lit(@ast::spanned { node: ast::lit_str(s), _ }) => {
320320
match dest {
321321
Ignore => {
322322
return bcx;
@@ -422,7 +422,9 @@ fn elements_required(bcx: block, content_expr: @ast::expr) -> uint {
422422
//! Figure out the number of elements we need to store this content
423423
424424
match /*bad*/copy content_expr.node {
425-
ast::expr_lit(@{node: ast::lit_str(s), span: _}) => s.len() + 1,
425+
ast::expr_lit(@ast::spanned { node: ast::lit_str(s), _ }) => {
426+
s.len() + 1
427+
},
426428
ast::expr_vec(es, _) => es.len(),
427429
ast::expr_repeat(_, count_expr, _) => {
428430
ty::eval_repeat_count(bcx.tcx(), count_expr, content_expr.span)

src/librustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3157,7 +3157,7 @@ fn expr_kind(tcx: ctxt,
31573157
ast::expr_copy(*) |
31583158
ast::expr_unary_move(*) |
31593159
ast::expr_repeat(*) |
3160-
ast::expr_lit(@{node: lit_str(_), _}) |
3160+
ast::expr_lit(@ast::spanned {node: lit_str(_), _}) |
31613161
ast::expr_vstore(_, ast::expr_vstore_slice) |
31623162
ast::expr_vstore(_, ast::expr_vstore_mut_slice) |
31633163
ast::expr_vstore(_, ast::expr_vstore_fixed(_)) |

src/librustc/middle/typeck/check/mod.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -552,11 +552,12 @@ fn check_struct(ccx: @crate_ctxt, struct_def: @ast::struct_def,
552552
let self_ty = ty::node_id_to_type(tcx, id);
553553

554554
do struct_def.dtor.iter() |dtor| {
555-
let class_t = {self_ty: self_ty,
556-
self_id: dtor.node.self_id,
557-
def_id: local_def(id),
558-
explicit_self: {node: ast::sty_by_ref,
559-
span: ast_util::dummy_sp()}};
555+
let class_t = { self_ty: self_ty,
556+
self_id: dtor.node.self_id,
557+
def_id: local_def(id),
558+
explicit_self:
559+
spanned { node: ast::sty_by_ref,
560+
span: ast_util::dummy_sp() } };
560561
// typecheck the dtor
561562
check_bare_fn(ccx, ast_util::dtor_dec(),
562563
dtor.node.body, dtor.node.id,
@@ -1911,7 +1912,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
19111912
match /*bad*/copy expr.node {
19121913
ast::expr_vstore(ev, vst) => {
19131914
let typ = match /*bad*/copy ev.node {
1914-
ast::expr_lit(@{node: ast::lit_str(s), span:_}) => {
1915+
ast::expr_lit(@ast::spanned { node: ast::lit_str(s), _ }) => {
19151916
let tt = ast_expr_vstore_to_vstore(fcx, ev, str::len(*s), vst);
19161917
ty::mk_estr(tcx, tt)
19171918
}
@@ -2600,7 +2601,8 @@ fn check_block(fcx0: @fn_ctxt, blk: ast::blk) -> bool {
26002601
for blk.node.stmts.each |s| {
26012602
if bot && !warned &&
26022603
match s.node {
2603-
ast::stmt_decl(@{node: ast::decl_local(_), _}, _) |
2604+
ast::stmt_decl(@ast::spanned { node: ast::decl_local(_),
2605+
_}, _) |
26042606
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) => {
26052607
true
26062608
}

src/librustc/middle/typeck/check/regionmanip.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ fn replace_bound_regions_in_fn_ty(
4343
let mut all_tys = ty::tys_in_fn_ty(fn_ty);
4444

4545
match self_info {
46-
Some({explicit_self: {node: ast::sty_region(m), _}, _}) => {
46+
Some({explicit_self: ast::spanned { node: ast::sty_region(m),
47+
_}, _}) => {
4748
let region = ty::re_bound(ty::br_self);
4849
let ty = ty::mk_rptr(tcx, region,
4950
{ ty: ty::mk_self(tcx), mutbl: m });

src/libsyntax/ast.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ use std::serialize::{Encodable, Decodable, Encoder, Decoder};
2323

2424
#[auto_encode]
2525
#[auto_decode]
26-
type spanned<T> = {node: T, span: span};
27-
26+
struct spanned<T> { node: T, span: span }
2827

2928
/* can't import macros yet, so this is copied from token.rs. See its comment
3029
* there. */

src/libsyntax/ast_map.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,15 @@ fn map_fn(fk: visit::fn_kind, decl: fn_decl, body: blk,
176176
cx.local_id += 1u;
177177
}
178178
match fk {
179-
visit::fk_dtor(tps, ref attrs, self_id, parent_id) => {
180-
let dt = @{node: {id: id, attrs: (*attrs), self_id: self_id,
181-
body: /* FIXME (#2543) */ copy body}, span: sp};
182-
cx.map.insert(id, node_dtor(/* FIXME (#2543) */ copy tps, dt,
183-
parent_id,
184-
@/* FIXME (#2543) */ copy cx.path));
179+
visit::fk_dtor(tps, ref attrs, self_id, parent_id) => {
180+
let dt = @spanned {
181+
node: {id: id, attrs: (*attrs), self_id: self_id,
182+
body: /* FIXME (#2543) */ copy body},
183+
span: sp,
184+
};
185+
cx.map.insert(id, node_dtor(/* FIXME (#2543) */ copy tps, dt,
186+
parent_id,
187+
@/* FIXME (#2543) */ copy cx.path));
185188
}
186189
_ => ()
187190
}

src/libsyntax/ast_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pure fn spanned<T>(+lo: BytePos, +hi: BytePos, +t: T) -> spanned<T> {
2929
}
3030

3131
pure fn respan<T>(sp: span, +t: T) -> spanned<T> {
32-
{node: move t, span: sp}
32+
spanned {node: t, span: sp}
3333
}
3434

3535
pure fn dummy_spanned<T>(+t: T) -> spanned<T> {
@@ -284,7 +284,7 @@ impl def_id : to_bytes::IterBytes {
284284

285285
fn block_from_expr(e: @expr) -> blk {
286286
let blk_ = default_block(~[], option::Some::<@expr>(e), e.id);
287-
return {node: blk_, span: e.span};
287+
return spanned {node: blk_, span: e.span};
288288
}
289289

290290
fn default_block(+stmts1: ~[@stmt], expr1: Option<@expr>, id1: node_id) ->

0 commit comments

Comments
 (0)