Skip to content

Commit 00dd9e9

Browse files
committed
auto merge of #8573 : mrordinaire/rust/struct-new-as-field-name, r=alexcrichton
fix for #8088, along with a test.
2 parents d56b9b1 + 4457d2b commit 00dd9e9

File tree

4 files changed

+8
-25
lines changed

4 files changed

+8
-25
lines changed

src/libsyntax/parse/obsolete.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use std::to_bytes;
3232
pub enum ObsoleteSyntax {
3333
ObsoleteLet,
3434
ObsoleteFieldTerminator,
35-
ObsoleteStructCtor,
3635
ObsoleteWith,
3736
ObsoleteClassTraits,
3837
ObsoletePrivSection,
@@ -89,7 +88,6 @@ pub trait ParserObsoleteMethods {
8988
fn token_is_obsolete_ident(&self, ident: &str, token: &Token) -> bool;
9089
fn is_obsolete_ident(&self, ident: &str) -> bool;
9190
fn eat_obsolete_ident(&self, ident: &str) -> bool;
92-
fn try_parse_obsolete_struct_ctor(&self) -> bool;
9391
fn try_parse_obsolete_with(&self) -> bool;
9492
fn try_parse_obsolete_priv_section(&self, attrs: &[Attribute]) -> bool;
9593
}
@@ -106,12 +104,6 @@ impl ParserObsoleteMethods for Parser {
106104
"field declaration terminated with semicolon",
107105
"fields are now separated by commas"
108106
),
109-
ObsoleteStructCtor => (
110-
"struct constructor",
111-
"structs are now constructed with `MyStruct { foo: val }` \
112-
syntax. Structs with private fields cannot be created \
113-
outside of their defining module"
114-
),
115107
ObsoleteWith => (
116108
"with",
117109
"record update is done with `..`, e.g. \
@@ -311,17 +303,6 @@ impl ParserObsoleteMethods for Parser {
311303
}
312304
}
313305

314-
fn try_parse_obsolete_struct_ctor(&self) -> bool {
315-
if self.eat_obsolete_ident("new") {
316-
self.obsolete(*self.last_span, ObsoleteStructCtor);
317-
self.parse_fn_decl();
318-
self.parse_block();
319-
true
320-
} else {
321-
false
322-
}
323-
}
324-
325306
fn try_parse_obsolete_with(&self) -> bool {
326307
if *self.token == token::COMMA
327308
&& self.look_ahead(1,

src/libsyntax/parse/parser.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3929,10 +3929,6 @@ impl Parser {
39293929
return ~[self.parse_single_struct_field(public, attrs)];
39303930
}
39313931

3932-
if self.try_parse_obsolete_struct_ctor() {
3933-
return ~[];
3934-
}
3935-
39363932
return ~[self.parse_single_struct_field(inherited, attrs)];
39373933
}
39383934

src/test/compile-fail/obsolete-syntax.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ struct s {
1313
//~^ ERROR obsolete syntax: `let` in field declaration
1414
bar: ();
1515
//~^ ERROR obsolete syntax: field declaration terminated with semicolon
16-
new() { }
17-
//~^ ERROR obsolete syntax: struct constructor
1816
}
1917

2018
struct q : r {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
struct Foo {
2+
new: int,
3+
}
4+
5+
pub fn main() {
6+
let foo = Foo{ new: 3 };
7+
assert_eq!(foo.new, 3);
8+
}

0 commit comments

Comments
 (0)