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

commit r17-5932-g9ff8f5a9643ee608990bac9a19a4be73cbee18df
Author: Pierre-Emmanuel Patry <[email protected]>
Date:   Wed Oct 28 14:53:54 2026 +0100

    gccrs: Throw an error when a global path starts with crate
    
    The crate start keyword on a path must not be used and the compiler shall
    emit an error.
    
    gcc/rust/ChangeLog:
    
            * resolve/rust-forever-stack.hxx: Emit an error message on ::crate.
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/extern_prelude_crate_keyword.rs: New test.
    
    Signed-off-by: Pierre-Emmanuel Patry <[email protected]>

Diff:
---
 gcc/rust/resolve/rust-forever-stack.hxx                    | 7 +++++++
 gcc/testsuite/rust/compile/extern_prelude_crate_keyword.rs | 7 +++++++
 2 files changed, 14 insertions(+)

diff --git a/gcc/rust/resolve/rust-forever-stack.hxx 
b/gcc/rust/resolve/rust-forever-stack.hxx
index 00d2d6ce4484..715e04e2edcc 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -494,6 +494,13 @@ ForeverStack<N>::find_starting_point (
 
       if (seg.is_crate_path_seg ())
        {
+         if (path.has_opening_scope ())
+           {
+             collect_errors.emplace_back (seg.locus, ErrorCode::E0433,
+                                          "global paths cannot start with %qs",
+                                          seg.name.c_str ());
+             return tl::nullopt;
+           }
          starting_point = root;
          insert_segment_resolution (Usage (seg.node_id),
                                     Definition (starting_point.get ().id), N);
diff --git a/gcc/testsuite/rust/compile/extern_prelude_crate_keyword.rs 
b/gcc/testsuite/rust/compile/extern_prelude_crate_keyword.rs
new file mode 100644
index 000000000000..bdc8dadbcf84
--- /dev/null
+++ b/gcc/testsuite/rust/compile/extern_prelude_crate_keyword.rs
@@ -0,0 +1,7 @@
+#![feature(no_core)]
+#![no_core]
+
+use ::crate::Grey as Gray;
+// { dg-error "global paths cannot start with .crate." "" { target *-*-* } .-1 
}
+
+pub struct Grey;

Reply via email to