]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Remove AST::TraitItemConst
authorOwen Avery <powerboat9.gamer@gmail.com>
Mon, 15 Sep 2025 03:23:56 +0000 (23:23 -0400)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 30 Oct 2025 19:59:12 +0000 (20:59 +0100)
gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Remove
overload for TraitItemConst.
* ast/rust-ast-collector.h (TokenCollector::visit): Likewise.
* ast/rust-ast-pointer-visitor.cc (PointerVisitor::visit):
Likewise.
* ast/rust-ast-pointer-visitor.h (PointerVisitor::visit):
Likewise.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
* ast/rust-ast-visitor.h (ASTVisitor::visit): Likewise.
(DefaultASTVisitor::visit): Likewise.
* expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise.
* expand/rust-cfg-strip.h (CfgStrip::visit): Likewise.
* expand/rust-derive.h (DeriveVisitor::visit): Likewise.
* expand/rust-expand-visitor.cc (ExpandVisitor::visit):
Likewise.
* expand/rust-expand-visitor.h (ExpandVisitor::visit): Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h (ASTLoweringBase::visit): Likewise.
* util/rust-attributes.cc (AttributeChecker::visit): Likewise.
* util/rust-attributes.h (AttributeChecker::visit): Likewise.
* ast/rust-ast.cc (ConstantItem::as_string): Handle missing
expression.
(TraitItemConst::as_string): Remove function definition.
(TraitItemConst::accept_vis): Remove function definition.
* ast/rust-item.h (ConstantItem::mark_for_strip): Adjust
comment.
(ConstantItem::has_expr): Make const.
(class TraitItemConst): Remove definition.
* ast/rust-ast-full-decls.h (class TraitItemConst): Remove
declaration.
* hir/rust-ast-lower-implitem.cc (ASTLowerTraitItem::visit):
Handle ConstantItem instead of TraitItemConst.
* hir/rust-ast-lower-implitem.h (ASTLowerTraitItem::visit):
Likewise.
* parse/rust-parse-impl.h (Parser::parse_trait_const): Return
pointer to ConstantItem instead of TraitItemConst.
* parse/rust-parse.h (Parser::parse_trait_const): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
22 files changed:
gcc/rust/ast/rust-ast-collector.cc
gcc/rust/ast/rust-ast-collector.h
gcc/rust/ast/rust-ast-full-decls.h
gcc/rust/ast/rust-ast-pointer-visitor.cc
gcc/rust/ast/rust-ast-pointer-visitor.h
gcc/rust/ast/rust-ast-visitor.cc
gcc/rust/ast/rust-ast-visitor.h
gcc/rust/ast/rust-ast.cc
gcc/rust/ast/rust-item.h
gcc/rust/expand/rust-cfg-strip.cc
gcc/rust/expand/rust-cfg-strip.h
gcc/rust/expand/rust-derive.h
gcc/rust/expand/rust-expand-visitor.cc
gcc/rust/expand/rust-expand-visitor.h
gcc/rust/hir/rust-ast-lower-base.cc
gcc/rust/hir/rust-ast-lower-base.h
gcc/rust/hir/rust-ast-lower-implitem.cc
gcc/rust/hir/rust-ast-lower-implitem.h
gcc/rust/parse/rust-parse-impl.h
gcc/rust/parse/rust-parse.h
gcc/rust/util/rust-attributes.cc
gcc/rust/util/rust-attributes.h

index 685992c478169e38b099266b9521f255b2bebb49..1060831862a87d148b852e951f7305d992849f6c 100644 (file)
@@ -2171,19 +2171,6 @@ TokenCollector::visit (SelfParam &param)
     }
 }
 
-void
-TokenCollector::visit (TraitItemConst &item)
-{
-  auto id = item.get_identifier ().as_string ();
-  indentation ();
-  push (Rust::Token::make (CONST, item.get_locus ()));
-  push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
-  push (Rust::Token::make (COLON, UNDEF_LOCATION));
-  visit (item.get_type ());
-  push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
-  newline ();
-}
-
 void
 TokenCollector::visit (TraitItemType &item)
 {
index 6f414e86e9961040b865bc6d913219423eb632f7..3e33476a90d8e38a46228a30560a13307adb55f3 100644 (file)
@@ -330,7 +330,6 @@ public:
   void visit (ConstantItem &const_item);
   void visit (StaticItem &static_item);
   void visit (SelfParam &param);
-  void visit (TraitItemConst &item);
   void visit (TraitItemType &item);
   void visit (Trait &trait);
   void visit (InherentImpl &impl);
index b646cdf078ce8311e5ac09ef19491ec85934badd..2903ba732bfd536f6ed12927d2c2f26c1c341922 100644 (file)
@@ -195,7 +195,6 @@ class Enum;
 class Union;
 class ConstantItem;
 class StaticItem;
-class TraitItemConst;
 class TraitItemType;
 class Trait;
 class Impl;
index 8a470a952f828153a61e351dd43bc1f144a8de4b..66aec80e6fa798b7d69d306eabb258bb0532cdfa 100644 (file)
@@ -1003,15 +1003,6 @@ PointerVisitor::visit (AST::StaticItem &static_item)
   reseat (static_item.get_expr_ptr ());
 }
 
-void
-PointerVisitor::visit (AST::TraitItemConst &item)
-{
-  visit_outer_attrs (item);
-  reseat (item.get_type_ptr ());
-  if (item.has_expr ())
-    reseat (item.get_expr_ptr ());
-}
-
 void
 PointerVisitor::visit (AST::TraitItemType &item)
 {
index 1f899ea1b6a564c62a2b9d0110ae7a00b7065e42..8c12b4e3825eecc0ba2be3c95792f4f3bcd472dd 100644 (file)
@@ -165,7 +165,6 @@ public:
   void visit (AST::Union &union_item) override;
   void visit (AST::ConstantItem &const_item) override;
   void visit (AST::StaticItem &static_item) override;
-  void visit (AST::TraitItemConst &item) override;
   void visit (AST::TraitItemType &item) override;
   void visit (AST::Trait &trait) override;
   void visit (AST::InherentImpl &impl) override;
index cf1bbe3b3cf3cf53d02a95e1f5d11d6959d1e9cc..e1bd08689cbcd59696433f942303f7986056e7b4 100644 (file)
@@ -1024,15 +1024,6 @@ DefaultASTVisitor::visit (AST::StaticItem &static_item)
   visit (static_item.get_expr ());
 }
 
-void
-DefaultASTVisitor::visit (AST::TraitItemConst &item)
-{
-  visit_outer_attrs (item);
-  visit (item.get_type ());
-  if (item.has_expr ())
-    visit (item.get_expr ());
-}
-
 void
 DefaultASTVisitor::visit (AST::TraitItemType &item)
 {
index a6b4fe83b0babd07ee52682efc041df8bdc94532..a7a2ac465ce5eb2f3e882de0881525e71aadabba 100644 (file)
@@ -164,7 +164,6 @@ public:
   virtual void visit (Union &union_item) = 0;
   virtual void visit (ConstantItem &const_item) = 0;
   virtual void visit (StaticItem &static_item) = 0;
-  virtual void visit (TraitItemConst &item) = 0;
   virtual void visit (TraitItemType &item) = 0;
   virtual void visit (Trait &trait) = 0;
   virtual void visit (InherentImpl &impl) = 0;
@@ -349,7 +348,6 @@ public:
   virtual void visit (AST::Union &union_item) override;
   virtual void visit (AST::ConstantItem &const_item) override;
   virtual void visit (AST::StaticItem &static_item) override;
-  virtual void visit (AST::TraitItemConst &item) override;
   virtual void visit (AST::TraitItemType &item) override;
   virtual void visit (AST::Trait &trait) override;
   virtual void visit (AST::InherentImpl &impl) override;
index d60b6711f94cab77ecc79949f77bdb9986b478c2..003a6edbc106a8baa032ee4f19f86a1f47664d63 100644 (file)
@@ -652,14 +652,8 @@ ConstantItem::as_string () const
     }
   str += "\n  Type: " + type->as_string ();
 
-  // DEBUG: null pointer check
-  if (const_expr == nullptr)
-    {
-      rust_debug ("something really terrible has gone wrong - null "
-                 "pointer expr in const item.");
-      return "NULL_POINTER_MARK";
-    }
-  str += "\n  Expression: " + const_expr->as_string ();
+  if (has_expr ())
+    str += "\n  Expression: " + const_expr->as_string ();
 
   return str + "\n";
 }
@@ -3049,20 +3043,6 @@ ExternalStaticItem::as_string () const
   return str;
 }
 
-std::string
-TraitItemConst::as_string () const
-{
-  // TODO: rewrite to work with non-linearisable exprs
-  std::string str = append_attributes (outer_attrs, OUTER);
-
-  str += "\nconst " + name.as_string () + " : " + type->as_string ();
-
-  if (has_expression ())
-    str += " = " + expr->as_string ();
-
-  return str;
-}
-
 std::string
 TraitItemType::as_string () const
 {
@@ -4763,12 +4743,6 @@ StaticItem::accept_vis (ASTVisitor &vis)
   vis.visit (*this);
 }
 
-void
-TraitItemConst::accept_vis (ASTVisitor &vis)
-{
-  vis.visit (*this);
-}
-
 void
 TraitItemType::accept_vis (ASTVisitor &vis)
 {
index dbc75a2cbd4c3f46ed45983cb3cc93b874730864..7aea763bd12ee781843234ff469682bc2fa7ae29 100644 (file)
@@ -2541,7 +2541,7 @@ public:
 
   void accept_vis (ASTVisitor &vis) override;
 
-  // Invalid if type or expression are null, so base stripping on that.
+  // Invalid if type and expression are null, so base stripping on that.
   void mark_for_strip () override
   {
     type = nullptr;
@@ -2552,7 +2552,7 @@ public:
     return type == nullptr && const_expr == nullptr;
   }
 
-  bool has_expr () { return const_expr != nullptr; }
+  bool has_expr () const { return const_expr != nullptr; }
 
   // TODO: is this better? Or is a "vis_block" better?
   Expr &get_expr ()
@@ -2719,123 +2719,6 @@ protected:
   }
 };
 
-// Constant item within traits
-class TraitItemConst : public TraitItem
-{
-  std::vector<Attribute> outer_attrs;
-  Identifier name;
-  std::unique_ptr<Type> type;
-
-  // bool has_expression;
-  std::unique_ptr<Expr> expr;
-
-public:
-  // Whether the constant item has an associated expression.
-  bool has_expression () const { return expr != nullptr; }
-
-  TraitItemConst (Identifier name, std::unique_ptr<Type> type,
-                 std::unique_ptr<Expr> expr,
-                 std::vector<Attribute> outer_attrs, location_t locus)
-    : TraitItem (locus), outer_attrs (std::move (outer_attrs)),
-      name (std::move (name)), type (std::move (type)), expr (std::move (expr))
-  {}
-
-  // Copy constructor with clones
-  TraitItemConst (TraitItemConst const &other)
-    : TraitItem (other.locus), outer_attrs (other.outer_attrs),
-      name (other.name)
-  {
-    node_id = other.node_id;
-
-    // guard to prevent null dereference
-    if (other.expr != nullptr)
-      expr = other.expr->clone_expr ();
-
-    // guard to prevent null dereference (only for error state)
-    if (other.type != nullptr)
-      type = other.type->clone_type ();
-  }
-
-  // Overloaded assignment operator to clone
-  TraitItemConst &operator= (TraitItemConst const &other)
-  {
-    TraitItem::operator= (other);
-    outer_attrs = other.outer_attrs;
-    name = other.name;
-    locus = other.locus;
-    node_id = other.node_id;
-
-    // guard to prevent null dereference
-    if (other.expr != nullptr)
-      expr = other.expr->clone_expr ();
-    else
-      expr = nullptr;
-
-    // guard to prevent null dereference (only for error state)
-    if (other.type != nullptr)
-      type = other.type->clone_type ();
-    else
-      type = nullptr;
-
-    return *this;
-  }
-
-  // move constructors
-  TraitItemConst (TraitItemConst &&other) = default;
-  TraitItemConst &operator= (TraitItemConst &&other) = default;
-
-  std::string as_string () const override;
-
-  location_t get_locus () const override { return locus; }
-
-  void accept_vis (ASTVisitor &vis) override;
-
-  // Invalid if type is null, so base stripping on that.
-  void mark_for_strip () override { type = nullptr; }
-  bool is_marked_for_strip () const override { return type == nullptr; }
-
-  // TODO: this mutable getter seems really dodgy. Think up better way.
-  std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
-  const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
-
-  bool has_expr () const { return expr != nullptr; }
-
-  // TODO: is this better? Or is a "vis_block" better?
-  Expr &get_expr ()
-  {
-    rust_assert (has_expr ());
-    return *expr;
-  }
-
-  std::unique_ptr<Expr> &get_expr_ptr ()
-  {
-    rust_assert (has_expr ());
-    return expr;
-  }
-
-  // TODO: is this better? Or is a "vis_block" better?
-  Type &get_type ()
-  {
-    rust_assert (type != nullptr);
-    return *type;
-  }
-
-  std::unique_ptr<Type> &get_type_ptr ()
-  {
-    rust_assert (type != nullptr);
-    return type;
-  }
-
-  Identifier get_identifier () const { return name; }
-
-protected:
-  // Clone function implementation as (not pure) virtual method
-  TraitItemConst *clone_associated_item_impl () const override
-  {
-    return new TraitItemConst (*this);
-  }
-};
-
 // Type items within traits
 class TraitItemType : public TraitItem
 {
index d45f7558948b55e5bfc524cf12e8a0632a942dac..3bc8461c4ffb8dfe4bf46a590490cc5a14098ab6 100644 (file)
@@ -2068,38 +2068,6 @@ CfgStrip::visit (AST::StaticItem &static_item)
                   "attributes not allowed");
 }
 
-void
-CfgStrip::visit (AST::TraitItemConst &item)
-{
-  // initial test based on outer attrs
-  expand_cfg_attrs (item.get_outer_attrs ());
-  if (fails_cfg_with_expand (item.get_outer_attrs ()))
-    {
-      item.mark_for_strip ();
-      return;
-    }
-
-  AST::DefaultASTVisitor::visit (item);
-
-  // strip any sub-types
-  auto &type = item.get_type ();
-
-  if (type.is_marked_for_strip ())
-    rust_error_at (type.get_locus (), "cannot strip type in this position");
-
-  /* strip any internal sub-expressions - expression itself isn't
-   * allowed to have external attributes in this position so can't be
-   * stripped */
-  if (item.has_expression ())
-    {
-      auto &expr = item.get_expr ();
-      if (expr.is_marked_for_strip ())
-       rust_error_at (expr.get_locus (),
-                      "cannot strip expression in this position - outer "
-                      "attributes not allowed");
-    }
-}
-
 void
 CfgStrip::visit (AST::TraitItemType &item)
 {
index 9d6a6d83ad42220d21730ff8eb7b9766ebfab797..42cd26688643d2c7a01fab23fc38dfb14f9d873c 100644 (file)
@@ -156,7 +156,6 @@ public:
   void visit (AST::Union &union_item) override;
   void visit (AST::ConstantItem &const_item) override;
   void visit (AST::StaticItem &static_item) override;
-  void visit (AST::TraitItemConst &item) override;
   void visit (AST::TraitItemType &item) override;
   void visit (AST::Trait &trait) override;
   void visit (AST::InherentImpl &impl) override;
index 0e066cab5396e7c907b7811f5e0f1905f90fd3db..d28bba9fab0ad7ab2a9894aee6cea56054030438 100644 (file)
@@ -192,7 +192,6 @@ private:
   virtual void visit (EnumItemDiscriminant &item) override final{};
   virtual void visit (ConstantItem &const_item) override final{};
   virtual void visit (StaticItem &static_item) override final{};
-  virtual void visit (TraitItemConst &item) override final{};
   virtual void visit (TraitItemType &item) override final{};
   virtual void visit (Trait &trait) override final{};
   virtual void visit (InherentImpl &impl) override final{};
index da9b39cbe32c5f0721e5bccc8362ccfb6cd69ade..590b95e235fbce1b1df958f7c22f42c0d2b3fe06 100644 (file)
@@ -907,15 +907,6 @@ ExpandVisitor::visit (AST::StaticItem &static_item)
   maybe_expand_expr (static_item.get_expr_ptr ());
 }
 
-void
-ExpandVisitor::visit (AST::TraitItemConst &const_item)
-{
-  maybe_expand_type (const_item.get_type_ptr ());
-
-  if (const_item.has_expr ())
-    maybe_expand_expr (const_item.get_expr_ptr ());
-}
-
 void
 ExpandVisitor::visit (AST::Trait &trait)
 {
index 677adeae86fd19da8659c2bc08b0449d3c0d04af..d0ed8439c12d56724f7f73c0f29c92d0eaf35247 100644 (file)
@@ -257,7 +257,6 @@ public:
   void visit (AST::Union &union_item) override;
   void visit (AST::ConstantItem &const_item) override;
   void visit (AST::StaticItem &static_item) override;
-  void visit (AST::TraitItemConst &item) override;
   void visit (AST::Trait &trait) override;
   void visit (AST::InherentImpl &impl) override;
   void visit (AST::TraitImpl &impl) override;
index f3faee652ba76a3edb2d276c22645e5941af7181..1c8e5b6d2c0e2c70db17f96c33ec9446bf0fa2f7 100644 (file)
@@ -372,9 +372,6 @@ void
 ASTLoweringBase::visit (AST::StaticItem &)
 {}
 void
-ASTLoweringBase::visit (AST::TraitItemConst &)
-{}
-void
 ASTLoweringBase::visit (AST::TraitItemType &)
 {}
 void
index e720fc9b210351d1e08f3ba9fa8a5741377aeff2..933f77bb7dc9647c3eaa6e6af8654666355a50af 100644 (file)
@@ -189,7 +189,6 @@ public:
   virtual void visit (AST::Union &union_item) override;
   virtual void visit (AST::ConstantItem &const_item) override;
   virtual void visit (AST::StaticItem &static_item) override;
-  virtual void visit (AST::TraitItemConst &item) override;
   virtual void visit (AST::TraitItemType &item) override;
   virtual void visit (AST::Trait &trait) override;
   virtual void visit (AST::InherentImpl &impl) override;
index 9b25873af8220de85cc14c1d05db1c0878e1034f..8fd9d167cea30dc5c2e499787fe34200281cca2f 100644 (file)
@@ -318,10 +318,10 @@ ASTLowerTraitItem::visit (AST::Function &func)
 }
 
 void
-ASTLowerTraitItem::visit (AST::TraitItemConst &constant)
+ASTLowerTraitItem::visit (AST::ConstantItem &constant)
 {
   HIR::Type *type = ASTLoweringType::translate (constant.get_type ());
-  HIR::Expr *expr = constant.has_expression ()
+  HIR::Expr *expr = constant.has_expr ()
                      ? ASTLoweringExpr::translate (constant.get_expr ())
                      : nullptr;
 
index 8331bba075ac5b87453efd37db8ce4ce10e920ee..dfcf567f2f5a811f5228660be790335f3b34bab2 100644 (file)
@@ -49,7 +49,7 @@ class ASTLowerTraitItem : public ASTLoweringBase
 public:
   static HIR::TraitItem *translate (AST::AssociatedItem &item);
   void visit (AST::Function &func) override;
-  void visit (AST::TraitItemConst &constant) override;
+  void visit (AST::ConstantItem &constant) override;
   void visit (AST::TraitItemType &type) override;
 
 private:
index bd12c384c3ac1ac2857fafc3ef92f0b1d1c9c5b9..4a6717a3bf90830f2063e79360f71abdccd8ba50 100644 (file)
@@ -5219,7 +5219,7 @@ Parser<ManagedTokenSource>::parse_trait_type (AST::AttrVec outer_attrs,
 
 // Parses a constant trait item.
 template <typename ManagedTokenSource>
-std::unique_ptr<AST::TraitItemConst>
+std::unique_ptr<AST::ConstantItem>
 Parser<ManagedTokenSource>::parse_trait_const (AST::AttrVec outer_attrs)
 {
   location_t locus = lexer.peek_token ()->get_locus ();
@@ -5257,10 +5257,9 @@ Parser<ManagedTokenSource>::parse_trait_const (AST::AttrVec outer_attrs)
       return nullptr;
     }
 
-  return std::unique_ptr<AST::TraitItemConst> (
-    new AST::TraitItemConst (std::move (ident), std::move (type),
-                            std::move (const_body), std::move (outer_attrs),
-                            locus));
+  return std::unique_ptr<AST::ConstantItem> (new AST::ConstantItem (
+    std::move (ident), AST::Visibility::create_private (), std::move (type),
+    std::move (const_body), std::move (outer_attrs), locus));
 }
 
 /* Parses a struct "impl" item (both inherent impl and trait impl can be
index 228b9fecd98fa1e85f469909aa023ef8bb42690b..7b4046365ddae8721cedc268351733449d7e606e 100644 (file)
@@ -372,7 +372,7 @@ private:
                                           AST::AttrVec outer_attrs);
   std::unique_ptr<AST::TraitItemType>
   parse_trait_type (AST::AttrVec outer_attrs, AST::Visibility);
-  std::unique_ptr<AST::TraitItemConst>
+  std::unique_ptr<AST::ConstantItem>
   parse_trait_const (AST::AttrVec outer_attrs);
 
   tl::expected<std::unique_ptr<AST::Param>, ParseSelfError> parse_self_param ();
index c305877388d34926b4fc0c3cdcf3189be4e8f629..716af3af699a21be371dd249db527c6e2f7c9d97 100644 (file)
@@ -798,10 +798,6 @@ AttributeChecker::visit (AST::StaticItem &item)
   check_proc_macro_non_function (item.get_outer_attrs ());
 }
 
-void
-AttributeChecker::visit (AST::TraitItemConst &)
-{}
-
 void
 AttributeChecker::visit (AST::TraitItemType &)
 {}
index 45addf30508772da1153e0c13b26a61fec391234..22670991beb79c8fd43340bb83ee818c99ff8ba1 100644 (file)
@@ -205,7 +205,6 @@ private:
   void visit (AST::Union &union_item) override;
   void visit (AST::ConstantItem &const_item) override;
   void visit (AST::StaticItem &static_item) override;
-  void visit (AST::TraitItemConst &item) override;
   void visit (AST::TraitItemType &item) override;
   void visit (AST::Trait &trait) override;
   void visit (AST::InherentImpl &impl) override;