]> git.ipfire.org Git - people/ms/gcc.git/commitdiff
Add feature gate definition for `extern_types`.
authormxlol233 <mxlol233@outlook.com>
Wed, 1 Mar 2023 11:31:19 +0000 (19:31 +0800)
committerCohenArthur <arthur.cohen@embecosm.com>
Wed, 1 Mar 2023 15:02:21 +0000 (15:02 +0000)
This commit add a basic implementation to gating `ExternalTypeItem` AST node.

gcc/rust/ChangeLog:

* checks/errors/rust-feature-gate.cc: Add definition
for `extern_types`.
* checks/errors/rust-feature-gate.h: Likewise.
* checks/errors/rust-feature.cc: Likewise.
* checks/errors/rust-feature.h: Likewise.

gcc/testsuite/ChangeLog:
* rust/compile/feature_extern_types.rs:New file.

Signed-off-by: Xiao Ma <mxlol233@outlook.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/testsuite/rust/compile/feature_extern_types.rs [new file with mode: 0644]

index 9b2f025689f1f67b14993d4720989ad8b939f194..07d367e629213a4d9345ceaf26b3b0df4cb4bc14 100644 (file)
@@ -103,6 +103,10 @@ FeatureGate::visit (AST::ExternBlock &block)
        gate (Feature::Name::INTRINSICS, block.get_locus (),
              "intrinsics are subject to change");
     }
+  for (const auto &item : block.get_extern_items ())
+    {
+      item->accept_vis (*this);
+    }
 }
 
 void
@@ -155,4 +159,13 @@ FeatureGate::visit (AST::Function &function)
   check_rustc_attri (function.get_outer_attrs ());
 }
 
+void
+FeatureGate::visit (AST::ExternalTypeItem &item)
+{
+  // TODO(mxlol233): The gating needs a complete visiting chain to activate
+  // `AST::ExternalTypeItem`.
+  gate (Feature::Name::EXTERN_TYPES, item.get_locus (),
+       "extern types are experimental");
+}
+
 } // namespace Rust
\ No newline at end of file
index 0262903f12354b64bd2fdd86f8829a2d5d727f61..c442fd3d7d023a550d344abd0283a9c5cc619d8e 100644 (file)
@@ -133,7 +133,7 @@ public:
   void visit (AST::Trait &trait) override {}
   void visit (AST::InherentImpl &impl) override;
   void visit (AST::TraitImpl &impl) override;
-  void visit (AST::ExternalTypeItem &item) override {}
+  void visit (AST::ExternalTypeItem &item) override;
   void visit (AST::ExternalStaticItem &item) override {}
   void visit (AST::ExternalFunctionItem &item) override {}
   void visit (AST::ExternBlock &block) override;
index ceae2aaddec9e27418da531ef5a42d40c34e985d..e36e540035fe0d213644f8a383309dcc1fd1f303 100644 (file)
@@ -43,6 +43,10 @@ Feature::create (Feature::Name name)
       return Feature (Feature::Name::DECL_MACRO, Feature::State::ACCEPTED,
                      "decl_macro", "1.0.0", 0,
                      Optional<CompileOptions::Edition>::none (), "");
+    case Feature::Name::EXTERN_TYPES:
+      return Feature (Feature::Name::EXTERN_TYPES, Feature::State::ACTIVE,
+                     "extern_types", "1.23.0", 43467,
+                     Optional<CompileOptions::Edition>::none (), "");
     default:
       gcc_unreachable ();
     }
@@ -56,6 +60,7 @@ const std::map<std::string, Feature::Name> Feature::name_hash_map = {
   // TODO: Rename to "auto_traits" when supporting
   // later Rust versions
   {"optin_builtin_traits", Feature::Name::AUTO_TRAITS},
+  {"extern_types", Feature::Name::EXTERN_TYPES},
 }; // namespace Rust
 
 Optional<Feature::Name>
index 1f580a00a0a16bfcb8a8330800e12fe8f44ea6d5..7562eaf594b854bf53369b6f4406f8d45ba5a8c1 100644 (file)
@@ -42,6 +42,7 @@ public:
     RUSTC_ATTRS,
     DECL_MACRO,
     AUTO_TRAITS,
+    EXTERN_TYPES,
   };
 
   const std::string &as_string () { return m_name_str; }
diff --git a/gcc/testsuite/rust/compile/feature_extern_types.rs b/gcc/testsuite/rust/compile/feature_extern_types.rs
new file mode 100644 (file)
index 0000000..5e31493
--- /dev/null
@@ -0,0 +1,8 @@
+extern "C" {
+    type F; //{ dg-error "extern types are experimental." "" { target *-*-* }  }
+}
+
+
+fn main() {
+
+}