From: Harishankar <[email protected]>

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 <[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/aafa6b453870cedfdacb3032fd052b2aa6ee08b4

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4451

 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 a0e31047a..df29a55c8 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 000000000..ddbe5a32b
--- /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

base-commit: 9894195b0405d74040ee3f2573077db5bdbfe511
-- 
2.53.0

Reply via email to