Allow empty struct expressions in Rust
authorTom Tromey <tom@tromey.com>
Mon, 11 Jul 2016 21:02:10 +0000 (15:02 -0600)
committerTom Tromey <tom@tromey.com>
Thu, 21 Jul 2016 21:16:04 +0000 (15:16 -0600)
I learned recently that empty struct expressions, like "X{}", have been
promoted from experimental to stable in Rust.  This patch changes the
Rust expression parser to allow this case.

New test case included.
Built and regtested on x86-64 Fedora 23, using Rust 1.11 beta.

2016-07-21  Tom Tromey  <tom@tromey.com>

* rust-lang.c (rust_tuple_struct_type_p): Return false for empty
structs.
* rust-exp.y (struct_expr_list): Allow empty elements.

2016-07-21  Tom Tromey  <tom@tromey.com>

* gdb.rust/simple.rs (main): Use empty struct expression.
* gdb.rust/simple.exp: Add tests for empty struct expression.

gdb/ChangeLog
gdb/rust-exp.y
gdb/rust-lang.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.rust/simple.exp
gdb/testsuite/gdb.rust/simple.rs

index 706c34d81da84cca28a760c98e6b45100c23732d..4a585355cf334e53f703c9075d5078bfddd6e085 100644 (file)
@@ -1,3 +1,9 @@
+2016-07-21  Tom Tromey  <tom@tromey.com>
+
+       * rust-lang.c (rust_tuple_struct_type_p): Return false for empty
+       structs.
+       * rust-exp.y (struct_expr_list): Allow empty elements.
+
 2016-07-21  Tom Tromey  <tom@tromey.com>
 
        * configure: Rebuild.
index 456ffe586c41399c72cb033091c0dbabcee603a4..6dc4704efe7c037102e03618f9d1d87e8d05173a 100644 (file)
@@ -428,10 +428,14 @@ struct_expr_tail:
                }
 ;
 
-/* S{} is documented as valid but seems to be an unstable feature, so
-   it is left out here.  */
 struct_expr_list:
-       struct_expr_tail
+       /* %empty */
+               {
+                 VEC (set_field) **result
+                   = OBSTACK_ZALLOC (&work_obstack, VEC (set_field) *);
+                 $$ = result;
+               }
+|      struct_expr_tail
                {
                  VEC (set_field) **result
                    = OBSTACK_ZALLOC (&work_obstack, VEC (set_field) *);
index 3deb52586ee40d50d91a354735af82694974c2c7..481a4fc59430ca319c5b00b72382461002423915 100644 (file)
@@ -294,7 +294,10 @@ rust_underscore_fields (struct type *type, int offset)
 int
 rust_tuple_struct_type_p (struct type *type)
 {
-  return rust_underscore_fields (type, 0);
+  /* This is just an approximation until DWARF can represent Rust more
+     precisely.  We exclude zero-length structs because they may not
+     be tuple structs, and there's no way to tell.  */
+  return TYPE_NFIELDS (type) > 0 && rust_underscore_fields (type, 0);
 }
 
 /* Return true if a variant TYPE is a tuple variant, false otherwise.  */
index d985c884e02d55c8d7635697b6a654447aa84b7b..547776147c4f2838bf086c30132cb2354b18c7b0 100644 (file)
@@ -1,3 +1,8 @@
+2016-07-21  Tom Tromey  <tom@tromey.com>
+
+       * gdb.rust/simple.rs (main): Use empty struct expression.
+       * gdb.rust/simple.exp: Add tests for empty struct expression.
+
 2016-07-21  Yao Qi  <yao.qi@linaro.org>
 
        * lib/gdbserver-support.exp (skip_gdbserver_tests): Return 1
index 32b3785c97172b8201a0e2ab4923283fad27cd1e..5e00b03c08816e390f8cfb0b152dd28d535f966d 100644 (file)
@@ -55,7 +55,10 @@ gdb_test "print *(&c as *mut i32)" " = 0"
 
 gdb_test "print j" " = simple::Unit"
 gdb_test "ptype j" " = struct simple::Unit"
+gdb_test "print j2" " = simple::Unit"
+gdb_test "ptype j2" " = struct simple::Unit"
 gdb_test "print simple::Unit" " = simple::Unit"
+gdb_test "print simple::Unit{}" " = simple::Unit"
 
 gdb_test "print g" " = \\(u8 \\(\\*\\)\\\[6\\\]\\) $hex b\"hi bob\""
 gdb_test "ptype g" " = u8 \\(\\*\\)\\\[6\\\]"
index 49808261324226cc8110f3a290f211a89eab0672..eeff3d71f9c9c0dd1c64cb34d3f89905e09f0a12 100644 (file)
@@ -81,6 +81,7 @@ fn main () {
     let i = ["whatever"; 8];
 
     let j = Unit;
+    let j2 = Unit{};
 
     let k = SpaceSaver::Nothing;
     let l = SpaceSaver::Thebox(9, Box::new(1729));
This page took 0.053158 seconds and 4 git commands to generate.