[COMMITTED 36/41] gccrs: resolve: Fix ICE on ambiguous glob re-exports
arthur.cohen@embecosm.com
arthur.cohen@embecosm.com
Fri Mar 20 17:30:25 GMT 2026
From: Harishankar <harishankarpp7@gmail.com>
This patch adds an ambiguity check in 'finalize_rebind_import'.
If a Definition is ambiguous, it emits a proper error diagnostic
instead of crashing, consistent with rustc's behavior(verified)
Fixes Rust-GCC/gccrs#4411
gcc/rust/ChangeLog:
* resolve/rust-early-name-resolver-2.0.cc (Early::finalize_rebind_import): Add ambiguity
check before calling get_node_id() on glob import definitions.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4411.rs: New test.
Signed-off-by: Harishankar <harishankarpp7@gmail.com>
---
gcc/rust/resolve/rust-early-name-resolver-2.0.cc | 11 +++++++++++
gcc/testsuite/rust/compile/issue-4411.rs | 16 ++++++++++++++++
2 files changed, 27 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/issue-4411.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 a0e31047a2b..df29a55c8fb 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
@@ -123,6 +123,17 @@ Early::resolve_rebind_import (NodeId use_dec_id,
// if we've found at least one definition, then we're good
if (definitions.empty ())
return false;
+ for (const auto &def : definitions)
+ {
+ if (def.first.is_ambiguous ())
+ {
+ rich_location rich_locus (line_table,
+ rebind_import.to_resolve.get_locus ());
+ rust_error_at (rich_locus, ErrorCode::E0659, "%qs is ambiguous",
+ rebind_import.to_resolve.as_string ().c_str ());
+ return true;
+ }
+ }
auto &imports = import_mappings.new_or_access (use_dec_id);
diff --git a/gcc/testsuite/rust/compile/issue-4411.rs b/gcc/testsuite/rust/compile/issue-4411.rs
new file mode 100644
index 00000000000..ddbe5a32b6b
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-4411.rs
@@ -0,0 +1,16 @@
+#![feature(no_core)]
+#![no_core]
+mod framing {
+ mod public_message {
+ pub struct ConfirmedTranscriptHashInput;
+ }
+ mod public_message_in {
+ pub struct ConfirmedTranscriptHashInput;
+ }
+ pub use self::public_message::*;
+ pub use self::public_message_in::*;
+}
+
+use crate::framing::ConfirmedTranscriptHashInput; // { dg-error "is ambiguous .E0659." }
+
+fn main() {}
\ No newline at end of file
--
2.50.1
More information about the Gcc-rust
mailing list