Skip to content

Commit d5d77b9

Browse files
ericktcatamorphism
authored andcommitted
convert the remaining ast record types into structs
These are: region,arg,fn_decl,method,_mod,foreign_mod, variant_arg,enum_def_,variant_,trait_ref.
1 parent 5ba7e55 commit d5d77b9

File tree

17 files changed

+335
-205
lines changed

17 files changed

+335
-205
lines changed

src/librustc/driver/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ mod test {
361361
if with_bin { attrs += ~[make_crate_type_attr(~"bin")]; }
362362
if with_lib { attrs += ~[make_crate_type_attr(~"lib")]; }
363363
@ast_util::respan(ast_util::dummy_sp(), ast::crate_ {
364-
module: {view_items: ~[], items: ~[]},
364+
module: ast::_mod { view_items: ~[], items: ~[] },
365365
attrs: attrs,
366366
config: ~[]
367367
})

src/librustc/front/config.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,14 @@ fn filter_view_item(cx: ctxt, &&view_item: @ast::view_item
6767
}
6868
}
6969

70-
fn fold_mod(cx: ctxt, m: ast::_mod, fld: fold::ast_fold) ->
71-
ast::_mod {
70+
fn fold_mod(cx: ctxt, m: ast::_mod, fld: fold::ast_fold) -> ast::_mod {
7271
let filtered_items = vec::filter_map(m.items, |a| filter_item(cx, *a));
7372
let filtered_view_items = vec::filter_map(m.view_items,
7473
|a| filter_view_item(cx, *a));
75-
return {
76-
view_items: vec::map(filtered_view_items, |x| fld.fold_view_item(*x)),
77-
items: vec::filter_map(filtered_items, |x| fld.fold_item(*x))
78-
};
74+
ast::_mod {
75+
view_items: filtered_view_items.map(|x| fld.fold_view_item(*x)),
76+
items: filtered_items.filter_map(|x| fld.fold_item(*x)),
77+
}
7978
}
8079

8180
fn filter_foreign_item(cx: ctxt, &&item: @ast::foreign_item) ->
@@ -85,18 +84,21 @@ fn filter_foreign_item(cx: ctxt, &&item: @ast::foreign_item) ->
8584
} else { option::None }
8685
}
8786

88-
fn fold_foreign_mod(cx: ctxt, nm: ast::foreign_mod,
89-
fld: fold::ast_fold) -> ast::foreign_mod {
87+
fn fold_foreign_mod(
88+
cx: ctxt,
89+
nm: ast::foreign_mod,
90+
fld: fold::ast_fold
91+
) -> ast::foreign_mod {
9092
let filtered_items = vec::filter_map(nm.items,
9193
|a| filter_foreign_item(cx, *a));
9294
let filtered_view_items = vec::filter_map(nm.view_items,
9395
|a| filter_view_item(cx, *a));
94-
return {
96+
ast::foreign_mod {
9597
sort: nm.sort,
9698
abi: nm.abi,
9799
view_items: vec::map(filtered_view_items, |x| fld.fold_view_item(*x)),
98100
items: filtered_items
99-
};
101+
}
100102
}
101103

102104
fn fold_item_underscore(cx: ctxt, +item: ast::item_,

src/librustc/front/core_inject.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn inject_libcore_ref(sess: Session,
6262
};
6363

6464
let vis = vec::append(~[vi1], crate.module.view_items);
65-
let mut new_module = {
65+
let mut new_module = ast::_mod {
6666
view_items: vis,
6767
../*bad*/copy crate.module
6868
};
@@ -95,7 +95,7 @@ fn inject_libcore_ref(sess: Session,
9595
let vis = vec::append(~[vi2], module.view_items);
9696

9797
// FIXME #2543: Bad copy.
98-
let new_module = { view_items: vis, ..copy module };
98+
let new_module = ast::_mod { view_items: vis, ..copy module };
9999
fold::noop_fold_mod(new_module, fld)
100100
},
101101
..*fold::default_ast_fold()

src/librustc/front/intrinsic_inject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn inject_intrinsic(sess: Session, crate: @ast::crate) -> @ast::crate {
3838

3939
@ast::spanned {
4040
node: ast::crate_ {
41-
module: {
41+
module: ast::_mod {
4242
items: items,
4343
.. /*bad*/copy crate.node.module
4444
},

src/librustc/front/test.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,12 @@ fn fold_mod(cx: test_ctxt, m: ast::_mod, fld: fold::ast_fold) -> ast::_mod {
9797
} else { item }
9898
}
9999

100-
let mod_nomain =
101-
{view_items: /*bad*/copy m.view_items,
102-
items: vec::map(m.items, |i| nomain(cx, *i))};
103-
return fold::noop_fold_mod(mod_nomain, fld);
100+
let mod_nomain = ast::_mod {
101+
view_items: /*bad*/copy m.view_items,
102+
items: vec::map(m.items, |i| nomain(cx, *i)),
103+
};
104+
105+
fold::noop_fold_mod(mod_nomain, fld)
104106
}
105107

106108
fn fold_crate(cx: test_ctxt, c: ast::crate_, fld: fold::ast_fold) ->
@@ -182,7 +184,10 @@ fn should_fail(i: @ast::item) -> bool {
182184

183185
fn add_test_module(cx: test_ctxt, +m: ast::_mod) -> ast::_mod {
184186
let testmod = mk_test_module(cx);
185-
return {items: vec::append_one(/*bad*/copy m.items, testmod),.. m};
187+
ast::_mod {
188+
items: vec::append_one(/*bad*/copy m.items, testmod),
189+
.. m
190+
}
186191
}
187192

188193
/*
@@ -213,8 +218,9 @@ fn mk_test_module(cx: test_ctxt) -> @ast::item {
213218
// The synthesized main function which will call the console test runner
214219
// with our list of tests
215220
let mainfn = mk_main(cx);
216-
let testmod: ast::_mod = {
217-
view_items: view_items, items: ~[mainfn, testsfn]
221+
let testmod = ast::_mod {
222+
view_items: view_items,
223+
items: ~[mainfn, testsfn],
218224
};
219225
let item_ = ast::item_mod(testmod);
220226
// This attribute tells resolve to let us call unexported functions
@@ -276,10 +282,11 @@ fn mk_std(cx: test_ctxt) -> @ast::view_item {
276282
fn mk_tests(cx: test_ctxt) -> @ast::item {
277283
let ret_ty = mk_test_desc_vec_ty(cx);
278284

279-
let decl: ast::fn_decl =
280-
{inputs: ~[],
281-
output: ret_ty,
282-
cf: ast::return_val};
285+
let decl = ast::fn_decl {
286+
inputs: ~[],
287+
output: ret_ty,
288+
cf: ast::return_val,
289+
};
283290

284291
// The vector of test_descs for this crate
285292
let test_descs = mk_test_desc_vec(cx);
@@ -486,7 +493,7 @@ fn mk_test_wrapper(cx: test_ctxt,
486493
let call_stmt: ast::stmt = nospan(
487494
ast::stmt_semi(@call_expr, cx.sess.next_node_id()));
488495

489-
let wrapper_decl: ast::fn_decl = {
496+
let wrapper_decl = ast::fn_decl {
490497
inputs: ~[],
491498
output: @ast::Ty {
492499
id: cx.sess.next_node_id(),
@@ -521,10 +528,11 @@ fn mk_main(cx: test_ctxt) -> @ast::item {
521528
span: dummy_sp(),
522529
};
523530

524-
let decl: ast::fn_decl =
525-
{inputs: ~[],
526-
output: @ret_ty,
527-
cf: ast::return_val};
531+
let decl = ast::fn_decl {
532+
inputs: ~[],
533+
output: @ret_ty,
534+
cf: ast::return_val,
535+
};
528536

529537
let test_main_call_expr = mk_test_main_call(cx);
530538

src/librustc/middle/trans/base.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,13 +1842,17 @@ fn trans_enum_variant(ccx: @crate_ctxt,
18421842
llfndecl: ValueRef) {
18431843
let _icx = ccx.insn_ctxt("trans_enum_variant");
18441844
// Translate variant arguments to function arguments.
1845-
let fn_args = vec::map(args, |varg|
1846-
{mode: ast::expl(ast::by_copy),
1847-
ty: varg.ty,
1848-
pat: ast_util::ident_to_pat(ccx.tcx.sess.next_node_id(),
1849-
ast_util::dummy_sp(),
1850-
special_idents::arg),
1851-
id: varg.id});
1845+
let fn_args = do args.map |varg| {
1846+
ast::arg {
1847+
mode: ast::expl(ast::by_copy),
1848+
ty: varg.ty,
1849+
pat: ast_util::ident_to_pat(
1850+
ccx.tcx.sess.next_node_id(),
1851+
ast_util::dummy_sp(),
1852+
special_idents::arg),
1853+
id: varg.id,
1854+
}
1855+
};
18521856
// XXX: Bad copy of `param_substs`.
18531857
let fcx = new_fn_ctxt_w_id(ccx, ~[], llfndecl, variant.node.id, None,
18541858
copy param_substs, None);
@@ -1902,7 +1906,7 @@ fn trans_tuple_struct(ccx: @crate_ctxt,
19021906

19031907
// Translate struct fields to function arguments.
19041908
let fn_args = do fields.map |field| {
1905-
{
1909+
ast::arg {
19061910
mode: ast::expl(ast::by_copy),
19071911
ty: field.node.ty,
19081912
pat: ast_util::ident_to_pat(ccx.tcx.sess.next_node_id(),

src/librustc/middle/trans/type_use.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint)
9696
match map_node {
9797
ast_map::node_item(@ast::item { node: item_fn(_, _, _, ref body),
9898
_ }, _) |
99-
ast_map::node_method(@{body: ref body, _}, _, _) => {
99+
ast_map::node_method(@ast::method {body: ref body, _}, _, _) => {
100100
handle_body(cx, (*body));
101101
}
102102
ast_map::node_trait_method(*) => {

src/libsyntax/ast.rs

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,10 @@ impl prim_ty : cmp::Eq {
11071107

11081108
#[auto_encode]
11091109
#[auto_decode]
1110-
type region = {id: node_id, node: region_};
1110+
struct region {
1111+
id: node_id,
1112+
node: region_,
1113+
}
11111114

11121115
#[auto_encode]
11131116
#[auto_decode]
@@ -1194,14 +1197,20 @@ impl Ty : to_bytes::IterBytes {
11941197

11951198
#[auto_encode]
11961199
#[auto_decode]
1197-
type arg = {mode: mode, ty: @Ty, pat: @pat, id: node_id};
1200+
struct arg {
1201+
mode: mode,
1202+
ty: @Ty,
1203+
pat: @pat,
1204+
id: node_id,
1205+
}
11981206

11991207
#[auto_encode]
12001208
#[auto_decode]
1201-
type fn_decl =
1202-
{inputs: ~[arg],
1203-
output: @Ty,
1204-
cf: ret_style};
1209+
struct fn_decl {
1210+
inputs: ~[arg],
1211+
output: @Ty,
1212+
cf: ret_style,
1213+
}
12051214

12061215
#[auto_encode]
12071216
#[auto_decode]
@@ -1321,15 +1330,26 @@ type self_ty = spanned<self_ty_>;
13211330
13221331
#[auto_encode]
13231332
#[auto_decode]
1324-
type method = {ident: ident, attrs: ~[attribute],
1325-
tps: ~[ty_param], self_ty: self_ty,
1326-
purity: purity, decl: fn_decl, body: blk,
1327-
id: node_id, span: span, self_id: node_id,
1328-
vis: visibility};
1333+
struct method {
1334+
ident: ident,
1335+
attrs: ~[attribute],
1336+
tps: ~[ty_param],
1337+
self_ty: self_ty,
1338+
purity: purity,
1339+
decl: fn_decl,
1340+
body: blk,
1341+
id: node_id,
1342+
span: span,
1343+
self_id: node_id,
1344+
vis: visibility,
1345+
}
13291346
13301347
#[auto_encode]
13311348
#[auto_decode]
1332-
type _mod = {view_items: ~[@view_item], items: ~[@item]};
1349+
struct _mod {
1350+
view_items: ~[@view_item],
1351+
items: ~[@item],
1352+
}
13331353
13341354
#[auto_encode]
13351355
#[auto_decode]
@@ -1367,15 +1387,19 @@ impl foreign_abi : cmp::Eq {
13671387
13681388
#[auto_encode]
13691389
#[auto_decode]
1370-
type foreign_mod =
1371-
{sort: foreign_mod_sort,
1372-
abi: ident,
1373-
view_items: ~[@view_item],
1374-
items: ~[@foreign_item]};
1390+
struct foreign_mod {
1391+
sort: foreign_mod_sort,
1392+
abi: ident,
1393+
view_items: ~[@view_item],
1394+
items: ~[@foreign_item],
1395+
}
13751396
13761397
#[auto_encode]
13771398
#[auto_decode]
1378-
type variant_arg = {ty: @Ty, id: node_id};
1399+
struct variant_arg {
1400+
ty: @Ty,
1401+
id: node_id,
1402+
}
13791403
13801404
#[auto_encode]
13811405
#[auto_decode]
@@ -1387,16 +1411,25 @@ enum variant_kind {
13871411
13881412
#[auto_encode]
13891413
#[auto_decode]
1390-
type enum_def_ = { variants: ~[variant], common: Option<@struct_def> };
1414+
struct enum_def_ {
1415+
variants: ~[variant],
1416+
common: Option<@struct_def>,
1417+
}
13911418
13921419
#[auto_encode]
13931420
#[auto_decode]
13941421
enum enum_def = enum_def_;
13951422
13961423
#[auto_encode]
13971424
#[auto_decode]
1398-
type variant_ = {name: ident, attrs: ~[attribute], kind: variant_kind,
1399-
id: node_id, disr_expr: Option<@expr>, vis: visibility};
1425+
struct variant_ {
1426+
name: ident,
1427+
attrs: ~[attribute],
1428+
kind: variant_kind,
1429+
id: node_id,
1430+
disr_expr: Option<@expr>,
1431+
vis: visibility,
1432+
}
14001433
14011434
type variant = spanned<variant_>;
14021435
@@ -1492,7 +1525,10 @@ struct attribute_ {
14921525
*/
14931526
#[auto_encode]
14941527
#[auto_decode]
1495-
type trait_ref = {path: @path, ref_id: node_id};
1528+
struct trait_ref {
1529+
path: @path,
1530+
ref_id: node_id,
1531+
}
14961532

14971533
#[auto_encode]
14981534
#[auto_decode]

src/libsyntax/ast_util.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,11 @@ fn operator_prec(op: ast::binop) -> uint {
443443
fn dtor_dec() -> fn_decl {
444444
let nil_t = @ast::Ty { id: 0, node: ty_nil, span: dummy_sp() };
445445
// dtor has no args
446-
{inputs: ~[],
447-
output: nil_t, cf: return_val}
446+
ast::fn_decl {
447+
inputs: ~[],
448+
output: nil_t,
449+
cf: return_val,
450+
}
448451
}
449452

450453
// ______________________________________________________________________

0 commit comments

Comments
 (0)