Skip to content

Commit ed3689d

Browse files
committed
remove ctor from ast
1 parent f5c3af1 commit ed3689d

30 files changed

+120
-651
lines changed

src/libsyntax/ast.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ enum def {
135135
@def, // closed over def
136136
node_id, // expr node that creates the closure
137137
node_id), // id for the block/body of the closure expr
138-
def_class(def_id, bool /* has constructor */),
138+
def_class(def_id),
139139
def_typaram_binder(node_id), /* class, impl or trait that has ty params */
140140
def_region(node_id),
141141
def_label(node_id)
@@ -235,9 +235,9 @@ impl def : cmp::Eq {
235235
_ => false
236236
}
237237
}
238-
def_class(e0a, e1a) => {
238+
def_class(e0a) => {
239239
match (*other) {
240-
def_class(e0b, e1b) => e0a == e0b && e1a == e1b,
240+
def_class(e0b) => e0a == e0b,
241241
_ => false
242242
}
243243
}
@@ -1462,8 +1462,6 @@ type struct_def = {
14621462
fields: ~[@struct_field], /* fields */
14631463
methods: ~[@method], /* methods */
14641464
/* (not including ctor or dtor) */
1465-
/* ctor is optional, and will soon go away */
1466-
ctor: Option<class_ctor>,
14671465
/* dtor is optional */
14681466
dtor: Option<class_dtor>
14691467
};
@@ -1563,7 +1561,6 @@ enum inlined_item {
15631561
ii_item(@item),
15641562
ii_method(def_id /* impl id */, @method),
15651563
ii_foreign(@foreign_item),
1566-
ii_ctor(class_ctor, ident, ~[ty_param], def_id /* parent id */),
15671564
ii_dtor(class_dtor, ident, ~[ty_param], def_id /* parent id */)
15681565
}
15691566

src/libsyntax/ast_map.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ enum ast_node {
7171
// order they are introduced.
7272
node_arg(arg, uint),
7373
node_local(uint),
74-
// Constructor for a class
75-
// def_id is parent id
76-
node_ctor(ident, ~[ty_param], @class_ctor, def_id, @path),
7774
// Destructor for a class
7875
node_dtor(~[ty_param], @class_dtor, def_id, @path),
7976
node_block(blk),
@@ -132,7 +129,7 @@ fn map_decoded_item(diag: span_handler,
132129
// don't decode and instantiate the impl, but just the method, we have to
133130
// add it to the table now:
134131
match ii {
135-
ii_item(*) | ii_ctor(*) | ii_dtor(*) => { /* fallthrough */ }
132+
ii_item(*) | ii_dtor(*) => { /* fallthrough */ }
136133
ii_foreign(i) => {
137134
cx.map.insert(i.id, node_foreign_item(i, foreign_abi_rust_intrinsic,
138135
@path));
@@ -155,18 +152,6 @@ fn map_fn(fk: visit::fn_kind, decl: fn_decl, body: blk,
155152
cx.local_id += 1u;
156153
}
157154
match fk {
158-
visit::fk_ctor(nm, attrs, tps, self_id, parent_id) => {
159-
let ct = @{node: {id: id,
160-
attrs: attrs,
161-
self_id: self_id,
162-
dec: /* FIXME (#2543) */ copy decl,
163-
body: /* FIXME (#2543) */ copy body},
164-
span: sp};
165-
cx.map.insert(id, node_ctor(/* FIXME (#2543) */ copy nm,
166-
/* FIXME (#2543) */ copy tps,
167-
ct, parent_id,
168-
@/* FIXME (#2543) */ copy cx.path));
169-
}
170155
visit::fk_dtor(tps, attrs, self_id, parent_id) => {
171156
let dt = @{node: {id: id, attrs: attrs, self_id: self_id,
172157
body: /* FIXME (#2543) */ copy body}, span: sp};
@@ -382,9 +367,6 @@ fn node_id_to_str(map: map, id: node_id, itr: @ident_interner) -> ~str {
382367
Some(node_local(_)) => { // add more info here
383368
fmt!("local (id=%?)", id)
384369
}
385-
Some(node_ctor(*)) => { // add more info here
386-
fmt!("node_ctor (id=%?)", id)
387-
}
388370
Some(node_dtor(*)) => { // add more info here
389371
fmt!("node_dtor (id=%?)", id)
390372
}

src/libsyntax/ast_util.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pure fn def_id_of_def(d: def) -> def_id {
5757
def_fn(id, _) | def_static_method(id, _) | def_mod(id) |
5858
def_foreign_mod(id) | def_const(id) |
5959
def_variant(_, id) | def_ty(id) | def_ty_param(id, _) |
60-
def_use(id) | def_class(id, _) => {
60+
def_use(id) | def_class(id) => {
6161
id
6262
}
6363
def_arg(id, _) | def_local(id, _) | def_self(id) |
@@ -339,7 +339,6 @@ impl inlined_item: inlined_item_utils {
339339
ii_item(i) => /* FIXME (#2543) */ copy i.ident,
340340
ii_foreign(i) => /* FIXME (#2543) */ copy i.ident,
341341
ii_method(_, m) => /* FIXME (#2543) */ copy m.ident,
342-
ii_ctor(_, nm, _, _) => /* FIXME (#2543) */ copy nm,
343342
ii_dtor(_, nm, _, _) => /* FIXME (#2543) */ copy nm
344343
}
345344
}
@@ -349,7 +348,6 @@ impl inlined_item: inlined_item_utils {
349348
ii_item(i) => i.id,
350349
ii_foreign(i) => i.id,
351350
ii_method(_, m) => m.id,
352-
ii_ctor(ctor, _, _, _) => ctor.node.id,
353351
ii_dtor(dtor, _, _, _) => dtor.node.id
354352
}
355353
}
@@ -359,9 +357,6 @@ impl inlined_item: inlined_item_utils {
359357
ii_item(i) => v.visit_item(i, e, v),
360358
ii_foreign(i) => v.visit_foreign_item(i, e, v),
361359
ii_method(_, m) => visit::visit_method_helper(m, e, v),
362-
ii_ctor(ctor, nm, tps, parent_id) => {
363-
visit::visit_class_ctor_helper(ctor, nm, tps, parent_id, e, v);
364-
}
365360
ii_dtor(dtor, _, tps, parent_id) => {
366361
visit::visit_class_dtor_helper(dtor, tps, parent_id, e, v);
367362
}
@@ -495,12 +490,6 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
495490
vfn(id);
496491

497492
match fk {
498-
visit::fk_ctor(_, _, tps, self_id, parent_id) => {
499-
for vec::each(tps) |tp| { vfn(tp.id); }
500-
vfn(id);
501-
vfn(self_id);
502-
vfn(parent_id.node);
503-
}
504493
visit::fk_dtor(tps, _, self_id, parent_id) => {
505494
for vec::each(tps) |tp| { vfn(tp.id); }
506495
vfn(id);

src/libsyntax/fold.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -271,23 +271,6 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
271271

272272
fn fold_struct_def(struct_def: @ast::struct_def, fld: ast_fold)
273273
-> @ast::struct_def {
274-
let resulting_optional_constructor;
275-
match struct_def.ctor {
276-
None => {
277-
resulting_optional_constructor = None;
278-
}
279-
Some(constructor) => {
280-
resulting_optional_constructor = Some({
281-
node: {
282-
body: fld.fold_block(constructor.node.body),
283-
dec: fold_fn_decl(constructor.node.dec, fld),
284-
id: fld.new_id(constructor.node.id),
285-
.. constructor.node
286-
},
287-
.. constructor
288-
});
289-
}
290-
}
291274
let dtor = do option::map(&struct_def.dtor) |dtor| {
292275
let dtor_body = fld.fold_block(dtor.node.body);
293276
let dtor_id = fld.new_id(dtor.node.id);
@@ -298,7 +281,6 @@ fn fold_struct_def(struct_def: @ast::struct_def, fld: ast_fold)
298281
traits: vec::map(struct_def.traits, |p| fold_trait_ref(*p, fld)),
299282
fields: vec::map(struct_def.fields, |f| fold_struct_field(*f, fld)),
300283
methods: vec::map(struct_def.methods, |m| fld.fold_method(*m)),
301-
ctor: resulting_optional_constructor,
302284
dtor: dtor
303285
};
304286
}
@@ -585,7 +567,6 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
585567
|f| fld.fold_struct_field(*f)),
586568
methods: vec::map(struct_def.methods,
587569
|m| fld.fold_method(*m)),
588-
ctor: None,
589570
dtor: dtor
590571
})
591572
}

src/libsyntax/parse/parser.rs

Lines changed: 9 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ enum class_member {
115115
So that we can distinguish a class ctor or dtor
116116
from other class members
117117
*/
118-
enum class_contents { ctor_decl(fn_decl, ~[attribute], blk, codemap::span),
119-
dtor_decl(blk, ~[attribute], codemap::span),
118+
enum class_contents { dtor_decl(blk, ~[attribute], codemap::span),
120119
members(~[@class_member]) }
121120

122121
type arg_or_capture_item = Either<arg, capture_item>;
@@ -2683,30 +2682,13 @@ impl parser {
26832682

26842683
let mut fields: ~[@struct_field];
26852684
let mut methods: ~[@method] = ~[];
2686-
let mut the_ctor: Option<(fn_decl, ~[attribute], blk, codemap::span)>
2687-
= None;
26882685
let mut the_dtor: Option<(blk, ~[attribute], codemap::span)> = None;
2689-
let ctor_id = self.get_id();
26902686

26912687
if self.eat(token::LBRACE) {
26922688
// It's a record-like struct.
26932689
fields = ~[];
26942690
while self.token != token::RBRACE {
26952691
match self.parse_class_item() {
2696-
ctor_decl(a_fn_decl, attrs, blk, s) => {
2697-
match the_ctor {
2698-
Some((_, _, _, s_first)) => {
2699-
self.span_note(s, #fmt("Duplicate constructor \
2700-
declaration for class %s",
2701-
*self.interner.get(class_name)));
2702-
self.span_fatal(copy s_first, ~"First constructor \
2703-
declared here");
2704-
}
2705-
None => {
2706-
the_ctor = Some((a_fn_decl, attrs, blk, s));
2707-
}
2708-
}
2709-
}
27102692
dtor_decl(blk, attrs, s) => {
27112693
match the_dtor {
27122694
Some((_, _, s_first)) => {
@@ -2764,36 +2746,14 @@ impl parser {
27642746
self_id: self.get_id(),
27652747
body: d_body},
27662748
span: d_s}};
2767-
match the_ctor {
2768-
Some((ct_d, ct_attrs, ct_b, ct_s)) => {
2769-
(class_name,
2770-
item_class(@{
2771-
traits: traits,
2772-
fields: move fields,
2773-
methods: move methods,
2774-
ctor: Some({
2775-
node: {id: ctor_id,
2776-
attrs: ct_attrs,
2777-
self_id: self.get_id(),
2778-
dec: ct_d,
2779-
body: ct_b},
2780-
span: ct_s}),
2781-
dtor: actual_dtor
2782-
}, ty_params),
2783-
None)
2784-
}
2785-
None => {
2786-
(class_name,
2787-
item_class(@{
2788-
traits: traits,
2789-
fields: move fields,
2790-
methods: move methods,
2791-
ctor: None,
2792-
dtor: actual_dtor
2793-
}, ty_params),
2794-
None)
2795-
}
2796-
}
2749+
(class_name,
2750+
item_class(@{
2751+
traits: traits,
2752+
fields: move fields,
2753+
methods: move methods,
2754+
dtor: actual_dtor
2755+
}, ty_params),
2756+
None)
27972757
}
27982758

27992759
fn token_is_pound_or_doc_comment(++tok: token::token) -> bool {
@@ -3097,12 +3057,6 @@ impl parser {
30973057
let mut methods: ~[@method] = ~[];
30983058
while self.token != token::RBRACE {
30993059
match self.parse_class_item() {
3100-
ctor_decl(*) => {
3101-
self.span_fatal(copy self.span,
3102-
~"deprecated explicit \
3103-
constructors are not allowed \
3104-
here");
3105-
}
31063060
dtor_decl(blk, attrs, s) => {
31073061
match the_dtor {
31083062
Some((_, _, s_first)) => {
@@ -3143,7 +3097,6 @@ impl parser {
31433097
traits: ~[],
31443098
fields: move fields,
31453099
methods: move methods,
3146-
ctor: None,
31473100
dtor: actual_dtor
31483101
};
31493102
}

src/libsyntax/print/pprust.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -653,18 +653,6 @@ fn print_struct(s: ps, struct_def: @ast::struct_def, tps: ~[ast::ty_param],
653653
}
654654
bopen(s);
655655
hardbreak_if_not_bol(s);
656-
do struct_def.ctor.iter |ctor| {
657-
maybe_print_comment(s, ctor.span.lo);
658-
print_outer_attributes(s, ctor.node.attrs);
659-
// Doesn't call head because there shouldn't be a space after new.
660-
cbox(s, indent_unit);
661-
ibox(s, 4);
662-
word(s.s, ~"new(");
663-
print_fn_args(s, ctor.node.dec, ~[], None);
664-
word(s.s, ~")");
665-
space(s.s);
666-
print_block(s, ctor.node.body);
667-
}
668656
do struct_def.dtor.iter |dtor| {
669657
hardbreak_if_not_bol(s);
670658
maybe_print_comment(s, dtor.span.lo);

src/libsyntax/visit.rs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,28 @@ enum fn_kind {
1717
fk_method(ident, ~[ty_param], @method),
1818
fk_anon(proto, capture_clause), //< an anonymous function like fn@(...)
1919
fk_fn_block(capture_clause), //< a block {||...}
20-
fk_ctor(ident, ~[attribute], ~[ty_param], node_id /* self id */,
21-
def_id /* parent class id */), // class constructor
2220
fk_dtor(~[ty_param], ~[attribute], node_id /* self id */,
2321
def_id /* parent class id */) // class destructor
2422

2523
}
2624

2725
fn name_of_fn(fk: fn_kind) -> ident {
2826
match fk {
29-
fk_item_fn(name, _, _) | fk_method(name, _, _)
30-
| fk_ctor(name, _, _, _, _) => /* FIXME (#2543) */ copy name,
27+
fk_item_fn(name, _, _) | fk_method(name, _, _) => {
28+
/* FIXME (#2543) */ copy name
29+
}
3130
fk_anon(*) | fk_fn_block(*) => parse::token::special_idents::anon,
3231
fk_dtor(*) => parse::token::special_idents::dtor
3332
}
3433
}
3534

3635
fn tps_of_fn(fk: fn_kind) -> ~[ty_param] {
3736
match fk {
38-
fk_item_fn(_, tps, _) | fk_method(_, tps, _)
39-
| fk_ctor(_, _, tps, _, _) | fk_dtor(tps, _, _, _) => {
40-
/* FIXME (#2543) */ copy tps
41-
}
42-
fk_anon(*) | fk_fn_block(*) => ~[]
37+
fk_item_fn(_, tps, _) | fk_method(_, tps, _) |
38+
fk_dtor(tps, _, _, _) => {
39+
/* FIXME (#2543) */ copy tps
40+
}
41+
fk_anon(*) | fk_fn_block(*) => ~[]
4342
}
4443
}
4544

@@ -291,17 +290,6 @@ fn visit_method_helper<E>(m: @method, e: E, v: vt<E>) {
291290
m.decl, m.body, m.span, m.id, e, v);
292291
}
293292

294-
// Similar logic to the comment on visit_method_helper - Tim
295-
fn visit_class_ctor_helper<E>(ctor: class_ctor, nm: ident, tps: ~[ty_param],
296-
parent_id: def_id, e: E, v: vt<E>) {
297-
v.visit_fn(fk_ctor(/* FIXME (#2543) */ copy nm,
298-
ctor.node.attrs,
299-
/* FIXME (#2543) */ copy tps,
300-
ctor.node.self_id, parent_id),
301-
ctor.node.dec, ctor.node.body, ctor.span, ctor.node.id, e, v)
302-
303-
}
304-
305293
fn visit_class_dtor_helper<E>(dtor: class_dtor, tps: ~[ty_param],
306294
parent_id: def_id, e: E, v: vt<E>) {
307295
v.visit_fn(fk_dtor(/* FIXME (#2543) */ copy tps, dtor.node.attrs,
@@ -330,7 +318,7 @@ fn visit_trait_method<E>(m: trait_method, e: E, v: vt<E>) {
330318
}
331319
}
332320

333-
fn visit_struct_def<E>(sd: @struct_def, nm: ast::ident, tps: ~[ty_param],
321+
fn visit_struct_def<E>(sd: @struct_def, _nm: ast::ident, tps: ~[ty_param],
334322
id: node_id, e: E, v: vt<E>) {
335323
for sd.fields.each |f| {
336324
v.visit_struct_field(*f, e, v);
@@ -341,9 +329,6 @@ fn visit_struct_def<E>(sd: @struct_def, nm: ast::ident, tps: ~[ty_param],
341329
for sd.traits.each |p| {
342330
visit_path(p.path, e, v);
343331
}
344-
do option::iter(&sd.ctor) |ctor| {
345-
visit_class_ctor_helper(*ctor, nm, tps, ast_util::local_def(id), e, v);
346-
};
347332
do option::iter(&sd.dtor) |dtor| {
348333
visit_class_dtor_helper(*dtor, tps, ast_util::local_def(id), e, v)
349334
};

0 commit comments

Comments
 (0)