From: Owen Avery <[email protected]>

The globbing visitor would previously descend into some kinds of rust
item, instead of registering them as glob imports or ignoring them. This
would cause items nested in those items to be glob imported, despite
them not being top level items inside the glob container.

gcc/rust/ChangeLog:

        * resolve/rust-finalize-imports-2.0.cc (GlobbingVisitor::visit):
        Add overrides for more items.
        * resolve/rust-finalize-imports-2.0.h (GlobbingVisitor::visit):
        Likewise.

gcc/testsuite/ChangeLog:

        * rust/compile/name_resolution27.rs: New test.

Reported-by: Arthur Cohen <[email protected]>
Signed-off-by: Owen Avery <[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/cd9103fd3fe8d3726d5b4c30d30c7da265f53da3

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/4569

 gcc/rust/resolve/rust-finalize-imports-2.0.cc | 22 +++++++++++++++++++
 gcc/rust/resolve/rust-finalize-imports-2.0.h  |  4 ++++
 .../rust/compile/name_resolution27.rs         | 20 +++++++++++++++++
 3 files changed, 46 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/name_resolution27.rs

diff --git a/gcc/rust/resolve/rust-finalize-imports-2.0.cc 
b/gcc/rust/resolve/rust-finalize-imports-2.0.cc
index a5bbc5b6c..8ad9322bb 100644
--- a/gcc/rust/resolve/rust-finalize-imports-2.0.cc
+++ b/gcc/rust/resolve/rust-finalize-imports-2.0.cc
@@ -142,6 +142,28 @@ GlobbingVisitor::visit (AST::ConstantItem &const_item)
                      Namespace::Values);
 }
 
+void
+GlobbingVisitor::visit (AST::TypeAlias &type)
+{
+  ctx.insert_globbed (type.get_new_type_name (), type.get_node_id (),
+                     Namespace::Types);
+}
+
+void
+GlobbingVisitor::visit (AST::Trait &trait)
+{
+  ctx.insert_globbed (trait.get_identifier (), trait.get_node_id (),
+                     Namespace::Types);
+}
+
+void
+GlobbingVisitor::visit (AST::InherentImpl &impl)
+{}
+
+void
+GlobbingVisitor::visit (AST::TraitImpl &impl)
+{}
+
 void
 GlobbingVisitor::visit (AST::ExternCrate &crate)
 {}
diff --git a/gcc/rust/resolve/rust-finalize-imports-2.0.h 
b/gcc/rust/resolve/rust-finalize-imports-2.0.h
index f4a6b57e1..3a1e70266 100644
--- a/gcc/rust/resolve/rust-finalize-imports-2.0.h
+++ b/gcc/rust/resolve/rust-finalize-imports-2.0.h
@@ -48,6 +48,10 @@ public:
   void visit (AST::Enum &enum_item) override;
   void visit (AST::Union &union_item) override;
   void visit (AST::ConstantItem &const_item) override;
+  void visit (AST::TypeAlias &type) override;
+  void visit (AST::Trait &trait) override;
+  void visit (AST::InherentImpl &impl) override;
+  void visit (AST::TraitImpl &impl) override;
   void visit (AST::ExternCrate &crate) override;
   void visit (AST::UseDeclaration &use) override;
 
diff --git a/gcc/testsuite/rust/compile/name_resolution27.rs 
b/gcc/testsuite/rust/compile/name_resolution27.rs
new file mode 100644
index 000000000..d1d09b132
--- /dev/null
+++ b/gcc/testsuite/rust/compile/name_resolution27.rs
@@ -0,0 +1,20 @@
+#![feature(no_core)]
+#![no_core]
+
+mod a {
+    trait A {
+        fn foo();
+    }
+
+    struct B;
+
+    impl A for B {
+        fn foo() {}
+    }
+}
+
+use a::*;
+
+pub fn bar() {
+    foo() // { dg-error "Cannot find path" }
+}

base-commit: b203e0fff0613f5577891ea77ead2b42c9d81e43
-- 
2.54.0

Reply via email to