Skip to content

Commit 7d6d002

Browse files
committed
syntax: remove parsing destructors
1 parent 5d79f94 commit 7d6d002

File tree

1 file changed

+14
-78
lines changed

1 file changed

+14
-78
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 14 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,6 @@ enum restriction {
102102
RESTRICT_NO_BAR_OR_DOUBLEBAR_OP,
103103
}
104104

105-
// So that we can distinguish a class dtor from other class members
106-
107-
enum class_contents { dtor_decl(blk, ~[attribute], codemap::span),
108-
members(~[@struct_field]) }
109-
110105
type arg_or_capture_item = Either<arg, ()>;
111106
type item_info = (ident, item_, Option<~[attribute]>);
112107

@@ -3299,34 +3294,15 @@ pub impl Parser {
32993294
}
33003295

33013296
let mut fields: ~[@struct_field];
3302-
let mut the_dtor: Option<(blk, ~[attribute], codemap::span)> = None;
33033297
let is_tuple_like;
33043298

33053299
if self.eat(&token::LBRACE) {
33063300
// It's a record-like struct.
33073301
is_tuple_like = false;
33083302
fields = ~[];
33093303
while *self.token != token::RBRACE {
3310-
match self.parse_struct_decl_field() {
3311-
dtor_decl(ref blk, ref attrs, s) => {
3312-
match the_dtor {
3313-
Some((_, _, s_first)) => {
3314-
self.span_note(s, fmt!("Duplicate destructor \
3315-
declaration for class %s",
3316-
*self.interner.get(class_name)));
3317-
self.span_fatal(copy s_first, ~"First destructor \
3318-
declared here");
3319-
}
3320-
None => {
3321-
the_dtor = Some((copy *blk, copy *attrs, s));
3322-
}
3323-
}
3324-
}
3325-
members(mms) => {
3326-
for mms.each |struct_field| {
3327-
fields.push(*struct_field)
3328-
}
3329-
}
3304+
for self.parse_struct_decl_field().each |struct_field| {
3305+
fields.push(*struct_field)
33303306
}
33313307
}
33323308
if fields.len() == 0 {
@@ -3365,19 +3341,12 @@ pub impl Parser {
33653341
);
33663342
}
33673343

3368-
let actual_dtor = do the_dtor.map |dtor| {
3369-
let (d_body, d_attrs, d_s) = copy *dtor;
3370-
codemap::spanned { node: ast::struct_dtor_ { id: self.get_id(),
3371-
attrs: d_attrs,
3372-
self_id: self.get_id(),
3373-
body: d_body},
3374-
span: d_s}};
33753344
let _ = self.get_id(); // XXX: Workaround for crazy bug.
33763345
let new_id = self.get_id();
33773346
(class_name,
33783347
item_struct(@ast::struct_def {
33793348
fields: fields,
3380-
dtor: actual_dtor,
3349+
dtor: None,
33813350
ctor_id: if is_tuple_like { Some(new_id) } else { None }
33823351
}, generics),
33833352
None)
@@ -3420,34 +3389,28 @@ pub impl Parser {
34203389
}
34213390

34223391
// parse an element of a struct definition
3423-
fn parse_struct_decl_field(&self) -> class_contents {
3392+
fn parse_struct_decl_field(&self) -> ~[@struct_field] {
34243393

34253394
if self.try_parse_obsolete_priv_section() {
3426-
return members(~[]);
3395+
return ~[];
34273396
}
34283397

3429-
let attrs = self.parse_outer_attributes();
3398+
// Need this to parse comments on fields.
3399+
let _attrs = self.parse_outer_attributes();
34303400

34313401
if self.eat_keyword(&~"priv") {
3432-
return members(~[self.parse_single_struct_field(private)])
3402+
return ~[self.parse_single_struct_field(private)]
34333403
}
34343404

34353405
if self.eat_keyword(&~"pub") {
3436-
return members(~[self.parse_single_struct_field(public)]);
3406+
return ~[self.parse_single_struct_field(public)];
34373407
}
34383408

34393409
if self.try_parse_obsolete_struct_ctor() {
3440-
return members(~[]);
3410+
return ~[];
34413411
}
34423412

3443-
if self.eat_keyword(&~"drop") {
3444-
let lo = self.last_span.lo;
3445-
let body = self.parse_block();
3446-
return dtor_decl(body, attrs, mk_sp(lo, self.last_span.hi))
3447-
}
3448-
else {
3449-
return members(~[self.parse_single_struct_field(inherited)]);
3450-
}
3413+
return ~[self.parse_single_struct_field(inherited)];
34513414
}
34523415

34533416
// parse visiility: PUB, PRIV, or nothing
@@ -3830,44 +3793,17 @@ pub impl Parser {
38303793
// parse a structure-like enum variant definition
38313794
// this should probably be renamed or refactored...
38323795
fn parse_struct_def(&self) -> @struct_def {
3833-
let mut the_dtor: Option<(blk, ~[attribute], codemap::span)> = None;
38343796
let mut fields: ~[@struct_field] = ~[];
38353797
while *self.token != token::RBRACE {
3836-
match self.parse_struct_decl_field() {
3837-
dtor_decl(ref blk, ref attrs, s) => {
3838-
match the_dtor {
3839-
Some((_, _, s_first)) => {
3840-
self.span_note(s, ~"duplicate destructor \
3841-
declaration");
3842-
self.span_fatal(copy s_first,
3843-
~"first destructor \
3844-
declared here");
3845-
}
3846-
None => {
3847-
the_dtor = Some((copy *blk, copy *attrs, s));
3848-
}
3849-
}
3850-
}
3851-
members(mms) => {
3852-
for mms.each |struct_field| {
3853-
fields.push(*struct_field);
3854-
}
3855-
}
3798+
for self.parse_struct_decl_field().each |struct_field| {
3799+
fields.push(*struct_field);
38563800
}
38573801
}
38583802
self.bump();
3859-
let actual_dtor = do the_dtor.map |dtor| {
3860-
let (d_body, d_attrs, d_s) = copy *dtor;
3861-
codemap::spanned { node: ast::struct_dtor_ { id: self.get_id(),
3862-
attrs: d_attrs,
3863-
self_id: self.get_id(),
3864-
body: d_body },
3865-
span: d_s }
3866-
};
38673803

38683804
return @ast::struct_def {
38693805
fields: fields,
3870-
dtor: actual_dtor,
3806+
dtor: None,
38713807
ctor_id: None
38723808
};
38733809
}

0 commit comments

Comments
 (0)