Skip to content

Commit 8cdc3fd

Browse files
ericktcatamorphism
authored andcommitted
convert ast::ty into a struct
1 parent 8a3a1fc commit 8cdc3fd

File tree

10 files changed

+149
-80
lines changed

10 files changed

+149
-80
lines changed

src/librustc/front/test.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -329,19 +329,25 @@ fn mk_test_desc_vec_ty(cx: test_ctxt) -> @ast::Ty {
329329
mk_path(cx, ~[cx.sess.ident_of(~"test"),
330330
cx.sess.ident_of(~"TestDesc")]);
331331

332-
let test_desc_ty: ast::Ty =
333-
{id: cx.sess.next_node_id(),
334-
node: ast::ty_path(test_desc_ty_path, cx.sess.next_node_id()),
335-
span: dummy_sp()};
332+
let test_desc_ty = ast::Ty {
333+
id: cx.sess.next_node_id(),
334+
node: ast::ty_path(test_desc_ty_path, cx.sess.next_node_id()),
335+
span: dummy_sp(),
336+
};
336337

337338
let vec_mt = ast::mt {ty: @test_desc_ty, mutbl: ast::m_imm};
338339

339-
let inner_ty = @{id: cx.sess.next_node_id(),
340-
node: ast::ty_vec(vec_mt),
341-
span: dummy_sp()};
342-
return @{id: cx.sess.next_node_id(),
343-
node: ast::ty_uniq(ast::mt {ty: inner_ty, mutbl: ast::m_imm}),
344-
span: dummy_sp()};
340+
let inner_ty = @ast::Ty {
341+
id: cx.sess.next_node_id(),
342+
node: ast::ty_vec(vec_mt),
343+
span: dummy_sp(),
344+
};
345+
346+
@ast::Ty {
347+
id: cx.sess.next_node_id(),
348+
node: ast::ty_uniq(ast::mt { ty: inner_ty, mutbl: ast::m_imm }),
349+
span: dummy_sp(),
350+
}
345351
}
346352

347353
fn mk_test_desc_vec(cx: test_ctxt) -> @ast::expr {
@@ -482,7 +488,11 @@ fn mk_test_wrapper(cx: test_ctxt,
482488

483489
let wrapper_decl: ast::fn_decl = {
484490
inputs: ~[],
485-
output: @{id: cx.sess.next_node_id(), node: ast::ty_nil, span: span},
491+
output: @ast::Ty {
492+
id: cx.sess.next_node_id(),
493+
node: ast::ty_nil,
494+
span: span,
495+
},
486496
cf: ast::return_val
487497
};
488498

@@ -505,9 +515,11 @@ fn mk_test_wrapper(cx: test_ctxt,
505515
}
506516

507517
fn mk_main(cx: test_ctxt) -> @ast::item {
508-
let ret_ty = {id: cx.sess.next_node_id(),
509-
node: ast::ty_nil,
510-
span: dummy_sp()};
518+
let ret_ty = ast::Ty {
519+
id: cx.sess.next_node_id(),
520+
node: ast::ty_nil,
521+
span: dummy_sp(),
522+
};
511523

512524
let decl: ast::fn_decl =
513525
{inputs: ~[],

src/librustc/middle/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ impl Resolver {
12811281
// If there are static methods, then create the module
12821282
// and add them.
12831283
match (trait_ref_opt, ty) {
1284-
(None, @{ id: _, node: ty_path(path, _), span: _ }) if
1284+
(None, @Ty { node: ty_path(path, _), _ }) if
12851285
has_static_methods && path.idents.len() == 1 => {
12861286
// Create the module.
12871287
let name = path_to_ident(path);

src/libsyntax/ast.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,11 @@ impl float_ty : cmp::Eq {
10401040

10411041
#[auto_encode]
10421042
#[auto_decode]
1043-
type Ty = {id: node_id, node: ty_, span: span};
1043+
struct Ty {
1044+
id: node_id,
1045+
node: ty_,
1046+
span: span,
1047+
}
10441048

10451049
// Not represented directly in the AST, referred to by name through a ty_path.
10461050
#[auto_encode]

src/libsyntax/ast_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ fn operator_prec(op: ast::binop) -> uint {
435435
}
436436

437437
fn dtor_dec() -> fn_decl {
438-
let nil_t = @{id: 0, node: ty_nil, span: dummy_sp()};
438+
let nil_t = @ast::Ty { id: 0, node: ty_nil, span: dummy_sp() };
439439
// dtor has no args
440440
{inputs: ~[],
441441
output: nil_t, cf: return_val}

src/libsyntax/ext/auto_encode.rs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ fn expand_auto_encode(
130130
do vec::flat_map(in_items) |item| {
131131
if item.attrs.any(is_auto_encode) {
132132
match item.node {
133-
ast::item_ty(@{node: ast::ty_rec(ref fields), _}, tps) => {
133+
ast::item_ty(
134+
@ast::Ty {node: ast::ty_rec(ref fields), _},
135+
tps
136+
) => {
134137
let ser_impl = mk_rec_ser_impl(
135138
cx,
136139
item.span,
@@ -196,7 +199,10 @@ fn expand_auto_decode(
196199
do vec::flat_map(in_items) |item| {
197200
if item.attrs.any(is_auto_decode) {
198201
match item.node {
199-
ast::item_ty(@{node: ast::ty_rec(ref fields), _}, tps) => {
202+
ast::item_ty(
203+
@ast::Ty {node: ast::ty_rec(ref fields), _},
204+
tps
205+
) => {
200206
let deser_impl = mk_rec_deser_impl(
201207
cx,
202208
item.span,
@@ -249,7 +255,7 @@ priv impl ext_ctxt {
249255
path: @ast::path,
250256
bounds: @~[ast::ty_param_bound]
251257
) -> ast::ty_param {
252-
let bound = ast::TraitTyParamBound(@{
258+
let bound = ast::TraitTyParamBound(@ast::Ty {
253259
id: self.next_id(),
254260
node: ast::ty_path(path, self.next_id()),
255261
span: span,
@@ -315,9 +321,13 @@ priv impl ext_ctxt {
315321

316322
fn ty_path(span: span, strs: ~[ast::ident],
317323
tps: ~[@ast::Ty]) -> @ast::Ty {
318-
@{id: self.next_id(),
319-
node: ast::ty_path(self.path_tps(span, strs, tps), self.next_id()),
320-
span: span}
324+
@ast::Ty {
325+
id: self.next_id(),
326+
node: ast::ty_path(
327+
self.path_tps(span, strs, tps),
328+
self.next_id()),
329+
span: span,
330+
}
321331
}
322332

323333
fn binder_pat(span: span, nm: ast::ident) -> @ast::pat {
@@ -438,7 +448,7 @@ fn mk_impl(
438448
let mut trait_tps = vec::append(
439449
~[ty_param],
440450
do tps.map |tp| {
441-
let t_bound = ast::TraitTyParamBound(@{
451+
let t_bound = ast::TraitTyParamBound(@ast::Ty {
442452
id: cx.next_id(),
443453
node: ast::ty_path(path, cx.next_id()),
444454
span: span,
@@ -568,7 +578,7 @@ fn mk_ser_method(
568578
span: span,
569579
ser_body: ast::blk
570580
) -> @ast::method {
571-
let ty_s = @{
581+
let ty_s = @ast::Ty {
572582
id: cx.next_id(),
573583
node: ast::ty_rptr(
574584
@{
@@ -597,7 +607,7 @@ fn mk_ser_method(
597607
id: cx.next_id(),
598608
}];
599609

600-
let ser_output = @{
610+
let ser_output = @ast::Ty {
601611
id: cx.next_id(),
602612
node: ast::ty_nil,
603613
span: span,
@@ -631,7 +641,7 @@ fn mk_deser_method(
631641
ty: @ast::Ty,
632642
deser_body: ast::blk
633643
) -> @ast::method {
634-
let ty_d = @{
644+
let ty_d = @ast::Ty {
635645
id: cx.next_id(),
636646
node: ast::ty_rptr(
637647
@{
@@ -670,8 +680,7 @@ fn mk_deser_method(
670680
ident: cx.ident_of(~"decode"),
671681
attrs: ~[],
672682
tps: ~[],
673-
self_ty: ast::spanned { node: ast::sty_static,
674-
span: span },
683+
self_ty: ast::spanned { node: ast::sty_static, span: span },
675684
purity: ast::impure_fn,
676685
decl: deser_decl,
677686
body: deser_body,
@@ -1181,7 +1190,7 @@ fn mk_enum_deser_body(
11811190
{
11821191
inputs: ~[{
11831192
mode: ast::infer(cx.next_id()),
1184-
ty: @{
1193+
ty: @ast::Ty {
11851194
id: cx.next_id(),
11861195
node: ast::ty_infer,
11871196
span: span
@@ -1196,7 +1205,7 @@ fn mk_enum_deser_body(
11961205
},
11971206
id: cx.next_id(),
11981207
}],
1199-
output: @{
1208+
output: @ast::Ty {
12001209
id: cx.next_id(),
12011210
node: ast::ty_infer,
12021211
span: span,

src/libsyntax/ext/build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ fn mk_local(cx: ext_ctxt, sp: span, mutbl: bool,
194194
None),
195195
span: sp,
196196
};
197-
let ty : @ast::Ty = @{ id: cx.next_id(), node: ast::ty_infer, span: sp };
197+
let ty = @ast::Ty { id: cx.next_id(), node: ast::ty_infer, span: sp };
198198
let local = @ast::spanned {
199199
node: ast::local_ {
200200
is_mutbl: mutbl,
@@ -293,7 +293,7 @@ fn mk_ty_path(cx: ext_ctxt,
293293
-> @ast::Ty {
294294
let ty = build::mk_raw_path(span, idents);
295295
let ty = ast::ty_path(ty, cx.next_id());
296-
let ty = @{ id: cx.next_id(), node: move ty, span: span };
296+
let ty = @ast::Ty { id: cx.next_id(), node: move ty, span: span };
297297
ty
298298
}
299299
fn mk_ty_path_global(cx: ext_ctxt,
@@ -302,7 +302,7 @@ fn mk_ty_path_global(cx: ext_ctxt,
302302
-> @ast::Ty {
303303
let ty = build::mk_raw_path_global(span, idents);
304304
let ty = ast::ty_path(ty, cx.next_id());
305-
let ty = @{ id: cx.next_id(), node: move ty, span: span };
305+
let ty = @ast::Ty { id: cx.next_id(), node: move ty, span: span };
306306
ty
307307
}
308308
fn mk_simple_ty_path(cx: ext_ctxt,

src/libsyntax/ext/deriving.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ fn create_eq_method(cx: ext_ctxt,
140140
arg_region,
141141
ast::mt { ty: arg_path_type, mutbl: m_imm }
142142
);
143-
let arg_type = @{ id: cx.next_id(), node: move arg_type, span: span };
143+
let arg_type = @ast::Ty {
144+
id: cx.next_id(),
145+
node: arg_type,
146+
span: span,
147+
};
144148

145149
// Create the `other` parameter.
146150
let other_ident = cx.ident_of(~"__other");
@@ -150,10 +154,10 @@ fn create_eq_method(cx: ext_ctxt,
150154
let bool_ident = cx.ident_of(~"bool");
151155
let output_type = build::mk_raw_path(span, ~[ bool_ident ]);
152156
let output_type = ty_path(output_type, cx.next_id());
153-
let output_type = @{
157+
let output_type = @ast::Ty {
154158
id: cx.next_id(),
155-
node: move output_type,
156-
span: span
159+
node: output_type,
160+
span: span,
157161
};
158162

159163
// Create the function declaration.
@@ -199,7 +203,7 @@ fn create_self_type_with_params(cx: ext_ctxt,
199203
~[ type_ident ],
200204
move self_ty_params);
201205
let self_type = ty_path(self_type, cx.next_id());
202-
@{ id: cx.next_id(), node: move self_type, span: span }
206+
@ast::Ty { id: cx.next_id(), node: self_type, span: span }
203207
}
204208

205209
fn create_derived_impl(cx: ext_ctxt,
@@ -303,7 +307,7 @@ fn create_iter_bytes_method(cx: ext_ctxt,
303307
let f_arg = build::mk_arg(cx, span, f_ident, f_arg_type);
304308

305309
// Create the type of the return value.
306-
let output_type = @{ id: cx.next_id(), node: ty_nil, span: span };
310+
let output_type = @ast::Ty { id: cx.next_id(), node: ty_nil, span: span };
307311

308312
// Create the function declaration.
309313
let inputs = ~[ move lsb0_arg, move f_arg ];

src/libsyntax/ext/pipes/ast_builder.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,19 @@ impl ext_ctxt: ext_ctxt_ast_builder {
176176
}
177177

178178
fn ty_rec(+fields: ~[ast::ty_field]) -> @ast::Ty {
179-
@{id: self.next_id(),
180-
node: ast::ty_rec(fields),
181-
span: dummy_sp()}
179+
@ast::Ty {
180+
id: self.next_id(),
181+
node: ast::ty_rec(fields),
182+
span: dummy_sp(),
183+
}
182184
}
183185

184186
fn ty_infer() -> @ast::Ty {
185-
@{id: self.next_id(),
186-
node: ast::ty_infer,
187-
span: dummy_sp()}
187+
@ast::Ty {
188+
id: self.next_id(),
189+
node: ast::ty_infer,
190+
span: dummy_sp(),
191+
}
188192
}
189193

190194
fn ty_param(id: ast::ident, +bounds: ~[ast::ty_param_bound])
@@ -340,15 +344,19 @@ impl ext_ctxt: ext_ctxt_ast_builder {
340344
}
341345

342346
fn ty_path_ast_builder(path: @ast::path) -> @ast::Ty {
343-
@{id: self.next_id(),
344-
node: ast::ty_path(path, self.next_id()),
345-
span: path.span}
347+
@ast::Ty {
348+
id: self.next_id(),
349+
node: ast::ty_path(path, self.next_id()),
350+
span: path.span,
351+
}
346352
}
347353

348354
fn ty_nil_ast_builder() -> @ast::Ty {
349-
@{id: self.next_id(),
350-
node: ast::ty_nil,
351-
span: dummy_sp()}
355+
@ast::Ty {
356+
id: self.next_id(),
357+
node: ast::ty_nil,
358+
span: dummy_sp(),
359+
}
352360
}
353361

354362
fn item_ty_poly(name: ident,

src/libsyntax/fold.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,11 @@ impl ast_fold_fns: ast_fold {
770770
}
771771
fn fold_ty(&&x: @Ty) -> @Ty {
772772
let (n, s) = (self.fold_ty)(x.node, x.span, self as ast_fold);
773-
return @{id: (self.new_id)(x.id), node: n, span: (self.new_span)(s)};
773+
@Ty {
774+
id: (self.new_id)(x.id),
775+
node: n,
776+
span: (self.new_span)(s),
777+
}
774778
}
775779
fn fold_mod(x: _mod) -> _mod {
776780
return (self.fold_mod)(x, self as ast_fold);

0 commit comments

Comments
 (0)