From: Pierre-Emmanuel Patry <[email protected]>

We emitted core but did not specify it had to come from the extern
prelude when generating builtin macros. We used opening scope resolution
every time.

gcc/rust/ChangeLog:

        * ast/rust-ast-builder.cc (Builder::discriminant_value): Add call to
        get opening scope resolution value.
        (Builder::qualified_call): Add opening scope resolution argument.
        * ast/rust-ast-builder.h: Update function prototype and add a new
        function to disambiguate opening scope from context.
        * expand/rust-derive-clone.cc (DeriveClone::clone_call): Fetch opening
        scope value.
        * expand/rust-derive-debug.cc (DeriveDebug::stub_debug_fn): Likewise.
        * expand/rust-derive-default.cc (DeriveDefault::default_call):
        Likewise.
        * expand/rust-derive-eq.cc (get_eq_trait_path): Likewise.
        * expand/rust-derive-hash.cc (DeriveHash::hash_call): Likewise.
        (DeriveHash::hash_fn): Likewise.
        * expand/rust-derive-ord.cc (DeriveOrd::cmp_call): Likewise.
        (DeriveOrd::cmp_fn): Likewise.
        (DeriveOrd::make_equal): Likewise.
        (DeriveOrd::recursive_match): Likewise.
        * expand/rust-expand-format-args.cc (format_arg): Likewise.
        (expand_format_args): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/45009f514b5759fe94525e49608f036bd3ce10d1

The commit has NOT been mentioned in any issue.

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/5023

 gcc/rust/ast/rust-ast-builder.cc           |  7 +++---
 gcc/rust/ast/rust-ast-builder.h            | 15 ++++++++++++-
 gcc/rust/expand/rust-derive-clone.cc       |  1 +
 gcc/rust/expand/rust-derive-debug.cc       | 10 +++++----
 gcc/rust/expand/rust-derive-default.cc     |  4 ++--
 gcc/rust/expand/rust-derive-eq.cc          |  3 ++-
 gcc/rust/expand/rust-derive-hash.cc        |  7 +++---
 gcc/rust/expand/rust-derive-ord.cc         | 26 ++++++++++++++--------
 gcc/rust/expand/rust-expand-format-args.cc | 21 +++++++++--------
 9 files changed, 62 insertions(+), 32 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc
index 09db66957..44b6a721f 100644
--- a/gcc/rust/ast/rust-ast-builder.cc
+++ b/gcc/rust/ast/rust-ast-builder.cc
@@ -548,7 +548,7 @@ Builder::discriminant_value (std::string binding_name, 
std::string instance)
 {
   auto intrinsic = ptrify (
     path_in_expression ({get_path_start (), "intrinsics", 
"discriminant_value"},
-                       true));
+                       has_opening_scope ()));
 
   return let (identifier_pattern (binding_name), nullptr,
              call (std::move (intrinsic), identifier (instance)));
@@ -742,10 +742,11 @@ Builder::new_generic_args (GenericArgs &args)
 
 std::unique_ptr<Expr>
 Builder::qualified_call (std::vector<std::string> &&segments,
+                        bool has_opening_scope,
                         std::vector<std::unique_ptr<Expr>> &&args) const
 {
-  auto path = std::unique_ptr<Expr> (
-    new PathInExpression (path_in_expression (std::move (segments))));
+  auto path = std::unique_ptr<Expr> (new PathInExpression (
+    path_in_expression (std::move (segments), has_opening_scope)));
 
   return call (std::move (path), std::move (args));
 }
diff --git a/gcc/rust/ast/rust-ast-builder.h b/gcc/rust/ast/rust-ast-builder.h
index bc790e98a..5c35a5e17 100644
--- a/gcc/rust/ast/rust-ast-builder.h
+++ b/gcc/rust/ast/rust-ast-builder.h
@@ -184,7 +184,7 @@ public:
                                = {}) const;
 
   std::unique_ptr<Expr>
-  qualified_call (std::vector<std::string> &&segments,
+  qualified_call (std::vector<std::string> &&segments, bool has_opening_scope,
                  std::vector<std::unique_ptr<Expr>> &&args) const;
 
   /* Self parameter for a function definition (`&self`) */
@@ -381,6 +381,19 @@ public:
        rust_unreachable ();
       }
   }
+
+  bool has_opening_scope () const
+  {
+    switch (item_source)
+      {
+      case Builder::Source::InCore:
+       return false;
+      case Builder::Source::Any:
+       return true;
+      default:
+       rust_unreachable ();
+      }
+  }
 };
 
 } // namespace AST
diff --git a/gcc/rust/expand/rust-derive-clone.cc 
b/gcc/rust/expand/rust-derive-clone.cc
index e21fe298f..f71592b29 100644
--- a/gcc/rust/expand/rust-derive-clone.cc
+++ b/gcc/rust/expand/rust-derive-clone.cc
@@ -44,6 +44,7 @@ DeriveClone::clone_call (std::unique_ptr<Expr> &&to_clone)
   // FIXME: Misses :: prefix to avoid collision with potential core module
   return builder.qualified_call ({builder.get_path_start (), "clone", "Clone",
                                  "clone"},
+                                builder.has_opening_scope (),
                                 std::move (args));
 }
 
diff --git a/gcc/rust/expand/rust-derive-debug.cc 
b/gcc/rust/expand/rust-derive-debug.cc
index 3bfc11045..b8a6470ea 100644
--- a/gcc/rust/expand/rust-derive-debug.cc
+++ b/gcc/rust/expand/rust-derive-debug.cc
@@ -54,11 +54,13 @@ DeriveDebug::stub_debug_fn ()
 
   auto self = builder.self_ref_param ();
 
-  auto return_type = ptrify (
-    builder.type_path ({builder.get_path_start (), "fmt", "Result"}, true));
+  auto return_type
+    = ptrify (builder.type_path ({builder.get_path_start (), "fmt", "Result"},
+                                builder.has_opening_scope ()));
 
   auto mut_fmt_type_inner = ptrify (
-    builder.type_path ({builder.get_path_start (), "fmt", "Formatter"}, true));
+    builder.type_path ({builder.get_path_start (), "fmt", "Formatter"},
+                      builder.has_opening_scope ()));
 
   auto mut_fmt_type
     = builder.reference_type (std::move (mut_fmt_type_inner), true);
@@ -83,7 +85,7 @@ DeriveDebug::stub_derive_impl (
 
   auto debug = [this] () {
     return builder.type_path ({builder.get_path_start (), "fmt", "Debug"},
-                             true);
+                             builder.has_opening_scope ());
   };
   auto generics = setup_impl_generics (name, type_generics, [&, this] () {
     return builder.trait_bound (debug ());
diff --git a/gcc/rust/expand/rust-derive-default.cc 
b/gcc/rust/expand/rust-derive-default.cc
index b6e137df6..dbe93a689 100644
--- a/gcc/rust/expand/rust-derive-default.cc
+++ b/gcc/rust/expand/rust-derive-default.cc
@@ -44,7 +44,7 @@ DeriveDefault::default_call (std::unique_ptr<Type> &&type)
 {
   auto default_trait
     = builder.type_path ({builder.get_path_start (), "default", "Default"},
-                        true);
+                        builder.has_opening_scope ());
 
   auto default_fn
     = builder.qualified_path_in_expression (std::move (type), default_trait,
@@ -73,7 +73,7 @@ DeriveDefault::default_impl (
 {
   auto default_path = [this] () {
     return builder.type_path ({builder.get_path_start (), "default", 
"Default"},
-                             true);
+                             builder.has_opening_scope ());
   };
 
   auto trait_items = vec (std::move (default_fn));
diff --git a/gcc/rust/expand/rust-derive-eq.cc 
b/gcc/rust/expand/rust-derive-eq.cc
index aa2238926..2eee4bd32 100644
--- a/gcc/rust/expand/rust-derive-eq.cc
+++ b/gcc/rust/expand/rust-derive-eq.cc
@@ -30,7 +30,8 @@ namespace AST {
 static TypePath
 get_eq_trait_path (Builder &builder)
 {
-  return builder.type_path ({builder.get_path_start (), "cmp", "Eq"}, true);
+  return builder.type_path ({builder.get_path_start (), "cmp", "Eq"},
+                           builder.has_opening_scope ());
 }
 
 DeriveEq::DeriveEq (location_t loc, Builder::Source item_source)
diff --git a/gcc/rust/expand/rust-derive-hash.cc 
b/gcc/rust/expand/rust-derive-hash.cc
index 69eb73008..f07626b9c 100644
--- a/gcc/rust/expand/rust-derive-hash.cc
+++ b/gcc/rust/expand/rust-derive-hash.cc
@@ -45,7 +45,7 @@ DeriveHash::hash_call (std::unique_ptr<Expr> &&value)
 {
   auto hash = builder.path_in_expression ({builder.get_path_start (), "hash",
                                           "Hash", "hash"},
-                                         true);
+                                         builder.has_opening_scope ());
 
   return builder.call (ptrify (hash),
                       vec (std::move (value),
@@ -67,7 +67,8 @@ DeriveHash::hash_fn (std::unique_ptr<BlockExpr> &&block)
 
   auto params = vec (builder.self_ref_param (), std::move (state_param));
   auto bounds = vec (builder.trait_bound (
-    builder.type_path ({builder.get_path_start (), "hash", "Hasher"}, true)));
+    builder.type_path ({builder.get_path_start (), "hash", "Hasher"},
+                      builder.has_opening_scope ())));
   auto generics = vec (
     builder.generic_type_param (DeriveHash::state_type, std::move (bounds)));
 
@@ -82,7 +83,7 @@ DeriveHash::hash_impl (
 {
   auto hash_path = [this] () {
     return builder.type_path ({builder.get_path_start (), "hash", "Hash"},
-                             true);
+                             builder.has_opening_scope ());
   };
 
   auto trait_items = vec (std::move (hash_fn));
diff --git a/gcc/rust/expand/rust-derive-ord.cc 
b/gcc/rust/expand/rust-derive-ord.cc
index 7960d2978..54bec4577 100644
--- a/gcc/rust/expand/rust-derive-ord.cc
+++ b/gcc/rust/expand/rust-derive-ord.cc
@@ -43,8 +43,10 @@ std::unique_ptr<Expr>
 DeriveOrd::cmp_call (std::unique_ptr<Expr> &&self_expr,
                     std::unique_ptr<Expr> &&other_expr)
 {
-  auto cmp_fn_path = builder.path_in_expression (
-    {builder.get_path_start (), "cmp", trait (ordering), fn (ordering)}, true);
+  auto cmp_fn_path
+    = builder.path_in_expression ({builder.get_path_start (), "cmp",
+                                  trait (ordering), fn (ordering)},
+                                 builder.has_opening_scope ());
 
   return builder.call (ptrify (cmp_fn_path),
                       vec (builder.ref (std::move (self_expr)),
@@ -60,7 +62,8 @@ DeriveOrd::cmp_impl (
 
   auto trait = ordering == Ordering::Partial ? "PartialOrd" : "Ord";
   auto trait_path = [&, this] () {
-    return builder.type_path ({builder.get_path_start (), "cmp", trait}, true);
+    return builder.type_path ({builder.get_path_start (), "cmp", trait},
+                             builder.has_opening_scope ());
   };
 
   auto trait_bound
@@ -81,7 +84,8 @@ DeriveOrd::cmp_fn (std::unique_ptr<BlockExpr> &&block, 
Identifier type_name)
 {
   // Ordering
   auto return_type
-    = builder.type_path ({builder.get_path_start (), "cmp", "Ordering"}, true);
+    = builder.type_path ({builder.get_path_start (), "cmp", "Ordering"},
+                        builder.has_opening_scope ());
 
   // In the case of PartialOrd, we return an Option<Ordering>
   if (ordering == Ordering::Partial)
@@ -96,7 +100,7 @@ DeriveOrd::cmp_fn (std::unique_ptr<BlockExpr> &&block, 
Identifier type_name)
       return_type
        = builder.type_path (vec (std::move (core), std::move (option),
                                  std::move (generic_seg)),
-                            true);
+                            builder.has_opening_scope ());
     }
 
   // &self, other: &Self
@@ -118,8 +122,10 @@ DeriveOrd::cmp_fn (std::unique_ptr<BlockExpr> &&block, 
Identifier type_name)
 std::unique_ptr<Pattern>
 DeriveOrd::make_equal ()
 {
-  std::unique_ptr<Pattern> equal = ptrify (builder.path_in_expression (
-    {builder.get_path_start (), "cmp", "Ordering", "Equal"}, true));
+  std::unique_ptr<Pattern> equal
+    = ptrify (builder.path_in_expression ({builder.get_path_start (), "cmp",
+                                          "Ordering", "Equal"},
+                                         builder.has_opening_scope ()));
 
   // We need to wrap the pattern in Option::Some if we are doing partial
   // ordering
@@ -153,8 +159,10 @@ DeriveOrd::recursive_match (std::vector<SelfOther> 
&&members)
 {
   if (members.empty ())
     {
-      std::unique_ptr<Expr> value = ptrify (builder.path_in_expression (
-       {builder.get_path_start (), "cmp", "Ordering", "Equal"}, true));
+      std::unique_ptr<Expr> value
+       = ptrify (builder.path_in_expression ({builder.get_path_start (), "cmp",
+                                              "Ordering", "Equal"},
+                                             builder.has_opening_scope ()));
 
       if (ordering == Ordering::Partial)
        value = builder.call (ptrify (builder.path_in_expression (
diff --git a/gcc/rust/expand/rust-expand-format-args.cc 
b/gcc/rust/expand/rust-expand-format-args.cc
index 38fdb8a9c..ba08652d6 100644
--- a/gcc/rust/expand/rust-expand-format-args.cc
+++ b/gcc/rust/expand/rust-expand-format-args.cc
@@ -35,13 +35,15 @@ static std::unique_ptr<AST::Expr>
 format_arg (const AST::Builder &builder, std::unique_ptr<AST::Expr> 
&&to_format,
            const std::string &trait)
 {
-  auto formatter_fn = std::unique_ptr<AST::Expr> (
-    new AST::PathInExpression (builder.path_in_expression (
-      {builder.get_path_start (), "fmt", trait, "fmt"})));
+  auto formatter_fn = std::unique_ptr<AST::Expr> (new AST::PathInExpression (
+    builder.path_in_expression ({builder.get_path_start (), "fmt", trait,
+                                "fmt"},
+                               builder.has_opening_scope ())));
 
-  auto path = std::unique_ptr<AST::Expr> (
-    new AST::PathInExpression (builder.path_in_expression (
-      {builder.get_path_start (), "fmt", "ArgumentV1", "new"})));
+  auto path = std::unique_ptr<AST::Expr> (new AST::PathInExpression (
+    builder.path_in_expression ({builder.get_path_start (), "fmt", 
"ArgumentV1",
+                                "new"},
+                               builder.has_opening_scope ())));
 
   auto args = std::vector<std::unique_ptr<AST::Expr>> ();
   args.emplace_back (std::move (to_format));
@@ -127,9 +129,10 @@ expand_format_args (AST::FormatArgs &fmt,
   auto pieces = builder.ref (builder.array (std::move (static_pieces)));
   auto args_slice = builder.ref (builder.array (std::move (args_array)));
 
-  auto final_path
-    = std::make_unique<AST::PathInExpression> (builder.path_in_expression (
-      {builder.get_path_start (), "fmt", "Arguments", "new_v1"}));
+  auto final_path = std::make_unique<AST::PathInExpression> (
+    builder.path_in_expression ({builder.get_path_start (), "fmt", "Arguments",
+                                "new_v1"},
+                               builder.has_opening_scope ()));
   auto final_args = std::vector<std::unique_ptr<AST::Expr>> ();
   final_args.emplace_back (std::move (pieces));
   final_args.emplace_back (std::move (args_slice));

base-commit: cad9e9eb58ecacac83afc8e296722f01c5df5a77
-- 
2.56.0

Reply via email to