From: Enes Cevik <[email protected]>
Previously, when using a grouped import that combines `self` and a glob
(e.g., `use path::module::{self, *};`), the compiler successfully
imported the inner items via the glob, but failed to import the base
module (or enum) itself.
This patch ensures `self` imports use their own unique NodeId, preventing
them from being dropped during early resolution.
Fixes Rust-GCC/gccrs#4689
gcc/rust/ChangeLog:
* resolve/rust-early-name-resolver-2.0.cc
(Early::resolve_rebind_import): Use the final segment's NodeId
for 'self' imports instead of the parent's to avoid clashing with
glob imports.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4689-1.rs: New test.
* rust/compile/issue-4689-2.rs: New test.
Signed-off-by: Enes Cevik <[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/db418335d71d605968d9d4978d2e312f58c1c59e
The commit has been mentioned in the following issue(s):
- Rust-GCC/gccrs#4689: https://github.com/Rust-GCC/gccrs/issues/4689
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4750
.../resolve/rust-early-name-resolver-2.0.cc | 18 ++-----------
gcc/testsuite/rust/compile/issue-4689-1.rs | 23 ++++++++++++++++
gcc/testsuite/rust/compile/issue-4689-2.rs | 27 +++++++++++++++++++
3 files changed, 52 insertions(+), 16 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issue-4689-1.rs
create mode 100644 gcc/testsuite/rust/compile/issue-4689-2.rs
diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
index 8a07f8f29..28e1d90a5 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
@@ -144,22 +144,8 @@ Early::resolve_rebind_import (NodeId use_dec_id,
import_id = rebind.get_node_id ();
break;
case AST::UseTreeRebind::NewBindType::NONE:
- {
- const auto &segments = path.get_segments ();
- // We don't want to insert `self` with `use module::self`
- if (path.get_final_segment ().is_lower_self_seg ())
- {
- // Erroneous `self` or `{self}` use declaration
- if (segments.size () == 1)
- break;
- import_id = segments[segments.size () - 2].get_node_id ();
- }
- else
- {
- import_id = path.get_final_segment ().get_node_id ();
- }
- break;
- }
+ import_id = path.get_final_segment ().get_node_id ();
+ break;
case AST::UseTreeRebind::NewBindType::WILDCARD:
// nothing
break;
diff --git a/gcc/testsuite/rust/compile/issue-4689-1.rs
b/gcc/testsuite/rust/compile/issue-4689-1.rs
new file mode 100644
index 000000000..4d525d5e8
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-4689-1.rs
@@ -0,0 +1,23 @@
+#![feature(no_core)]
+#![no_core]
+
+pub mod collections {
+ pub enum TryReserveError {
+ AllocError,
+ CapacityOverflow,
+ }
+}
+
+pub mod test_working {
+ use crate::collections::TryReserveError::{self, AllocError,
CapacityOverflow};
+ fn _test_function() -> TryReserveError {
+ AllocError
+ }
+}
+
+pub mod test_failing {
+ use crate::collections::TryReserveError::{self, *};
+ fn _test_function() -> TryReserveError {
+ CapacityOverflow
+ }
+}
diff --git a/gcc/testsuite/rust/compile/issue-4689-2.rs
b/gcc/testsuite/rust/compile/issue-4689-2.rs
new file mode 100644
index 000000000..d5a35b165
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-4689-2.rs
@@ -0,0 +1,27 @@
+#![feature(no_core)]
+#![no_core]
+
+pub mod my_module {
+ pub const MY_CONST: i32 = 42;
+ pub fn my_func() {}
+}
+
+pub mod test_working {
+ use crate::my_module::{self, MY_CONST};
+
+ pub fn check() {
+ let _ = MY_CONST;
+ my_module::my_func();
+ }
+}
+
+pub mod test_failing {
+ use crate::my_module::{self, *};
+
+ pub fn check() {
+ let _ = MY_CONST;
+ my_func();
+
+ my_module::my_func();
+ }
+}
base-commit: fa1a84b6b8225b6ca8c59c80ef4d9a7eb52017a1
--
2.54.0