From: Pierre-Emmanuel Patry <pierre-emmanuel.pa...@embecosm.com>

Raw ref operators are still experimental and shall not slip within
stable rust, they should therefore be feature gated.

gcc/rust/ChangeLog:

        * checks/errors/rust-feature-gate.cc (FeatureGate::visit): Gate raw
        borrow.
        * checks/errors/rust-feature-gate.h: Update function prototype.
        * checks/errors/rust-feature.cc: Add raw_ref_op gate.
        * checks/errors/rust-feature.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.pa...@embecosm.com>
---
 gcc/rust/checks/errors/rust-feature-gate.cc | 8 ++++++++
 gcc/rust/checks/errors/rust-feature-gate.h  | 2 +-
 gcc/rust/checks/errors/rust-feature.cc      | 4 ++++
 gcc/rust/checks/errors/rust-feature.h       | 1 +
 4 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc 
b/gcc/rust/checks/errors/rust-feature-gate.cc
index 16c5ecee6cb..8f9e991237b 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/rust-feature-gate.cc
@@ -201,4 +201,12 @@ FeatureGate::visit (AST::TypeParam &param)
   AST::DefaultASTVisitor::visit (param);
 }
 
+void
+FeatureGate::visit (AST::BorrowExpr &expr)
+{
+  if (expr.is_raw_borrow ())
+    gate (Feature::Name::RAW_REF_OP, expr.get_locus (),
+         "raw address of syntax is experimental");
+}
+
 } // namespace Rust
diff --git a/gcc/rust/checks/errors/rust-feature-gate.h 
b/gcc/rust/checks/errors/rust-feature-gate.h
index 5ead1103086..a31405e7d63 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/rust-feature-gate.h
@@ -54,7 +54,7 @@ public:
   void visit (AST::AttrInputMacro &attr_input) override {}
   void visit (AST::MetaItemLitExpr &meta_item) override {}
   void visit (AST::MetaItemPathLit &meta_item) override {}
-  void visit (AST::BorrowExpr &expr) override {}
+  void visit (AST::BorrowExpr &expr) override;
   void visit (AST::DereferenceExpr &expr) override {}
   void visit (AST::ErrorPropagationExpr &expr) override {}
   void visit (AST::NegationExpr &expr) override {}
diff --git a/gcc/rust/checks/errors/rust-feature.cc 
b/gcc/rust/checks/errors/rust-feature.cc
index b9a648e62ef..bc8aa915064 100644
--- a/gcc/rust/checks/errors/rust-feature.cc
+++ b/gcc/rust/checks/errors/rust-feature.cc
@@ -51,6 +51,9 @@ Feature::create (Feature::Name name)
     case Feature::Name::DROPCK_EYEPATCH:
       return Feature (Feature::Name::DROPCK_EYEPATCH, Feature::State::ACTIVE,
                      "dropck_eyepatch", "1.10.0", 34761, tl::nullopt, "");
+    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, "");
     default:
       rust_unreachable ();
     }
@@ -70,6 +73,7 @@ const std::map<std::string, Feature::Name> 
Feature::name_hash_map = {
   {"no_core", Feature::Name::NO_CORE},
   {"box_syntax", Feature::Name::BOX_SYNTAX},
   {"dropck_eyepatch", Feature::Name::DROPCK_EYEPATCH},
+  {"raw_ref_op", Feature::Name::RAW_REF_OP},
 }; // namespace Rust
 
 tl::optional<Feature::Name>
diff --git a/gcc/rust/checks/errors/rust-feature.h 
b/gcc/rust/checks/errors/rust-feature.h
index 0fb63b591d4..6661865aedf 100644
--- a/gcc/rust/checks/errors/rust-feature.h
+++ b/gcc/rust/checks/errors/rust-feature.h
@@ -48,6 +48,7 @@ public:
     NO_CORE,
     BOX_SYNTAX,
     DROPCK_EYEPATCH,
+    RAW_REF_OP,
   };
 
   const std::string &as_string () { return m_name_str; }
-- 
2.45.2

Reply via email to