Allow empty struct expressions in Rust
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.
This commit is contained in:
parent
305450edd3
commit
12df5c002d
6 changed files with 26 additions and 4 deletions
|
@ -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>
|
2016-07-21 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* configure: Rebuild.
|
* configure: Rebuild.
|
||||||
|
|
|
@ -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_list:
|
||||||
struct_expr_tail
|
/* %empty */
|
||||||
|
{
|
||||||
|
VEC (set_field) **result
|
||||||
|
= OBSTACK_ZALLOC (&work_obstack, VEC (set_field) *);
|
||||||
|
$$ = result;
|
||||||
|
}
|
||||||
|
| struct_expr_tail
|
||||||
{
|
{
|
||||||
VEC (set_field) **result
|
VEC (set_field) **result
|
||||||
= OBSTACK_ZALLOC (&work_obstack, VEC (set_field) *);
|
= OBSTACK_ZALLOC (&work_obstack, VEC (set_field) *);
|
||||||
|
|
|
@ -294,7 +294,10 @@ rust_underscore_fields (struct type *type, int offset)
|
||||||
int
|
int
|
||||||
rust_tuple_struct_type_p (struct type *type)
|
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. */
|
/* Return true if a variant TYPE is a tuple variant, false otherwise. */
|
||||||
|
|
|
@ -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>
|
2016-07-21 Yao Qi <yao.qi@linaro.org>
|
||||||
|
|
||||||
* lib/gdbserver-support.exp (skip_gdbserver_tests): Return 1
|
* lib/gdbserver-support.exp (skip_gdbserver_tests): Return 1
|
||||||
|
|
|
@ -55,7 +55,10 @@ gdb_test "print *(&c as *mut i32)" " = 0"
|
||||||
|
|
||||||
gdb_test "print j" " = simple::Unit"
|
gdb_test "print j" " = simple::Unit"
|
||||||
gdb_test "ptype j" " = struct 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 simple::Unit{}" " = simple::Unit"
|
||||||
|
|
||||||
gdb_test "print g" " = \\(u8 \\(\\*\\)\\\[6\\\]\\) $hex b\"hi bob\""
|
gdb_test "print g" " = \\(u8 \\(\\*\\)\\\[6\\\]\\) $hex b\"hi bob\""
|
||||||
gdb_test "ptype g" " = u8 \\(\\*\\)\\\[6\\\]"
|
gdb_test "ptype g" " = u8 \\(\\*\\)\\\[6\\\]"
|
||||||
|
|
|
@ -81,6 +81,7 @@ fn main () {
|
||||||
let i = ["whatever"; 8];
|
let i = ["whatever"; 8];
|
||||||
|
|
||||||
let j = Unit;
|
let j = Unit;
|
||||||
|
let j2 = Unit{};
|
||||||
|
|
||||||
let k = SpaceSaver::Nothing;
|
let k = SpaceSaver::Nothing;
|
||||||
let l = SpaceSaver::Thebox(9, Box::new(1729));
|
let l = SpaceSaver::Thebox(9, Box::new(1729));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue