diff --git a/gcc/rust/ast/rust-ast-full-decls.h b/gcc/rust/ast/rust-ast-full-decls.h index 9e961f9878d6..4b89056541c6 100644 --- a/gcc/rust/ast/rust-ast-full-decls.h +++ b/gcc/rust/ast/rust-ast-full-decls.h @@ -52,7 +52,6 @@ class GenericParam; class LifetimeParam; class ConstGenericParam; class TraitItem; -class InherentImplItem; class TraitImplItem; struct Crate; class PathExpr; diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index d80c00298919..d6fd744e85da 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -64,7 +64,7 @@ SingleASTNode::SingleASTNode (SingleASTNode const &other) break; case IMPL: - impl_item = other.impl_item->clone_inherent_impl_item (); + impl_item = other.impl_item->clone_associated_item (); break; case TRAIT_IMPL: @@ -104,7 +104,7 @@ SingleASTNode::operator= (SingleASTNode const &other) break; case IMPL: - impl_item = other.impl_item->clone_inherent_impl_item (); + impl_item = other.impl_item->clone_associated_item (); break; case TRAIT_IMPL: diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index d94b0db29c72..8d04be76a568 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1687,22 +1687,6 @@ class TraitItem : virtual public AssociatedItem location_t get_locus () const override { return locus; } }; -/* Abstract base class for items used within an inherent impl block (the impl - * name {} one) */ -class InherentImplItem : virtual public AssociatedItem -{ -protected: - // Clone function implementation as pure virtual method - virtual InherentImplItem *clone_associated_item_impl () const override = 0; - -public: - // Unique pointer custom clone function - std::unique_ptr clone_inherent_impl_item () const - { - return std::unique_ptr (clone_associated_item_impl ()); - } -}; - // Abstract base class for items used in a trait impl class TraitImplItem : virtual public AssociatedItem { @@ -1860,7 +1844,7 @@ class SingleASTNode : public Visitable std::unique_ptr stmt; std::unique_ptr external_item; std::unique_ptr trait_item; - std::unique_ptr impl_item; + std::unique_ptr impl_item; std::unique_ptr trait_impl_item; std::unique_ptr type; @@ -1885,7 +1869,7 @@ class SingleASTNode : public Visitable : kind (TRAIT), trait_item (std::move (item)) {} - SingleASTNode (std::unique_ptr item) + SingleASTNode (std::unique_ptr item) : kind (IMPL), impl_item (std::move (item)) {} @@ -1959,7 +1943,7 @@ class SingleASTNode : public Visitable return std::move (external_item); } - std::unique_ptr take_impl_item () + std::unique_ptr take_impl_item () { rust_assert (!is_error ()); return std::move (impl_item); diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index d907748fa6f3..b44d6d92967d 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -1285,7 +1285,9 @@ class UseDeclaration : public VisItem class LetStmt; // Rust function declaration AST node -class Function : public VisItem, public InherentImplItem, public TraitImplItem +class Function : public VisItem, + virtual public AssociatedItem, + public TraitImplItem { FunctionQualifiers qualifiers; Identifier function_name; @@ -2308,7 +2310,7 @@ class Union : public VisItem /* "Constant item" AST node - used for constant, compile-time expressions * within module scope (like constexpr) */ class ConstantItem : public VisItem, - public InherentImplItem, + virtual public AssociatedItem, public TraitImplItem { // either has an identifier or "_" - maybe handle in identifier? @@ -3408,7 +3410,7 @@ class Impl : public VisItem class InherentImpl : public Impl { // bool has_impl_items; - std::vector> impl_items; + std::vector> impl_items; public: std::string as_string () const override; @@ -3417,7 +3419,7 @@ class InherentImpl : public Impl bool has_impl_items () const { return !impl_items.empty (); } // Mega-constructor - InherentImpl (std::vector> impl_items, + InherentImpl (std::vector> impl_items, std::vector> generic_params, std::unique_ptr trait_type, WhereClause where_clause, Visibility vis, std::vector inner_attrs, @@ -3433,7 +3435,7 @@ class InherentImpl : public Impl { impl_items.reserve (other.impl_items.size ()); for (const auto &e : other.impl_items) - impl_items.push_back (e->clone_inherent_impl_item ()); + impl_items.push_back (e->clone_associated_item ()); } // Overloaded assignment operator with vector clone @@ -3443,7 +3445,7 @@ class InherentImpl : public Impl impl_items.reserve (other.impl_items.size ()); for (const auto &e : other.impl_items) - impl_items.push_back (e->clone_inherent_impl_item ()); + impl_items.push_back (e->clone_associated_item ()); return *this; } @@ -3455,11 +3457,11 @@ class InherentImpl : public Impl void accept_vis (ASTVisitor &vis) override; // TODO: think of better way to do this - const std::vector> &get_impl_items () const + const std::vector> &get_impl_items () const { return impl_items; } - std::vector> &get_impl_items () + std::vector> &get_impl_items () { return impl_items; } diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index 07991649a936..f1f525056969 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -599,7 +599,7 @@ class MacroInvocation : public TypeNoBounds, public Item, public TraitItem, public TraitImplItem, - public InherentImplItem, + virtual public AssociatedItem, public ExternalItem, public ExprWithoutBlock { diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc index 3f598b7f21ce..1745af061746 100644 --- a/gcc/rust/expand/rust-expand-visitor.cc +++ b/gcc/rust/expand/rust-expand-visitor.cc @@ -1180,7 +1180,7 @@ ExpandVisitor::visit (AST::InherentImpl &impl) if (impl.has_where_clause ()) expand_where_clause (impl.get_where_clause ()); - std::function (AST::SingleASTNode)> + std::function (AST::SingleASTNode)> extractor = [] (AST::SingleASTNode node) { return node.take_impl_item (); }; expand_macro_children (MacroExpander::ContextType::IMPL, diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 5d4865d6a78c..a2096f73e72b 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -5388,12 +5388,12 @@ Parser::parse_impl (AST::Visibility vis, AST::AttrVec inner_attrs = parse_inner_attributes (); // parse inherent impl items - std::vector> impl_items; + std::vector> impl_items; const_TokenPtr t = lexer.peek_token (); while (t->get_id () != RIGHT_CURLY) { - std::unique_ptr impl_item + std::unique_ptr impl_item = parse_inherent_impl_item (); if (impl_item == nullptr) @@ -5512,7 +5512,7 @@ Parser::parse_impl (AST::Visibility vis, // Parses a single inherent impl item (item inside an inherent impl block). template -std::unique_ptr +std::unique_ptr Parser::parse_inherent_impl_item () { // parse outer attributes (if they exist) @@ -5629,7 +5629,7 @@ Parser::parse_inherent_impl_item () // InherentImplItem is this specialisation of the template while TraitImplItem // will be the other. template -std::unique_ptr +std::unique_ptr Parser::parse_inherent_impl_function_or_method ( AST::Visibility vis, AST::AttrVec outer_attrs) { diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index d3718467b489..4291e4198a5f 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -170,7 +170,7 @@ template class Parser std::unique_ptr parse_type (bool save_errors = true); std::unique_ptr parse_external_item (); std::unique_ptr parse_trait_item (); - std::unique_ptr parse_inherent_impl_item (); + std::unique_ptr parse_inherent_impl_item (); std::unique_ptr parse_trait_impl_item (); AST::PathInExpression parse_path_in_expression (); std::vector> parse_lifetime_params (); @@ -348,7 +348,7 @@ template class Parser std::unique_ptr parse_impl (AST::Visibility vis, AST::AttrVec outer_attrs); - std::unique_ptr + std::unique_ptr parse_inherent_impl_function_or_method (AST::Visibility vis, AST::AttrVec outer_attrs); std::unique_ptr