public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Add feature gate definition for `extern_types`.
@ 2023-03-05 11:41 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-03-05 11:41 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:9c46a853be4b5a9c2e1b965fa0dcd44beed71924

commit 9c46a853be4b5a9c2e1b965fa0dcd44beed71924
Author: mxlol233 <mxlol233@outlook.com>
Date:   Wed Mar 1 19:31:19 2023 +0800

    Add feature gate definition for `extern_types`.
    
    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>

Diff:
---
 gcc/rust/checks/errors/rust-feature-gate.cc        | 13 +++++++++++++
 gcc/rust/checks/errors/rust-feature-gate.h         |  2 +-
 gcc/rust/checks/errors/rust-feature.cc             |  5 +++++
 gcc/rust/checks/errors/rust-feature.h              |  1 +
 gcc/testsuite/rust/compile/feature_extern_types.rs |  8 ++++++++
 5 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc b/gcc/rust/checks/errors/rust-feature-gate.cc
index 9b2f025689f..07d367e6292 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/rust-feature-gate.cc
@@ -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
diff --git a/gcc/rust/checks/errors/rust-feature-gate.h b/gcc/rust/checks/errors/rust-feature-gate.h
index 0262903f123..c442fd3d7d0 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/rust-feature-gate.h
@@ -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;
diff --git a/gcc/rust/checks/errors/rust-feature.cc b/gcc/rust/checks/errors/rust-feature.cc
index ceae2aaddec..e36e540035f 100644
--- a/gcc/rust/checks/errors/rust-feature.cc
+++ b/gcc/rust/checks/errors/rust-feature.cc
@@ -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>
diff --git a/gcc/rust/checks/errors/rust-feature.h b/gcc/rust/checks/errors/rust-feature.h
index 1f580a00a0a..7562eaf594b 100644
--- a/gcc/rust/checks/errors/rust-feature.h
+++ b/gcc/rust/checks/errors/rust-feature.h
@@ -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
index 00000000000..5e314931d6a
--- /dev/null
+++ b/gcc/testsuite/rust/compile/feature_extern_types.rs
@@ -0,0 +1,8 @@
+extern "C" {
+    type F; //{ dg-error "extern types are experimental." "" { target *-*-* }  }
+}
+
+
+fn main() {
+
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-05 11:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-05 11:41 [gcc/devel/rust/master] Add feature gate definition for `extern_types` Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).