aboutsummaryrefslogtreecommitdiff
path: root/gdb/rust-exp.y
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-03-19 10:25:05 -0600
committerTom Tromey <tom@tromey.com>2018-03-19 11:01:31 -0600
commit926300415b642367cdc2febac6619f8cb8a80b46 (patch)
tree4b0859a0bdf08f69f8ceb3e2ce69ad6bf1cf4441 /gdb/rust-exp.y
parent76727919ceb590f03ff0f6db08b7ceab5b7aeaff (diff)
downloadgdb-926300415b642367cdc2febac6619f8cb8a80b46.zip
gdb-926300415b642367cdc2febac6619f8cb8a80b46.tar.gz
gdb-926300415b642367cdc2febac6619f8cb8a80b46.tar.bz2
Support bare-identifier field initializers in Rust
In Rust one can initialize a struct member from an identically-named local variable by simply mentioning the member name in the initializer, like: let x = 0; let y = Struct { x }; This initializes "Struct::x" from "x". This patch adds this form of initializer to the Rust expression parser and adds a test. Tested on x86-64 Fedora 26 using rustc 1.23. 2018-03-19 Tom Tromey <tom@tromey.com> * rust-exp.y (struct_expr_tail, struct_expr_list): Add plain "IDENT" production. 2018-03-19 Tom Tromey <tom@tromey.com> * gdb.rust/simple.rs (main): Add local variables field1, field2, y0. * gdb.rust/simple.exp: Test bare identifier form of struct initializer.
Diffstat (limited to 'gdb/rust-exp.y')
-rw-r--r--gdb/rust-exp.y17
1 files changed, 17 insertions, 0 deletions
diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
index f1dcece..b661a80 100644
--- a/gdb/rust-exp.y
+++ b/gdb/rust-exp.y
@@ -481,6 +481,14 @@ struct_expr_tail:
sf.init = $3;
$$ = sf;
}
+| IDENT
+ {
+ struct set_field sf;
+
+ sf.name = $1;
+ sf.init = ast_path ($1, NULL);
+ $$ = sf;
+ }
;
struct_expr_list:
@@ -503,6 +511,15 @@ struct_expr_list:
$5->push_back (sf);
$$ = $5;
}
+| IDENT ',' struct_expr_list
+ {
+ struct set_field sf;
+
+ sf.name = $1;
+ sf.init = ast_path ($1, NULL);
+ $3->push_back (sf);
+ $$ = $3;
+ }
;
array_expr: