From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 120742 invoked by alias); 19 Mar 2018 17:04:44 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 120625 invoked by uid 89); 19 Mar 2018 17:04:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.8 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=1126, UD:rs, sk:identic X-HELO: gateway34.websitewelcome.com Received: from gateway34.websitewelcome.com (HELO gateway34.websitewelcome.com) (192.185.148.104) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 19 Mar 2018 17:04:41 +0000 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 3549F5CB64 for ; Mon, 19 Mar 2018 12:04:40 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id xyDAeeGnXQUwqxyDAeVdBh; Mon, 19 Mar 2018 12:04:40 -0500 Received: from 174-29-60-18.hlrn.qwest.net ([174.29.60.18]:50572 helo=pokyo.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1exyD9-000jT8-QK; Mon, 19 Mar 2018 12:04:39 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [FYI] Support bare-identifier field initializers in Rust Date: Mon, 19 Mar 2018 17:04:00 -0000 Message-Id: <20180319170428.19879-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1exyD9-000jT8-QK X-Source-Sender: 174-29-60-18.hlrn.qwest.net (pokyo.Home) [174.29.60.18]:50572 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-SW-Source: 2018-03/txt/msg00361.txt.bz2 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 * rust-exp.y (struct_expr_tail, struct_expr_list): Add plain "IDENT" production. 2018-03-19 Tom Tromey * gdb.rust/simple.rs (main): Add local variables field1, field2, y0. * gdb.rust/simple.exp: Test bare identifier form of struct initializer. --- gdb/ChangeLog | 5 +++++ gdb/rust-exp.y | 17 +++++++++++++++++ gdb/testsuite/ChangeLog | 7 +++++++ gdb/testsuite/gdb.rust/simple.exp | 3 +++ gdb/testsuite/gdb.rust/simple.rs | 4 ++++ 5 files changed, 36 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index fe4ae9f684..ac52a9a666 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2018-03-19 Tom Tromey + + * rust-exp.y (struct_expr_tail, struct_expr_list): Add plain + "IDENT" production. + 2018-03-19 Pedro Alves Tom Tromey diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y index f1dcecec96..b661a803e3 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: diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index c648fc518f..f155ffee71 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,12 @@ 2018-03-19 Tom Tromey + * gdb.rust/simple.rs (main): Add local variables field1, field2, + y0. + * gdb.rust/simple.exp: Test bare identifier form of struct + initializer. + +2018-03-19 Tom Tromey + * gdb.gdb/observer.exp: Remove. 2018-03-19 Andreas Arnez diff --git a/gdb/testsuite/gdb.rust/simple.exp b/gdb/testsuite/gdb.rust/simple.exp index 230e6a7a88..2db596b932 100644 --- a/gdb/testsuite/gdb.rust/simple.exp +++ b/gdb/testsuite/gdb.rust/simple.exp @@ -166,6 +166,9 @@ gdb_test "print simple::HiBob + 5" \ gdb_test "print nosuchsymbol" \ "No symbol 'nosuchsymbol' in current context" +gdb_test "print simple::HiBob{field1, field2}" \ + " = simple::HiBob \\{field1: 77, field2: 88\\}" + gdb_test "print e" " = simple::MoreComplicated::Two\\(73\\)" gdb_test "print e2" \ " = simple::MoreComplicated::Four\\{this: true, is: 8, a: 109 'm', struct_: 100, variant: 10\\}" diff --git a/gdb/testsuite/gdb.rust/simple.rs b/gdb/testsuite/gdb.rust/simple.rs index 7e43cd8707..b2b5dfe0f6 100644 --- a/gdb/testsuite/gdb.rust/simple.rs +++ b/gdb/testsuite/gdb.rust/simple.rs @@ -112,6 +112,10 @@ fn main () { let y = HiBob {field1: 7, field2: 8}; let z = ByeBob(7, 8); + let field1 = 77; + let field2 = 88; + let y0 = HiBob { field1, field2 }; + let univariant = Univariant::Foo {a : 1}; let univariant_anon = UnivariantAnon::Foo(1); -- 2.13.6