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]>
---
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/c56d8ef4b3d9a6e2df27a7186a3a4924cc31e055
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/5030
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 00d2d6ce4..715e04e2e 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 000000000..bdc8dadbc
--- /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.56.0