https://gcc.gnu.org/g:06e8b826d77d47467cb378d122a04465be28e2f4

commit 06e8b826d77d47467cb378d122a04465be28e2f4
Author: Arthur Cohen <arthur.co...@embecosm.com>
Date:   Wed Aug 21 15:09:23 2024 +0200

    attributes: Start handling prelude_import properly
    
    This commit adds basic handling for the `#[prelude_import]` attribute,
    without doing anything functionality wise.
    
    gcc/rust/ChangeLog:
    
            * checks/errors/rust-feature-gate.cc (FeatureGate::visit): Add base
            feature gating for `#[feature(prelude_import)]`.
            * checks/errors/rust-feature-gate.h: Likewise.
            * checks/errors/rust-feature.cc (Feature::create): Likewise.
            * checks/errors/rust-feature.h: Likewise.
            * util/rust-attribute-values.h: Add base handling for 
`#[prelude_import]`
            attribute.
            * util/rust-attributes.cc: Likewise.
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/prelude_import.rs: New test.

Diff:
---
 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 +
 gcc/rust/util/rust-attribute-values.h        |  1 +
 gcc/rust/util/rust-attributes.cc             |  3 ++-
 gcc/testsuite/rust/compile/prelude_import.rs | 12 ++++++++++++
 7 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc 
b/gcc/rust/checks/errors/rust-feature-gate.cc
index 0fe2edbce4fc..47e4ad872319 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/rust-feature-gate.cc
@@ -217,4 +217,12 @@ FeatureGate::visit (AST::RangePattern &pattern)
          "exclusive range pattern syntax is experimental");
 }
 
+void
+FeatureGate::visit (AST::UseTreeGlob &use)
+{
+  // At the moment, UseTrees do not have outer attributes, but they should. we
+  // need to eventually gate `#[prelude_import]` on use-trees based on the
+  // #[feature(prelude_import)]
+}
+
 } // namespace Rust
diff --git a/gcc/rust/checks/errors/rust-feature-gate.h 
b/gcc/rust/checks/errors/rust-feature-gate.h
index 5a063ea5c8a1..5d02504d9d27 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/rust-feature-gate.h
@@ -107,7 +107,7 @@ public:
   void visit (AST::TypeBoundWhereClauseItem &item) override {}
   void visit (AST::Module &module) override {}
   void visit (AST::ExternCrate &crate) override {}
-  void visit (AST::UseTreeGlob &use_tree) override {}
+  void visit (AST::UseTreeGlob &use_tree) override;
   void visit (AST::UseTreeList &use_tree) override {}
   void visit (AST::UseTreeRebind &use_tree) override {}
   void visit (AST::UseDeclaration &use_decl) override {}
diff --git a/gcc/rust/checks/errors/rust-feature.cc 
b/gcc/rust/checks/errors/rust-feature.cc
index cd2df0f96f6a..587f0e58b8a7 100644
--- a/gcc/rust/checks/errors/rust-feature.cc
+++ b/gcc/rust/checks/errors/rust-feature.cc
@@ -58,6 +58,9 @@ Feature::create (Feature::Name name)
       return Feature (Feature::Name::EXCLUSIVE_RANGE_PATTERN,
                      Feature::State::ACTIVE, "exclusive_range_pattern",
                      "1.11.0", 37854, tl::nullopt, "");
+    case Feature::Name::PRELUDE_IMPORT:
+      return Feature (Feature::Name::PRELUDE_IMPORT, Feature::State::ACTIVE,
+                     "prelude_import", "1.0.0", 0, tl::nullopt, "");
     default:
       rust_unreachable ();
     }
@@ -79,6 +82,7 @@ const std::map<std::string, Feature::Name> 
Feature::name_hash_map = {
   {"dropck_eyepatch", Feature::Name::DROPCK_EYEPATCH},
   {"raw_ref_op", Feature::Name::RAW_REF_OP},
   {"exclusive_range_pattern", Feature::Name::EXCLUSIVE_RANGE_PATTERN},
+  {"prelude_import", Feature::Name::PRELUDE_IMPORT},
 }; // 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 89e58cf0ed1e..482c933b0bd8 100644
--- a/gcc/rust/checks/errors/rust-feature.h
+++ b/gcc/rust/checks/errors/rust-feature.h
@@ -50,6 +50,7 @@ public:
     DROPCK_EYEPATCH,
     RAW_REF_OP,
     EXCLUSIVE_RANGE_PATTERN,
+    PRELUDE_IMPORT,
   };
 
   const std::string &as_string () { return m_name_str; }
diff --git a/gcc/rust/util/rust-attribute-values.h 
b/gcc/rust/util/rust-attribute-values.h
index 428a86f6df61..fa316b45a9e9 100644
--- a/gcc/rust/util/rust-attribute-values.h
+++ b/gcc/rust/util/rust-attribute-values.h
@@ -56,6 +56,7 @@ public:
   static constexpr auto &RUSTC_CONST_STABLE = "rustc_const_stable";
   static constexpr auto &RUSTC_CONST_UNSTABLE = "rustc_const_unstable";
   static constexpr auto &MAY_DANGLE = "may_dangle";
+  static constexpr auto &PRELUDE_IMPORT = "prelude_import";
 };
 } // namespace Values
 } // namespace Rust
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 33166673c28a..14f00bd3c526 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -64,7 +64,8 @@ static const BuiltinAttrDefinition __definitions[]
      {Attrs::UNSTABLE, STATIC_ANALYSIS},
      // assuming we keep these for static analysis
      {Attrs::RUSTC_CONST_STABLE, STATIC_ANALYSIS},
-     {Attrs::RUSTC_CONST_UNSTABLE, STATIC_ANALYSIS}};
+     {Attrs::RUSTC_CONST_UNSTABLE, STATIC_ANALYSIS},
+     {Attrs::PRELUDE_IMPORT, NAME_RESOLUTION}};
 
 BuiltinAttributeMappings *
 BuiltinAttributeMappings::get ()
diff --git a/gcc/testsuite/rust/compile/prelude_import.rs 
b/gcc/testsuite/rust/compile/prelude_import.rs
new file mode 100644
index 000000000000..569fb62ad8c9
--- /dev/null
+++ b/gcc/testsuite/rust/compile/prelude_import.rs
@@ -0,0 +1,12 @@
+#![feature(prelude_import)]
+
+mod core {
+    mod prelude {
+        mod v1 {
+            // hehe
+        }
+    }
+}
+
+#[prelude_import]
+use core::prelude::v1::*;

Reply via email to