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:
parent
a1674b6150
commit
4457d2b379
@ -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,
|
||||
|
@ -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)];
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
8
src/test/run-pass/struct-new-as-field-name.rs
Normal file
8
src/test/run-pass/struct-new-as-field-name.rs
Normal file
@ -0,0 +1,8 @@
|
||||
struct Foo {
|
||||
new: int,
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let foo = Foo{ new: 3 };
|
||||
assert_eq!(foo.new, 3);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user