]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Separate strip information from internal state
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Mon, 25 Aug 2025 15:16:24 +0000 (17:16 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 30 Oct 2025 19:58:47 +0000 (20:58 +0100)
Marking a TupleIndexExpr for strip makes it invalid for a generic visitor

gcc/rust/ChangeLog:

* ast/rust-expr.h (class TupleIndexExpr): Store strip information.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/ast/rust-expr.h

index 94d9ba13f1dfcd0b88f8cfb149a6cc5fd8a03003..189fb9afc49a64c16be6626f4fe1a2addd75e382 100644 (file)
@@ -1611,6 +1611,7 @@ class TupleIndexExpr : public ExprWithoutBlock
   TupleIndex tuple_index;
 
   location_t locus;
+  bool to_strip;
 
   // i.e. pair.0
 
@@ -1622,13 +1623,15 @@ public:
   TupleIndexExpr (std::unique_ptr<Expr> tuple_expr, TupleIndex index,
                  std::vector<Attribute> outer_attribs, location_t locus)
     : outer_attrs (std::move (outer_attribs)),
-      tuple_expr (std::move (tuple_expr)), tuple_index (index), locus (locus)
+      tuple_expr (std::move (tuple_expr)), tuple_index (index), locus (locus),
+      to_strip (false)
   {}
 
   // Copy constructor requires a clone for tuple_expr
   TupleIndexExpr (TupleIndexExpr const &other)
     : ExprWithoutBlock (other), outer_attrs (other.outer_attrs),
-      tuple_index (other.tuple_index), locus (other.locus)
+      tuple_index (other.tuple_index), locus (other.locus),
+      to_strip (other.to_strip)
   {
     // guard to prevent null dereference (only required if error state)
     if (other.tuple_expr != nullptr)
@@ -1642,6 +1645,7 @@ public:
     tuple_index = other.tuple_index;
     locus = other.locus;
     outer_attrs = other.outer_attrs;
+    to_strip = other.to_strip;
 
     // guard to prevent null dereference (only required if error state)
     if (other.tuple_expr != nullptr)
@@ -1661,8 +1665,8 @@ public:
   void accept_vis (ASTVisitor &vis) override;
 
   // Invalid if tuple expr is null, so base stripping on that.
-  void mark_for_strip () override { tuple_expr = nullptr; }
-  bool is_marked_for_strip () const override { return tuple_expr == nullptr; }
+  void mark_for_strip () override { to_strip = true; }
+  bool is_marked_for_strip () const override { return to_strip; }
 
   // TODO: is this better? Or is a "vis_block" better?
   Expr &get_tuple_expr ()