]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #8573 : mrordinaire/rust/struct-new-as-field-name, r=alexcrichton
authorbors <bors@rust-lang.org>
Wed, 21 Aug 2013 04:41:50 +0000 (21:41 -0700)
committerbors <bors@rust-lang.org>
Wed, 21 Aug 2013 04:41:50 +0000 (21:41 -0700)
fix for #8088, along with a test.

src/libsyntax/parse/obsolete.rs
src/libsyntax/parse/parser.rs
src/test/compile-fail/obsolete-syntax.rs
src/test/run-pass/struct-new-as-field-name.rs [new file with mode: 0644]

index 01c1af7464db618537f4a311c80fa04fa3c2538c..989a796cbc9127f800b01d8f9ff4cb1d1e18dcdb 100644 (file)
@@ -32,7 +32,6 @@
 pub enum ObsoleteSyntax {
     ObsoleteLet,
     ObsoleteFieldTerminator,
-    ObsoleteStructCtor,
     ObsoleteWith,
     ObsoleteClassTraits,
     ObsoletePrivSection,
@@ -89,7 +88,6 @@ fn report(&self,
     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 @@ fn obsolete(&self, sp: span, kind: ObsoleteSyntax) {
                 "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 @@ fn eat_obsolete_ident(&self, ident: &str) -> bool {
         }
     }
 
-    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,
index de7abb8d1f46d290738cf7c16c9d1ada65f15006..2b977153b033ff7a4ea101eeb003a12fa43a299a 100644 (file)
@@ -3929,10 +3929,6 @@ fn parse_struct_decl_field(&self) -> ~[@struct_field] {
            return ~[self.parse_single_struct_field(public, attrs)];
         }
 
-        if self.try_parse_obsolete_struct_ctor() {
-            return ~[];
-        }
-
         return ~[self.parse_single_struct_field(inherited, attrs)];
     }
 
index 8ba5e2815a5a9b6fec675f90ea65341b81d36035..49af0972341d14385934f41e95b04da5fba23e86 100644 (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 {
diff --git a/src/test/run-pass/struct-new-as-field-name.rs b/src/test/run-pass/struct-new-as-field-name.rs
new file mode 100644 (file)
index 0000000..fb93c56
--- /dev/null
@@ -0,0 +1,8 @@
+struct Foo {
+    new: int,
+}
+
+pub fn main() {
+    let foo = Foo{ new: 3 };
+    assert_eq!(foo.new, 3);
+}