]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add exclusive_range_pattern feature gate
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Tue, 21 May 2024 16:09:14 +0000 (18:09 +0200)
committerP-E-P <32375388+P-E-P@users.noreply.github.com>
Wed, 12 Jun 2024 11:11:56 +0000 (11:11 +0000)
This syntax is experimental and shall be explicitely enabled in the crate
attributes as it cannot be used in stable rust.

gcc/rust/ChangeLog:

* checks/errors/rust-feature-gate.cc (FeatureGate::visit): Gate the
excluded pattern.
* checks/errors/rust-feature-gate.h: Update the function prototype
and delete two empty implementations in order to use default visitor
behavior.
* checks/errors/rust-feature.cc (Feature::create): Add the new
exclusive range pattern feature gate.
* checks/errors/rust-feature.h: Add new feature enum variant for
exclusive range patterns.
* parse/rust-parse-impl.h (Parser::parse_pattern_no_alt): Forward the
token location to the AST.
(Parser::parse_ident_leading_pattern): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/checks/errors/rust-feature-gate.cc
gcc/rust/checks/errors/rust-feature-gate.h
gcc/rust/checks/errors/rust-feature.cc
gcc/rust/checks/errors/rust-feature.h
gcc/rust/parse/rust-parse-impl.h

index d5b70635857f9d93328443323ac139ad16d200be..0fe2edbce4fcb79c81065f17ce75bde3e8d4777d 100644 (file)
@@ -209,4 +209,12 @@ FeatureGate::visit (AST::BorrowExpr &expr)
          "raw address of syntax is experimental");
 }
 
+void
+FeatureGate::visit (AST::RangePattern &pattern)
+{
+  if (pattern.get_range_kind () == AST::RangeKind::EXCLUDED)
+    gate (Feature::Name::EXCLUSIVE_RANGE_PATTERN, pattern.get_locus (),
+         "exclusive range pattern syntax is experimental");
+}
+
 } // namespace Rust
index 0d53b40c151be34c33fe847b9bd8e09f0134a3db..5a063ea5c8a16067250888e98d14ec37876cb16b 100644 (file)
@@ -99,9 +99,7 @@ public:
   void visit (AST::ForLoopExpr &expr) override {}
   void visit (AST::IfExpr &expr) override {}
   void visit (AST::IfExprConseqElse &expr) override {}
-  void visit (AST::IfLetExpr &expr) override {}
   void visit (AST::IfLetExprConseqElse &expr) override {}
-  void visit (AST::MatchExpr &expr) override {}
   void visit (AST::AwaitExpr &expr) override {}
   void visit (AST::AsyncBlockExpr &expr) override {}
   void visit (AST::TypeParam &param) override;
@@ -150,7 +148,7 @@ public:
   void visit (AST::RangePatternBoundLiteral &bound) override {}
   void visit (AST::RangePatternBoundPath &bound) override {}
   void visit (AST::RangePatternBoundQualPath &bound) override {}
-  void visit (AST::RangePattern &pattern) override {}
+  void visit (AST::RangePattern &pattern) override;
   void visit (AST::ReferencePattern &pattern) override {}
   void visit (AST::StructPatternFieldTuplePat &field) override {}
   void visit (AST::StructPatternFieldIdentPat &field) override {}
index cb2b42cafaf029b566243d7e0d82dabf94cdf4b5..cd2df0f96f6ad7722c432a1c5891fd87ccd976a4 100644 (file)
@@ -54,6 +54,10 @@ Feature::create (Feature::Name name)
     case Feature::Name::RAW_REF_OP:
       return Feature (Feature::Name::RAW_REF_OP, Feature::State::ACTIVE,
                      "raw_ref_op", "1.41.0", 64490, tl::nullopt, "");
+    case Feature::Name::EXCLUSIVE_RANGE_PATTERN:
+      return Feature (Feature::Name::EXCLUSIVE_RANGE_PATTERN,
+                     Feature::State::ACTIVE, "exclusive_range_pattern",
+                     "1.11.0", 37854, tl::nullopt, "");
     default:
       rust_unreachable ();
     }
@@ -74,6 +78,7 @@ const std::map<std::string, Feature::Name> Feature::name_hash_map = {
   {"box_syntax", Feature::Name::BOX_SYNTAX},
   {"dropck_eyepatch", Feature::Name::DROPCK_EYEPATCH},
   {"raw_ref_op", Feature::Name::RAW_REF_OP},
+  {"exclusive_range_pattern", Feature::Name::EXCLUSIVE_RANGE_PATTERN},
 }; // namespace Rust
 
 tl::optional<Feature::Name>
index 5a1819912df2cd79587dbe0f7587e365597af2cc..89e58cf0ed1e41b2f30591aa3aa3d039d1b8ea56 100644 (file)
@@ -49,6 +49,7 @@ public:
     BOX_SYNTAX,
     DROPCK_EYEPATCH,
     RAW_REF_OP,
+    EXCLUSIVE_RANGE_PATTERN,
   };
 
   const std::string &as_string () { return m_name_str; }
index db5c3c00b596008f701340197a1dd67a2f7abcfd..0a20bf632fa7d7c0fb69d24dc75ce5583863678a 100644 (file)
@@ -10586,7 +10586,7 @@ Parser<ManagedTokenSource>::parse_pattern_no_alt ()
              return std::unique_ptr<AST::RangePattern> (
                new AST::RangePattern (std::move (lower_bound),
                                       std::move (upper_bound), kind,
-                                      UNKNOWN_LOCATION));
+                                      next->get_locus ()));
            }
          case EXCLAM:
            return parse_macro_invocation_partial (std::move (path),
@@ -11112,7 +11112,7 @@ Parser<ManagedTokenSource>::parse_ident_leading_pattern ()
        return std::unique_ptr<AST::RangePattern> (
          new AST::RangePattern (std::move (lower_bound),
                                 std::move (upper_bound), kind,
-                                UNKNOWN_LOCATION));
+                                t->get_locus ()));
       }
       case PATTERN_BIND: {
        // only allow on single-segment paths