From: Pierre-Emmanuel Patry <[email protected]>
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]>
Tested on x86_64-pc-linux-gnu.
---
gcc/rust/resolve/rust-forever-stack.hxx | 7 +++++++
gcc/testsuite/rust/compile/extern_prelude_crate_keyword.rs | 7 +++++++
2 files changed, 14 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/extern_prelude_crate_keyword.rs
diff --git a/gcc/rust/resolve/rust-forever-stack.hxx
b/gcc/rust/resolve/rust-forever-stack.hxx
index 00d2d6ce448..715e04e2edc 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 00000000000..bdc8dadbcf8
--- /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;
--
2.55.0