From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7905) id 3EECB385771B; Tue, 16 Jan 2024 18:10:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3EECB385771B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705428624; bh=Nb+wjw5VeP/cgUmamY4otxs4E5k50edsGnzj4+nwEHI=; h=From:To:Subject:Date:From; b=MqndiTyUzODgU363E11UiWxIvxoy+FG4F3GEa0nlp4jCc0IchRygQX25CXSZ4PT1t XTdAOfUC8gzP8S871ZBSvJeH7e3ZSwWh1P3R7xHxoM7dU7XWjstRiLSe93ujCXklDN PESHP16Ph2daWdFdg4gNhAmwgLASGYY8NgkfHGH0= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Arthur Cohen To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-7977] gccrs: Change trait getter to return references X-Act-Checkin: gcc X-Git-Author: Pierre-Emmanuel Patry X-Git-Refname: refs/heads/trunk X-Git-Oldrev: de8bc8f9bc03230f124802c4dd0a42f79796a770 X-Git-Newrev: 90ee631428f0af1d91ee297ea114755d7f0563c7 Message-Id: <20240116181024.3EECB385771B@sourceware.org> Date: Tue, 16 Jan 2024 18:10:24 +0000 (GMT) List-Id: https://gcc.gnu.org/g:90ee631428f0af1d91ee297ea114755d7f0563c7 commit r14-7977-g90ee631428f0af1d91ee297ea114755d7f0563c7 Author: Pierre-Emmanuel Patry Date: Mon Jul 31 12:31:58 2023 +0200 gccrs: Change trait getter to return references Having copy and any other constructor stuff might lead to a breakage in the future where the node id differs due to a newly constructed SimplePath node. This change will allow us to assert the NodeId is from the ast and not any copy made in between. gcc/rust/ChangeLog: * ast/rust-ast.cc (Attribute::get_traits_to_derive): Change return type to a vector of references. * ast/rust-ast.h: Update constructor. * expand/rust-expand-visitor.cc (ExpandVisitor::expand_inner_stmts): Update function call. Signed-off-by: Pierre-Emmanuel Patry Diff: --- gcc/rust/ast/rust-ast.cc | 6 +++--- gcc/rust/ast/rust-ast.h | 2 +- gcc/rust/expand/rust-expand-visitor.cc | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 076f40e338b..3525a15beb5 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -95,15 +95,15 @@ Attribute::is_derive () const * * @param attrs The attributes on the item to derive */ -std::vector +std::vector> Attribute::get_traits_to_derive () { - std::vector result; + std::vector> result; auto &input = get_attr_input (); switch (input.get_attr_input_type ()) { case AST::AttrInput::META_ITEM: { - auto meta = static_cast (input); + auto &meta = static_cast (input); for (auto ¤t : meta.get_items ()) { // HACK: Find a better way to achieve the downcast. diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 32732ffdbd7..136da86525d 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -519,7 +519,7 @@ public: bool is_derive () const; - std::vector get_traits_to_derive (); + std::vector> get_traits_to_derive (); // default destructor ~Attribute () = default; diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc index f75069b2e0a..55d5de0a04e 100644 --- a/gcc/rust/expand/rust-expand-visitor.cc +++ b/gcc/rust/expand/rust-expand-visitor.cc @@ -185,7 +185,7 @@ ExpandVisitor::expand_inner_items ( for (auto &to_derive : traits_to_derive) { auto maybe_builtin = MacroBuiltin::builtins.lookup ( - to_derive.as_string ()); + to_derive.get ().as_string ()); if (MacroBuiltin::builtins.is_iter_ok (maybe_builtin)) { auto new_item @@ -271,7 +271,7 @@ ExpandVisitor::expand_inner_stmts (AST::BlockExpr &expr) for (auto &to_derive : traits_to_derive) { auto maybe_builtin = MacroBuiltin::builtins.lookup ( - to_derive.as_string ()); + to_derive.get ().as_string ()); if (MacroBuiltin::builtins.is_iter_ok (maybe_builtin)) { auto new_item