]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: attributes: Start handling prelude_import properly
authorArthur Cohen <arthur.cohen@embecosm.com>
Wed, 21 Aug 2024 13:09:23 +0000 (15:09 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Wed, 19 Mar 2025 14:32:04 +0000 (15:32 +0100)
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.

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/util/rust-attribute-values.h
gcc/rust/util/rust-attributes.cc
gcc/testsuite/rust/compile/prelude_import.rs [new file with mode: 0644]

index 580afc9e11032412f6fe037c13668b6a4d458de4..ca19374b4f367854b5417f29a88ad43183e306eb 100644 (file)
@@ -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
index 31c2ed659044ae018a6ce68ec85458dfbf16fbf2..7d62a63a61ba11fc026ac35522b9ffb09f357339 100644 (file)
@@ -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 {}
index 917e3b2bdd065d91333913261f4881408eac0f2f..eba8f5bfea81345f77e577f8cc638589b9cbe225 100644 (file)
@@ -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>
index 698aac2dc635a98f4080898e23fe926294545e63..2b134e2d2c8660cf6fcdfa132906ad27e5e6bcd2 100644 (file)
@@ -50,6 +50,7 @@ public:
     DROPCK_EYEPATCH,
     RAW_REF_OP,
     EXCLUSIVE_RANGE_PATTERN,
+    PRELUDE_IMPORT,
   };
 
   const std::string &as_string () { return m_name_str; }
index 90417012ed71e78920ead5b01dbde82468894201..ef01e67dc528d707b2a4cfe8b6797aeaa2f1e6f8 100644 (file)
@@ -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
index c9e376400fdd4791c6641343d3ff7e1f6729bb2d..958f7c3528492b713f4b142b19f8c0da5d91f532 100644 (file)
@@ -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 (file)
index 0000000..569fb62
--- /dev/null
@@ -0,0 +1,12 @@
+#![feature(prelude_import)]
+
+mod core {
+    mod prelude {
+        mod v1 {
+            // hehe
+        }
+    }
+}
+
+#[prelude_import]
+use core::prelude::v1::*;