Skip to content

Commit 970f5cc

Browse files
committed
Make ast::ty_method hold a fn_decl, rather than duplicating its fields
1 parent f0dfbe7 commit 970f5cc

File tree

5 files changed

+20
-39
lines changed

5 files changed

+20
-39
lines changed

src/comp/middle/typeck.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,21 +356,21 @@ fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t {
356356
let tmeths: [ty::method] = [];
357357
for m: ast::ty_method in meths {
358358
let ins = [];
359-
for ta: ast::arg in m.node.inputs {
359+
for ta: ast::arg in m.decl.inputs {
360360
ins += [ast_arg_to_arg(tcx, mode, ta)];
361361
}
362-
let out = ast_ty_to_ty(tcx, mode, m.node.output);
362+
let out = ast_ty_to_ty(tcx, mode, m.decl.output);
363363

364364
let out_constrs = [];
365-
for constr: @ast::constr in m.node.constrs {
365+
for constr: @ast::constr in m.decl.constraints {
366366
out_constrs += [ty::ast_constr_to_constr(tcx, constr)];
367367
}
368368
let new_m: ty::method =
369-
{proto: m.node.proto,
370-
ident: m.node.ident,
369+
{proto: m.decl.proto,
370+
ident: m.ident,
371371
inputs: ins,
372372
output: out,
373-
cf: m.node.cf,
373+
cf: m.decl.cf,
374374
constrs: out_constrs};
375375
tmeths += [new_m];
376376
}

src/comp/syntax/ast.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -307,17 +307,9 @@ type mt = {ty: @ty, mut: mutability};
307307

308308
type ty_field_ = {ident: ident, mt: mt};
309309

310-
type ty_method_ =
311-
{proto: proto,
312-
ident: ident,
313-
inputs: [arg],
314-
output: @ty,
315-
cf: ret_style,
316-
constrs: [@constr]};
317-
318310
type ty_field = spanned<ty_field_>;
319311

320-
type ty_method = spanned<ty_method_>;
312+
type ty_method = {ident: ident, decl: fn_decl, span: span};
321313

322314
tag int_ty { ty_i; ty_char; ty_i8; ty_i16; ty_i32; ty_i64; }
323315

src/comp/syntax/parse/parser.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,7 @@ fn parse_ty_obj(p: parser) -> ast::ty_ {
294294
expect(p, token::SEMI);
295295
alt f {
296296
ast::ty_fn(d) {
297-
// FIXME[fn_decl]
298-
ret spanned(flo, fhi,
299-
{proto: d.proto,
300-
ident: ident,
301-
inputs: d.inputs,
302-
output: d.output,
303-
cf: d.cf,
304-
constrs: d.constraints});
297+
{ident: ident, decl: d, span: ast_util::mk_sp(flo, fhi)}
305298
}
306299
}
307300
}

src/comp/syntax/print/pprust.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,7 @@ fn print_type(s: ps, &&ty: @ast::ty) {
306306
pclose(s);
307307
}
308308
ast::ty_fn(d) {
309-
print_ty_fn(s, d.proto, none::<str>, d.inputs, d.output, d.cf,
310-
d.constraints);
309+
print_ty_fn(s, d, none::<str>);
311310
}
312311
ast::ty_obj(methods) {
313312
head(s, "obj");
@@ -316,8 +315,7 @@ fn print_type(s: ps, &&ty: @ast::ty) {
316315
hardbreak_if_not_bol(s);
317316
cbox(s, indent_unit);
318317
maybe_print_comment(s, m.span.lo);
319-
print_ty_fn(s, m.node.proto, some(m.node.ident), m.node.inputs,
320-
m.node.output, m.node.cf, m.node.constrs);
318+
print_ty_fn(s, m.decl, some(m.ident));
321319
word(s.s, ";");
322320
end(s);
323321
}
@@ -1338,11 +1336,9 @@ fn print_mt(s: ps, mt: ast::mt) {
13381336
print_type(s, mt.ty);
13391337
}
13401338

1341-
fn print_ty_fn(s: ps, proto: ast::proto, id: option::t<ast::ident>,
1342-
inputs: [ast::arg], output: @ast::ty, cf: ast::ret_style,
1343-
constrs: [@ast::constr]) {
1339+
fn print_ty_fn(s: ps, decl: ast::fn_decl, id: option::t<ast::ident>) {
13441340
ibox(s, indent_unit);
1345-
word(s.s, proto_to_str(proto));
1341+
word(s.s, proto_to_str(decl.proto));
13461342
alt id { some(id) { word(s.s, " "); word(s.s, id); } _ { } }
13471343
zerobreak(s.s);
13481344
popen(s);
@@ -1353,18 +1349,18 @@ fn print_ty_fn(s: ps, proto: ast::proto, id: option::t<ast::ident>,
13531349
}
13541350
print_type(s, input.ty);
13551351
}
1356-
commasep(s, inconsistent, inputs, print_arg);
1352+
commasep(s, inconsistent, decl.inputs, print_arg);
13571353
pclose(s);
1358-
maybe_print_comment(s, output.span.lo);
1359-
if output.node != ast::ty_nil {
1354+
maybe_print_comment(s, decl.output.span.lo);
1355+
if decl.output.node != ast::ty_nil {
13601356
space_if_not_bol(s);
13611357
ibox(s, indent_unit);
13621358
word_space(s, "->");
1363-
if cf == ast::noreturn { word_nbsp(s, "!"); }
1364-
else { print_type(s, output); }
1359+
if decl.cf == ast::noreturn { word_nbsp(s, "!"); }
1360+
else { print_type(s, decl.output); }
13651361
end(s);
13661362
}
1367-
word(s.s, ast_ty_fn_constrs_str(constrs));
1363+
word(s.s, ast_ty_fn_constrs_str(decl.constraints));
13681364
end(s);
13691365
}
13701366

src/comp/syntax/visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ fn visit_ty<E>(t: @ty, e: E, v: vt<E>) {
151151
}
152152
ty_obj(tmeths) {
153153
for m: ty_method in tmeths {
154-
for a in m.node.inputs { v.visit_ty(a.ty, e, v); }
155-
v.visit_ty(m.node.output, e, v);
154+
for a in m.decl.inputs { v.visit_ty(a.ty, e, v); }
155+
v.visit_ty(m.decl.output, e, v);
156156
}
157157
}
158158
ty_path(p, _) { visit_path(p, e, v); }

0 commit comments

Comments
 (0)