]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Remove AttrInputMacro attribute input kind
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wed, 25 Mar 2026 15:51:42 +0000 (16:51 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 14 Apr 2026 21:48:43 +0000 (23:48 +0200)
This attribute kind is being replaced with AttrInputExpr attributes.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Remove
AttrInputMacro handling.
* ast/rust-ast-collector.h: Remove function prototype.
* ast/rust-ast-full-decls.h (class AttrInputMacro): Remove forward
declaration.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Remove function.
* ast/rust-ast-visitor.h: Remove function prototypes.
* ast/rust-ast.cc (Attribute::get_traits_to_derive): Remove handling of
macros.
(AttrInputMacro::as_string): Remove function.
(AttrInputMacro::AttrInputMacro): Likewise.
(AttrInputMacro::operator=): Likewise.
(AttrInputMacro::accept_vis): Likewise.
* ast/rust-ast.h: Remove MACRO kind.
* ast/rust-expr.h (class AttrInputMacro): Add getter for expr pointer.
Remove AttrInputMacro class.
* expand/rust-derive.h: Remove function prototype.
* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Change function
to AttrInputExpr.
* expand/rust-expand-visitor.h: Update prototype.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Remove function.
* hir/rust-ast-lower-base.h: Remove function prototype.
* parse/rust-parse-impl-attribute.hxx: Parse the attribute content as
AttrInputExpr instead.
* util/rust-attributes.cc (check_doc_attribute): Remove MACRO kind
handling.
(check_export_name_attribute): Remove switch and only handle literals.
(AttributeChecker::visit): Remove function.
* util/rust-attributes.h: Remove function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
16 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-visitor.cc
gcc/rust/ast/rust-ast-visitor.h
gcc/rust/ast/rust-ast.cc
gcc/rust/ast/rust-ast.h
gcc/rust/ast/rust-expr.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/parse/rust-parse-impl-attribute.hxx
gcc/rust/util/rust-attributes.cc
gcc/rust/util/rust-attributes.h

index ba4b8aa0b3df60e1de9363d7d67caa95e0005ac8..e6072a80bcaa473f6e2260fab1d1d2bd14f05fa8 100644 (file)
@@ -176,11 +176,6 @@ TokenCollector::visit (Attribute &attrib)
                static_cast<AttrInputLiteral &> (attrib.get_attr_input ()));
              break;
            }
-         case AST::AttrInput::AttrInputType::MACRO:
-           {
-             visit (static_cast<AttrInputMacro &> (attrib.get_attr_input ()));
-             break;
-           }
          case AST::AttrInput::AttrInputType::EXPR:
            {
              visit (static_cast<AttrInputExpr &> (attrib.get_attr_input ()));
@@ -903,15 +898,6 @@ TokenCollector::visit (AttrInputLiteral &literal)
   });
 }
 
-void
-TokenCollector::visit (AttrInputMacro &macro)
-{
-  describe_node (std::string ("AttrInputMacro"), [this, &macro] () {
-    push (Rust::Token::make (EQUAL, UNDEF_LOCATION));
-    visit (macro.get_macro ());
-  });
-}
-
 void
 TokenCollector::visit (AttrInputExpr &attr)
 {
index af60e9d1f4185a94aacc61db11463d9febb230d1..6f03f5758629a8c1f760780730dddde5db6b8540 100644 (file)
@@ -291,7 +291,6 @@ public:
   // rust-expr.h
   void visit (LiteralExpr &expr);
   void visit (AttrInputLiteral &attr_input);
-  void visit (AttrInputMacro &attr_input);
   void visit (AttrInputExpr &attr_input);
   void visit (MetaItemLitExpr &meta_item);
   void visit (MetaItemPathExpr &meta_item);
index f90b93145e84c269fe99ae0b8cdee7e30b1d2f44..21bb686d4e72782e44303bd864f7e1eb72f01046 100644 (file)
@@ -77,7 +77,6 @@ class QualifiedPathInType;
 class ExprWithBlock;
 class LiteralExpr;
 class AttrInputLiteral;
-class AttrInputMacro;
 class MetaItemLitExpr;
 class MetaItemPathExpr;
 class OperatorExpr;
index 66054c7afbdb424d1231214e364e1626fbebfbc9..f7d33ffc44e53538f6f2e976c71e50eeca379d4c 100644 (file)
@@ -208,12 +208,6 @@ DefaultASTVisitor::visit (AST::AttrInputLiteral &attr_input)
   visit (attr_input.get_literal ());
 }
 
-void
-DefaultASTVisitor::visit (AST::AttrInputMacro &attr_input)
-{
-  visit (attr_input.get_macro ());
-}
-
 void
 DefaultASTVisitor::visit (AST::AttrInputExpr &attr_input)
 {
index 0ad69a453ee15fd709b4b640f82e205b3647ad31..c3ec4362b50e22f6353058f9bbf7cd1b985525ee 100644 (file)
@@ -72,7 +72,6 @@ public:
   // rust-expr.h
   virtual void visit (LiteralExpr &expr) = 0;
   virtual void visit (AttrInputLiteral &attr_input) = 0;
-  virtual void visit (AttrInputMacro &attr_input) = 0;
   virtual void visit (AttrInputExpr &attr_input) = 0;
   virtual void visit (MetaItemLitExpr &meta_item) = 0;
   virtual void visit (MetaItemPathExpr &meta_item) = 0;
@@ -270,7 +269,6 @@ public:
   virtual void visit (AST::LiteralExpr &expr) override;
   virtual void visit (AST::AttrInputLiteral &attr_input) override;
   virtual void visit (AST::AttrInputExpr &attr_input) override;
-  virtual void visit (AST::AttrInputMacro &attr_input) override;
   virtual void visit (AST::MetaItemLitExpr &meta_item) override;
   virtual void visit (AST::MetaItemPathExpr &meta_item) override;
   virtual void visit (AST::BorrowExpr &expr) override;
index 004e276037290176fd89dacb80cc82d77f5a7c39..e8897696a475e35fd44a7d7a39bc6b4ea7626ecb 100644 (file)
@@ -344,7 +344,6 @@ Attribute::get_traits_to_derive ()
       break;
     case AST::AttrInput::TOKEN_TREE:
     case AST::AttrInput::LITERAL:
-    case AST::AttrInput::MACRO:
     case AST::AttrInput::EXPR:
       rust_unreachable ();
       break;
@@ -3377,12 +3376,6 @@ AttrInputExpr::accept_vis (ASTVisitor &vis)
   vis.visit (*this);
 }
 
-std::string
-AttrInputMacro::as_string () const
-{
-  return " = " + macro->as_string ();
-}
-
 /* Override that calls the function recursively on all items contained within
  * the module. */
 void
@@ -4314,19 +4307,6 @@ BlockExpr::normalize_tail_expr ()
     }
 }
 
-// needed here because "rust-expr.h" doesn't include "rust-macro.h"
-AttrInputMacro::AttrInputMacro (const AttrInputMacro &oth)
-  : macro (oth.macro->clone_macro_invocation_impl ())
-{}
-
-AttrInputMacro &
-AttrInputMacro::operator= (const AttrInputMacro &oth)
-{
-  macro = std::unique_ptr<MacroInvocation> (
-    oth.macro->clone_macro_invocation_impl ());
-  return *this;
-}
-
 /* Visitor implementations - these are short but inlining can't happen anyway
  * due to virtual functions and I didn't want to make the ast header includes
  * any longer than they already are. */
@@ -4373,12 +4353,6 @@ AttrInputLiteral::accept_vis (ASTVisitor &vis)
   vis.visit (*this);
 }
 
-void
-AttrInputMacro::accept_vis (ASTVisitor &vis)
-{
-  vis.visit (*this);
-}
-
 void
 MetaItemLitExpr::accept_vis (ASTVisitor &vis)
 {
index b82a8cbd7a7aca9d836ca54b16977d1109e3ef94..4a1974d4d9dcdc0c8a4f169de360e856a4739422 100644 (file)
@@ -726,7 +726,6 @@ public:
   {
     EXPR,
     LITERAL,
-    MACRO,
     META_ITEM,
     TOKEN_TREE,
   };
index 1ea5c3a3004814d0d5511053f455db1f78a37e9e..90e4daec413c28be4389a431a759f0ca60c3f4ac 100644 (file)
@@ -204,58 +204,14 @@ public:
 
   Expr &get_expr () { return *expr; }
 
+  std::unique_ptr<Expr> &get_expr_ptr () { return expr; }
+
   AttrInputExpr *clone_attr_input_impl () const override
   {
     return new AttrInputExpr (*this);
   }
 };
 
-// Like an AttrInputLiteral, but stores a MacroInvocation
-class AttrInputMacro : public AttrInput
-{
-  std::unique_ptr<MacroInvocation> macro;
-
-public:
-  AttrInputMacro (std::unique_ptr<MacroInvocation> macro)
-    : macro (std::move (macro))
-  {}
-
-  AttrInputMacro (const AttrInputMacro &oth);
-
-  AttrInputMacro (AttrInputMacro &&oth) : macro (std::move (oth.macro)) {}
-
-  AttrInputMacro &operator= (const AttrInputMacro &oth);
-
-  AttrInputMacro &operator= (AttrInputMacro &&oth)
-  {
-    macro = std::move (oth.macro);
-    return *this;
-  }
-
-  std::string as_string () const override;
-
-  void accept_vis (ASTVisitor &vis) override;
-
-  // assuming this can't be a cfg predicate
-  bool check_cfg_predicate (const Session &) const override { return false; }
-
-  // assuming this is like AttrInputLiteral
-  bool is_meta_item () const override { return false; }
-
-  std::unique_ptr<MacroInvocation> &get_macro () { return macro; }
-
-  AttrInputType get_attr_input_type () const final override
-  {
-    return AttrInput::AttrInputType::MACRO;
-  }
-
-protected:
-  AttrInputMacro *clone_attr_input_impl () const override
-  {
-    return new AttrInputMacro (*this);
-  }
-};
-
 /* literal expr only meta item inner - TODO possibly replace with inheritance of
  * LiteralExpr itself? */
 class MetaItemLitExpr : public MetaItemInner
index 1f0662ab2cb5c10d18f40c7bd95eb22e575a42cd..7774c6bac83ad96672dcd2dfcbbe65d4488be933 100644 (file)
@@ -104,7 +104,6 @@ private:
   virtual void visit (Token &tok) override final{};
   virtual void visit (DelimTokenTree &delim_tok_tree) override final{};
   virtual void visit (AttrInputMetaItemContainer &input) override final{};
-  virtual void visit (AttrInputMacro &expr) override final{};
   virtual void visit (AttrInputExpr &expr) override final{};
   virtual void visit (IdentifierExpr &ident_expr) override final{};
   virtual void visit (Lifetime &lifetime) override final{};
index 690c74bee285fbe3c39af98560cb669415ccc2f3..c124f9ab9375685ab309f1f0c9b5849c8e180aad 100644 (file)
@@ -584,9 +584,9 @@ ExpandVisitor::visit (AST::AttrInputLiteral &)
 {}
 
 void
-ExpandVisitor::visit (AST::AttrInputMacro &macro)
+ExpandVisitor::visit (AST::AttrInputExpr &attr_input)
 {
-  rust_sorry_at (UNDEF_LOCATION, "macros in attributes not supported");
+  reseat (attr_input.get_expr_ptr ());
 }
 
 void
index 2a3938afe7331b8dc58ade5a6f99415bd6372671..d6e48e0757ff56285a491bfab745a3f2446462b6 100644 (file)
@@ -231,7 +231,7 @@ public:
 
   void visit (AST::LiteralExpr &expr) override;
   void visit (AST::AttrInputLiteral &) override;
-  void visit (AST::AttrInputMacro &) override;
+  void visit (AST::AttrInputExpr &) override;
   void visit (AST::MetaItemLitExpr &) override;
   void visit (AST::MetaItemPathExpr &) override;
   void visit (AST::StructExprStruct &expr) override;
index 1fc73152a00743cd3ac28dc0f812352faed7c01a..8b2fa5a2f507dae4b7a124c679979072c35862ed 100644 (file)
@@ -140,9 +140,6 @@ ASTLoweringBase::visit (AST::LiteralExpr &)
 void
 ASTLoweringBase::visit (AST::AttrInputLiteral &)
 {}
-void
-ASTLoweringBase::visit (AST::AttrInputMacro &)
-{}
 
 void
 ASTLoweringBase::visit (AST::AttrInputExpr &)
index 42675c281cfa229b66462e3983f182141b64e408..ff1e51eb21b8f2ec421d44fd5c659bc79cf268b2 100644 (file)
@@ -106,7 +106,6 @@ public:
   virtual void visit (AST::LiteralExpr &expr) override;
   virtual void visit (AST::AttrInputLiteral &attr_input) override;
   virtual void visit (AST::AttrInputExpr &attr_input) override;
-  virtual void visit (AST::AttrInputMacro &attr_input) override;
   virtual void visit (AST::MetaItemLitExpr &meta_item) override;
   virtual void visit (AST::MetaItemPathExpr &meta_item) override;
   virtual void visit (AST::BorrowExpr &expr) override;
index 5c7bd99bf3eac734ee9e933cbb02e7fe432eb469..3db1cd5c69e4f94db722f0f52687aafeed392cbd 100644 (file)
@@ -314,8 +314,7 @@ Parser<ManagedTokenSource>::parse_attr_input ()
            if (!invoke)
              return Parse::Error::AttrInput::make_bad_macro_invocation ();
 
-           return std::unique_ptr<AST::AttrInput> (
-             new AST::AttrInputMacro (std::move (invoke)));
+           return std::make_unique<AST::AttrInputExpr> (std::move (invoke));
          }
 
        AST::Literal::LitType lit_type = AST::Literal::STRING;
index 7c137d06b98e65a97e120d04eec38568674297d5..3b6587ffdaa191bfbea8f5c5b2c7f4d04977c1dd 100644 (file)
@@ -271,7 +271,6 @@ check_doc_attribute (const AST::Attribute &attribute)
   switch (attribute.get_attr_input ().get_attr_input_type ())
     {
     case AST::AttrInput::LITERAL:
-    case AST::AttrInput::MACRO:
     case AST::AttrInput::META_ITEM:
     case AST::AttrInput::EXPR:
       break;
@@ -507,38 +506,26 @@ check_export_name_attribute (const AST::Attribute &attribute)
       return;
     }
 
-  // We don't support the whole extended_key_value_attributes feature, we only
-  // support a subset for macros. We need to emit an error message when the
-  // attribute does not contain a macro or a string literal.
   if (attribute.has_attr_input ())
     {
       auto &attr_input = attribute.get_attr_input ();
-      switch (attr_input.get_attr_input_type ())
+      if (attr_input.get_attr_input_type ()
+         == AST::AttrInput::AttrInputType::LITERAL)
        {
-       case AST::AttrInput::AttrInputType::LITERAL:
-         {
-           auto &literal_expr
-             = static_cast<AST::AttrInputLiteral &> (attr_input)
-                 .get_literal ();
-           auto lit_type = literal_expr.get_lit_type ();
-           switch (lit_type)
-             {
-             case AST::Literal::LitType::STRING:
-             case AST::Literal::LitType::RAW_STRING:
-             case AST::Literal::LitType::BYTE_STRING:
-               return;
-             default:
-               break;
-             }
-           break;
-         }
-       case AST::AttrInput::AttrInputType::MACRO:
-         return;
-       default:
-         break;
+         auto &literal_expr
+           = static_cast<AST::AttrInputLiteral &> (attr_input).get_literal ();
+         auto lit_type = literal_expr.get_lit_type ();
+         switch (lit_type)
+           {
+           case AST::Literal::LitType::STRING:
+           case AST::Literal::LitType::RAW_STRING:
+           case AST::Literal::LitType::BYTE_STRING:
+             return;
+           default:
+             break;
+           }
        }
     }
-  rust_error_at (attribute.get_locus (), "attribute must be a string literal");
 }
 
 static void
@@ -642,10 +629,6 @@ void
 AttributeChecker::visit (AST::AttrInputLiteral &)
 {}
 
-void
-AttributeChecker::visit (AST::AttrInputMacro &)
-{}
-
 void
 AttributeChecker::visit (AST::MetaItemLitExpr &)
 {}
index f63f902363c3f8e661883aa938be4308c2164b7e..4bac820120c8f775306c353d0c58b204e9364425 100644 (file)
@@ -129,7 +129,6 @@ private:
   // rust-expr.h
   void visit (AST::LiteralExpr &expr) override;
   void visit (AST::AttrInputLiteral &attr_input) override;
-  void visit (AST::AttrInputMacro &attr_input) override;
   void visit (AST::MetaItemLitExpr &meta_item) override;
   void visit (AST::MetaItemPathExpr &meta_item) override;
   void visit (AST::BorrowExpr &expr) override;