fix for #8088 (Cannot name a struct field new due to ancient syntax)

remove code for parsing ancient syntax
added a run-pass test
This commit is contained in:
Do Nhat Minh 2013-08-17 14:43:13 +08:00
parent a1674b6150
commit 4457d2b379
4 changed files with 8 additions and 25 deletions

View File

@ -32,7 +32,6 @@ use std::to_bytes;
pub enum ObsoleteSyntax {
ObsoleteLet,
ObsoleteFieldTerminator,
ObsoleteStructCtor,
ObsoleteWith,
ObsoleteClassTraits,
ObsoletePrivSection,
@ -89,7 +88,6 @@ pub trait ParserObsoleteMethods {
fn token_is_obsolete_ident(&self, ident: &str, token: &Token) -> bool;
fn is_obsolete_ident(&self, ident: &str) -> bool;
fn eat_obsolete_ident(&self, ident: &str) -> bool;
fn try_parse_obsolete_struct_ctor(&self) -> bool;
fn try_parse_obsolete_with(&self) -> bool;
fn try_parse_obsolete_priv_section(&self, attrs: &[Attribute]) -> bool;
}
@ -106,12 +104,6 @@ impl ParserObsoleteMethods for Parser {
"field declaration terminated with semicolon",
"fields are now separated by commas"
),
ObsoleteStructCtor => (
"struct constructor",
"structs are now constructed with `MyStruct { foo: val }` \
syntax. Structs with private fields cannot be created \
outside of their defining module"
),
ObsoleteWith => (
"with",
"record update is done with `..`, e.g. \
@ -311,17 +303,6 @@ impl ParserObsoleteMethods for Parser {
}
}
fn try_parse_obsolete_struct_ctor(&self) -> bool {
if self.eat_obsolete_ident("new") {
self.obsolete(*self.last_span, ObsoleteStructCtor);
self.parse_fn_decl();
self.parse_block();
true
} else {
false
}
}
fn try_parse_obsolete_with(&self) -> bool {
if *self.token == token::COMMA
&& self.look_ahead(1,

View File

@ -3929,10 +3929,6 @@ impl Parser {
return ~[self.parse_single_struct_field(public, attrs)];
}
if self.try_parse_obsolete_struct_ctor() {
return ~[];
}
return ~[self.parse_single_struct_field(inherited, attrs)];
}

View File

@ -13,8 +13,6 @@ struct s {
//~^ ERROR obsolete syntax: `let` in field declaration
bar: ();
//~^ ERROR obsolete syntax: field declaration terminated with semicolon
new() { }
//~^ ERROR obsolete syntax: struct constructor
}
struct q : r {

View File

@ -0,0 +1,8 @@
struct Foo {
new: int,
}
pub fn main() {
let foo = Foo{ new: 3 };
assert_eq!(foo.new, 3);
}